views:

64

answers:

1

Hi all.....

i am new to iPhone programming..can anybody help me out from the following problem

i am using the fallowing code to unarcive a zip file.. its not working... and printing the NSLog(@"Failure To Unzip Archive"); msg

self.fileManager = [NSFileManager defaultManager];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);

self.documentsDir = [paths objectAtIndex:0];

NSString *filePath = [NSString stringWithFormat:@"%@/temp", self.documentsDir];

NSString *updateURL = [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:@"bmlgg.zip"];


NSLog(@"Checking update at : %@", updateURL);

NSLog(@"Checking filepath at : %@", filePath);


    ZipArchive *zipArchive = [[ZipArchive alloc] init];

    if([zipArchive UnzipOpenFile:updateURL]) {

        if ([zipArchive UnzipFileTo:filePath overWrite:YES]) {
            //unzipped successfully
            NSLog(@"Archive unzip Success");
            //[self.fileManager removeItemAtPath:filePath error:NULL];
        } else {
            NSLog(@"Failure To Unzip Archive");             
        }

    } else  {
        NSLog(@"Failure To Open Archive");
    }

    [zipArchive release];

thank u....

A: 

Hi.. all

i got the solution...

the problem is the zip file is not recognized... i changed the fallowing code

NSString *updateURL = [[NSBundle mainBundle] pathForResource:@"bmlg" ofType:@"zip" inDirectory:@"res"];

this helped me

self.fileManager = [NSFileManager defaultManager];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);

self.documentsDir = [paths objectAtIndex:0];

NSString *filePath = [NSString stringWithFormat:@"%@/temp", self.documentsDir];

NSString *updateURL = [[NSBundle mainBundle] pathForResource:@"bmlg" ofType:@"zip" inDirectory:@"res"];


[fileManager createDirectoryAtPath:filePath withIntermediateDirectories:NO  attributes:nil  error:nil];


       if([fileManager fileExistsAtPath:updateURL]) {
        NSLog(@"File exists at path: %@", updateURL);
    } else {
        NSLog(@"File does not exists at path: %@", updateURL);
    }

    NSLog(@"Checking update at : %@", updateURL); 

    NSLog(@"Checking filepath at : %@", filePath);


    ZipArchive *zipArchive = [[ZipArchive alloc] init];

    if([zipArchive UnzipOpenFile:updateURL]) {

        if ([zipArchive UnzipFileTo:filePath overWrite:YES]) {
            //unzipped successfully
            NSLog(@"Archive unzip Success");
            //[self.fileManager removeItemAtPath:filePath error:NULL];
        } else {
            NSLog(@"Failure To Unzip Archive");             
        }

    } else  {
        NSLog(@"Failure To Open Archive");
    }

    [zipArchive release];
rockey