06-30-2011, 09:54 PM
#1 (permalink )
Registered Member
Join Date: Dec 2009
Posts: 4
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
07-01-2011, 02:24 AM
#2 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
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];
}
__________________
07-02-2011, 11:13 AM
#3 (permalink )
Registered Member
Join Date: Dec 2009
Posts: 4
Quote:
Originally Posted by
dany_dev
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~
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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