7

I want to include an unrar files option in my iphone app.

I have already tried https://github.com/ararog/Unrar4iOS but this library is not complete (some functions are not yet implemented like -(BOOL) unrarFileTo:(NSString*)path overWrite:(BOOL)overwrite)

Thanks.

Alex1987
  • 9,397
  • 14
  • 70
  • 92
  • For future reference, you'll get better search results if you consider "language and API" versus "OS", otherwise you'll miss perfectly good libraries and sample code that works equally well on iOS or Mac OS X. Start with "unrar objective-c" for the broadest results. – Joshua Nozzi Oct 16 '11 at 17:19
  • Please search the site. This has been asked a good half-dozen times before. – Dave DeLong Oct 16 '11 at 18:33
  • Obviously I searched extensively before asking this question. – Alex1987 Oct 16 '11 at 18:50
  • 4
    Alex: *Obviously?* Obvious to *whom*? None of us are privy to your browsing history and you did not say where you've looked and why the results that *can* be found don't work for you. In fact you apparently already tried something (your response to omz's response) that didn't work for you but you failed to mention it. Sorry, but there's nothing "obvious" about what you did or didn't do. It's better to take responsibility for the clarity of your own questions so you can make them better (and help us give you better answers). – Joshua Nozzi Oct 16 '11 at 22:38

3 Answers3

5

I ended up using Unrar4ios but I needed to write myself the function that actually extracts the rar file:

-(BOOL) unrarFileTo:(NSString*)path overWrite:(BOOL)overwrite {

    int RHCode = 0, PFCode = 0;

    [self _unrarOpenFile:filename mode:RAR_OM_EXTRACT];

    while ((RHCode = RARReadHeaderEx(_rarFile, header)) == 0) {

        if ((PFCode = RARProcessFile(_rarFile, RAR_EXTRACT, (char *)[path UTF8String], NULL)) != 0) {
            [self _unrarCloseFile];
            return NO;
        }

    }

    [self _unrarCloseFile];


    return YES;
}
Alex1987
  • 9,397
  • 14
  • 70
  • 92
  • 3
    Consider submitting a pull request on github, to help the original project. – Moshe Oct 23 '11 at 13:14
  • @Moshe: Gladly. The problem is that I'm not too familiar with github - Can you please give me a short explanation (or a link) on how to do that? – Alex1987 Oct 23 '11 at 16:31
  • I'm not a GitHub pro myself, but essentially, you need to fork the repo, make your changes, push a commit, and then request a pull. I'll grab a link if I find one. – Moshe Oct 23 '11 at 17:05
  • @pacoflaco It seems that the framework is not "global", in a way that it can work only for the simulator and not for the device... I didn't have time to dig into how to create a framework in xcode 4 so what I did was to create a static library (.a file) of Unrar4ios file and then added it to my main project (with the headers). Of course here I had to create a "universal" static library so I used a run script from here http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4 (Adam's answer)... – Alex1987 Oct 25 '11 at 20:23
  • @Alex1987 i tried but appear an error "use of undeclared identifier 'archive'", can you upload your static library? – gfdgfd Oct 25 '11 at 21:09
4

This might help: https://github.com/ararog/Unrar4iOS

omz
  • 53,243
  • 5
  • 129
  • 141
  • I already tried this library - but it is somewhat incomplete. If you look at the source you will see that some functions are not implemented most importantly -(BOOL) unrarFileTo:(NSString*)path overWrite:(BOOL)overwrite. – Alex1987 Oct 16 '11 at 18:35
  • 1
    @Alex: Have you looked at the example project that comes with it? Particularly the -decompress: method of ./UnrarExample/Classes/UnrarExampleViewController.mm? Seems to work fine. – Joshua Nozzi Oct 16 '11 at 22:47
  • @JoshuaNozzi It works becuase he uses a different method called extractStream, which basically returns you an NSData object. It might work when we are talking about images (like in the project) - but not when it comes to bigger files. – Alex1987 Oct 17 '11 at 07:54
  • ...that's exactly the kind of thing you should put in your original question so we don't do things like spend time searching the suggested library you already tried to find a method that doesn't work for a reason you already knew. ;-) – Joshua Nozzi Oct 17 '11 at 13:24
0

The unrarlib library should work for you, since Objective C is a superset of C.

MindJuice
  • 4,121
  • 3
  • 29
  • 41
  • Have you actually tried it? It's a very old project (2002-2004) and doesn't support rar 3.x archives – Alex1987 Oct 22 '11 at 23:50