Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-30-2011, 09:54 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 4
nicegyuha is on a distinguished road
Lightbulb How to View contents of ZIP & RAR files without extracting on iphone?

How to View contents of ZIP & RAR files without extracting on iphone?



Any assistance is welcome.



Thanks
nicegyuha is offline   Reply With Quote
Old 07-01-2011, 02:24 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

using ziparchive - An Objective C class for zip/unzip on iPhone and Mac OSX - Google Project Hosting

you can use this method


Quote:
Comment by carlos...@gmail.com, Nov 15, 2009

Dear Everyone

If you wish to add a function to merely list the items in the zip file, and return this as an NSString array, insert the following lines into ZipArchive?.mm:

Code:
- (NSMutableArray *) getZipFileContents
{
        BOOL success = YES;
        int ret = unzGoToFirstFile( _unzFile );
        NSMutableArray * AllFilenames = [[NSMutableArray alloc] initWithCapacity:40];
        
        if( ret!=UNZ_OK )
        {
                [self OutputErrorMessage:@"Failed"];
        }
        
        do{
                if( [_password length]==0 )
                        ret = unzOpenCurrentFile( _unzFile );
                else
                        ret = unzOpenCurrentFilePassword( _unzFile, [_password cStringUsingEncoding:NSASCIIStringEncoding] );
                if( ret!=UNZ_OK )
                {
                        [self OutputErrorMessage:@"Error occured"];
                        success = NO;
                        break;
                }
                
                // reading data and write to file
                unz_file_info   fileInfo ={0};
                ret = unzGetCurrentFileInfo(_unzFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
                if( ret!=UNZ_OK )
                {
                        [self OutputErrorMessage:@"Error occurs while getting file info"];
                        success = NO;
                        unzCloseCurrentFile( _unzFile );
                        break;
                }
                char* filename = (char*) malloc( fileInfo.size_filename +1 );
                unzGetCurrentFileInfo(_unzFile, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
                filename[fileInfo.size_filename] = '\0';
                
                // check if it contains directory
                NSString * strPath = [NSString stringWithCString:filename];
                BOOL isDirectory = NO;
                if( filename[fileInfo.size_filename-1]=='/' || filename[fileInfo.size_filename-1]=='\\')
                        isDirectory = YES;
                free( filename );
                if( [strPath rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"/\\"]].location!=NSNotFound )
                {// contains a path
                        strPath = [strPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
                }
                
                // Copy name to array
                [AllFilenames addObject:[strPath copy]];
                                
                unzCloseCurrentFile( _unzFile );
                ret = unzGoToNextFile( _unzFile );
        }  while( ret==UNZ_OK && UNZ_OK!=UNZ_END_OF_LIST_OF_FILE );

        return [AllFilenames autorelease];
}
__________________
dany_dev is offline   Reply With Quote
Old 07-02-2011, 11:13 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 4
nicegyuha is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
using ziparchive - An Objective C class for zip/unzip on iPhone and Mac OSX - Google Project Hosting

you can use this method



Code:
- (NSMutableArray *) getZipFileContents
{
        BOOL success = YES;
        int ret = unzGoToFirstFile( _unzFile );
        NSMutableArray * AllFilenames = [[NSMutableArray alloc] initWithCapacity:40];
        
        if( ret!=UNZ_OK )
        {
                [self OutputErrorMessage:@"Failed"];
        }
        
        do{
                if( [_password length]==0 )
                        ret = unzOpenCurrentFile( _unzFile );
                else
                        ret = unzOpenCurrentFilePassword( _unzFile, [_password cStringUsingEncoding:NSASCIIStringEncoding] );
                if( ret!=UNZ_OK )
                {
                        [self OutputErrorMessage:@"Error occured"];
                        success = NO;
                        break;
                }
                
                // reading data and write to file
                unz_file_info   fileInfo ={0};
                ret = unzGetCurrentFileInfo(_unzFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
                if( ret!=UNZ_OK )
                {
                        [self OutputErrorMessage:@"Error occurs while getting file info"];
                        success = NO;
                        unzCloseCurrentFile( _unzFile );
                        break;
                }
                char* filename = (char*) malloc( fileInfo.size_filename +1 );
                unzGetCurrentFileInfo(_unzFile, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
                filename[fileInfo.size_filename] = '\0';
                
                // check if it contains directory
                NSString * strPath = [NSString stringWithCString:filename];
                BOOL isDirectory = NO;
                if( filename[fileInfo.size_filename-1]=='/' || filename[fileInfo.size_filename-1]=='\\')
                        isDirectory = YES;
                free( filename );
                if( [strPath rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"/\\"]].location!=NSNotFound )
                {// contains a path
                        strPath = [strPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
                }
                
                // Copy name to array
                [AllFilenames addObject:[strPath copy]];
                                
                unzCloseCurrentFile( _unzFile );
                ret = unzGoToNextFile( _unzFile );
        }  while( ret==UNZ_OK && UNZ_OK!=UNZ_END_OF_LIST_OF_FILE );

        return [AllFilenames autorelease];
}
Thank you..
But, I want to see rar compress..
I found PhysicsFS.
PhysicsFS on the Iphone | Gamingseasons
It is a file manager which enables easy access of the contents of quake files(PAK), doom files (WAD), zip files and more.
zip is resolved. However, rar I can not see

Help me~
nicegyuha is offline   Reply With Quote
Reply

Bookmarks

Tags
rar, view, zip

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 341
9 members and 332 guests
apatsufas, chemistry, lendo, leostc, Leslie80, lzwasyc, MarkC, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:32 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0