Recent

Author Topic: [SOLVED] Working with .Rar or .cbr files - Best way to work with?  (Read 3331 times)

zxandris

  • Full Member
  • ***
  • Posts: 170
I want to support working with RAR, now just extracting would be fine, but I'd like to be able to add files to a rar based file too.  I'm curious what would you guys say is the best way of doing that.  I assume there is some way of doing it, or some libraries for doing it but I've not had the best of luck finding anything so any help would be greatly appreciated.

CJ
« Last Edit: October 26, 2023, 01:56:43 pm by zxandris »

Warfley

  • Hero Member
  • *****
  • Posts: 2039
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #1 on: October 18, 2023, 03:04:24 pm »
Simply speaking, you can't.

Rar is a proprietary format and while rarlabs, the company that holds the copyright, provides code for unpacking from third party applications they do not allow such applications to create or modify archives.

rvk

  • Hero Member
  • *****
  • Posts: 6948
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #2 on: October 18, 2023, 03:12:32 pm »
Of course you could execute WinRAR\rar.exe directly from your program in code.

rar.exe has command line options to do stuff.
https://cects.com/using-the-winrar-command-line-tools-in-windows/

zxandris

  • Full Member
  • ***
  • Posts: 170
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #3 on: October 18, 2023, 03:28:03 pm »
Of course you could execute WinRAR\rar.exe directly from your program in code.

rar.exe has command line options to do stuff.
https://cects.com/using-the-winrar-command-line-tools-in-windows/

That's probably what I'll have to do, thanks.

But as a matter of interest is there a pascal library JUST for extracting files, because honestly that would do it.

rvk

  • Hero Member
  • *****
  • Posts: 6948
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #4 on: October 18, 2023, 03:40:26 pm »
But as a matter of interest is there a pascal library JUST for extracting files, because honestly that would do it.
There is a Delphi component which uses unrar.dll (there are actually two):
https://www.rarlab.com/rar_add.htm (at the bottom, search for Delphi)

You could also try the 7zip dll.

I'm not sure if there are any native pascal sources for this.
(the unrar source is availably on above mentioned site)


zxandris

  • Full Member
  • ***
  • Posts: 170
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #5 on: October 18, 2023, 03:44:34 pm »
But as a matter of interest is there a pascal library JUST for extracting files, because honestly that would do it.
There is a Delphi component which uses unrar.dll (there are actually two):
https://www.rarlab.com/rar_add.htm (at the bottom, search for Delphi)

You could also try the 7zip dll.

I'm not sure if there are any native pascal sources for this.
(the unrar source is availably on above mentioned site)

Unfortunately since it sounds perfect, I'm way below being able to figure out header files from another language to be able to use 7zip.dll though I would love it if someone has and is willing to share :)?

That sort of thing is just beyond me right now.  I barely understand pascal, despite working with it for years, so I imagine the headers are in C or C++ and thus I would have no darn idea. THough I would guess I could automate the 7z.exe and offer a setting for the exe path or something to enable that support.  That sounds like what I'd have to do.

rvk

  • Hero Member
  • *****
  • Posts: 6948
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #6 on: October 18, 2023, 03:58:07 pm »
Unfortunately since it sounds perfect, I'm way below being able to figure out header files from another language to be able to use 7zip.dll though I would love it if someone has and is willing to share :)?
You can just download and include the sevenzip7.pas in your uses clause and use some of the example listed on this github repo.

https://github.com/PascalVault/Lazarus_7zip

(I'm not sure if FPC has one included or if there are more.)

Extracting would look like this:
Code: Pascal  [Select][+][-]
  1. uses sevenzip7;
  2. // ...
  3. with CreateInArchive(CLSID_CFormatRar) do
  4. begin
  5.   OpenFile('c:\temp\test.cbr');
  6.   ExtractTo('c:\temp\test');
  7. end;

paweld

  • Hero Member
  • *****
  • Posts: 1571
Best regards / Pozdrawiam
paweld

zxandris

  • Full Member
  • ***
  • Posts: 170
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #8 on: October 18, 2023, 04:03:56 pm »
Thank you SO much peeps,

This should all enable me to do what I'm trying to do and then some :).

Again, I've said it before and I'll say it more, this forum is a massive help to me and many other people.  Thank you very much

CJ

domasz

  • Hero Member
  • *****
  • Posts: 617
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #9 on: October 18, 2023, 05:02:55 pm »
Just to clarify a bit:
.CBR files are usually uncompressed. To read uncompressed RAR/CBR you can try this:
https://github.com/PascalVault/Lazarus_Unpacker
You can also create uncompressed CBR/RAR files:
https://github.com/PascalVault/Lazarus_Packer

However if your RAR/CBR files are compressed then there is no pure Pascal solution to read them. One way is to use 7zip DLL. Here's a library for Lazarus to use 7zip DLL:
https://github.com/PascalVault/Lazarus_7zip
With that DLL it's a bit tricky to show progress or ask for password (in case of password protected files). To make things easier you can disable multi threading: SetMultiThreading
« Last Edit: October 18, 2023, 05:04:47 pm by domasz »

zxandris

  • Full Member
  • ***
  • Posts: 170
Re: Working with .Rar or .cbr files - Best way to work with?
« Reply #10 on: October 26, 2023, 01:56:29 pm »
Just to clarify a bit:
.CBR files are usually uncompressed. To read uncompressed RAR/CBR you can try this:
https://github.com/PascalVault/Lazarus_Unpacker
You can also create uncompressed CBR/RAR files:
https://github.com/PascalVault/Lazarus_Packer

However if your RAR/CBR files are compressed then there is no pure Pascal solution to read them. One way is to use 7zip DLL. Here's a library for Lazarus to use 7zip DLL:
https://github.com/PascalVault/Lazarus_7zip
With that DLL it's a bit tricky to show progress or ask for password (in case of password protected files). To make things easier you can disable multi threading: SetMultiThreading

The 7zip unit seems to work perfectly for me, once I remembered I'm working with 64bit and thus needed the 64bit dll lol.  Now it's pretty seemless which ever format I'm working with it just does the job for me - thank you peeps.

 

TinyPortal © 2005-2018