开发者

decompression error while putting together parts with macHacha

开发者 https://www.devze.com 2023-03-17 04:30 出处:网络
OK I have app for iPad that reads magazines. All previous issues works fine. I manage to make new issue (before it was done by other guy that left the firm) and to run it in simulator and on device wi

OK I have app for iPad that reads magazines. All previous issues works fine. I manage to make new issue (before it was done by other guy that left the firm) and to run it in simulator and on device without problems.

Now I add row for new issue of magazine in database and compress all pictures and multimedia by ZIP tool and divide them by MacHacha (because Java class that uploads demand parts from MacHacha to upload one by one) and upload it on server. In App store I downloaded magazine and can see new issue. On server new row is good have all good parameters and the size is adequate to size on disk.

When new issue finnish download it shows me error. I tried same procedure from simulator and in OUTPUT in the moment it crashes shows me decompression error (0).

I supposed that problem is with putting parts together with MacHacha. Can anyone help or give me that catch that solves this problem.

if it will help I can upload new issue and provide link (it's free) I it will be helpful for You guys and girls :)

http://www.mazzantieditori.it/applicazioni/219-nycit-italian-american-magazine.html

link for application. In library there is few issues and the last one is new (Giugno 2011).

I will provide code for that method that gives me string for mistake:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

{

// controllo se il receipt è corretto e faccio partire il download if(min == 0 && [receivedData length]

NSString *file = [[self documentsDir:1] stringByAppendingPathComponent:@"archivio.zip"];

if (max <= num && !cancelDownload) {
    self.progressBar.progress = (1.0f/num)*min;
    min = max+1;
    max += 5;

    // creo directory per l'elemento scaricato
    BOOL isDir = NO;

    if(![[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDir]) {
        NSError *error;
        //creo directory
        [[NSFileManager defaultManager] createDirectoryAtPath:[self documentsDir:1] withIntermediateDirectories:YES attributes:nil error:&error];
        //creo file vuoto
        [[NSFileManager defaultManager] createFileAtPath:file contents:nil attributes:nil];
    }

    NSFileHandle *handler = [NSFileHandle fileHandleForWritingAtPath:file];

    if(handler) {
        [handler seekToEndOfFile];
        [handler writeData:receivedData];
    }
    NSLog(@"Received %d bytes of data; min: %i max: %i",[receivedData length],min,max);
    [receivedData setLength:0];

    // questa è la seconda invocazione
    [self downloadArchivePart:@"verified"];
    [connection release];
    return;
}

NSFileManager *man = [[NSFileManager alloc] init];
NSDictionary *attrs = [man attributesOfItemAtPath:file error: NULL];
//UInt32 result = 
NSNumber *size = [attrs objectForKey:NSFileSize];
//int length = [receivedData length];
NSLog(@"Succeeded! Received %i bytes of data",[size intValue]);
[man release];

//1.038.090 è il numero di byte della parte più piccola dell'archivio
if([size intValue]  >= kMinPartSize) {  

    NSLog(@"prod %@",self.prodName);
    if(self.prodName == nil || [self.prodName isEqualToString:@""]) self.prodName = prodId;         

    NSError *error;
    BOOL ok = [TWZipArchive unzipFileAtPath:file toDestination:[self documentsDir:1] overwrite:YES password:nil error:&error];
    //unzipFileAtPath:file toDestination:[self documentsDir]];

    NSString *msg;
    if(ok) {
        NSLog(@"decompression successfull");
        self.progressBar.progress = 1.0f;
        NSFileManager *fm = [NSFileManager defaultManager];
        [fm removeItemAtPath:file error:&error];
        msg = @"Download completed: new issue added in libray";

        NSMutableArray *array;
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        NSString *path = [[self documentsDir:0] stringByAppendingPathComponent:@"downloaded.plist"];
        if(![[NSFileManager defaultManager] fileExistsAtPath:path]) {   
            [dict setObject:prodId forKey:@"id"];
            [dict setObject:prodName forKey:@"titolo"];
            array = [NSArray arrayWithObject:dict];
            [array writeToFile:path atomically:YES];
        }
        array = [NSMutableArray arrayWithContentsOfFile:path];
        BOOL exist = NO;
        for (int i=0; i<[array count]; i++) {
            if ([[[array objectAtIndex:i] objectForKey:@"id"] isEqualToString:prodId]) {
                exist = YES;
                //prodId = [NSString stringWithFormat:@"%@%i",prodId,i];
            }
        }   

        if(exist == NO) {
            [dict setObject:prodId forKey:@"id"];
            [dict setObject:prodName forKey:@"titolo"];
            [array insertObject:dict atIndex:0];    //sempre in testa l'ultimo elemento scaricato
            [array writeToFile:path atomically:YES];
        }

    }
    else {
    开发者_Go百科    NSLog(@"decompression error");
        msg = @"An error has occurred";
    }

    //[myAlert release];
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                    message:@"Download completed: new issue added in libray"
                                                   delegate:self 
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles: nil];
    [alert show];

    //[alert release];
}else {

    if(cancelDownload == YES) {

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                        message:@"Download stopped for user action" 
                                                       delegate:self 
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];

    }else {

        NSString *errFile = [[self documentsDir:1] stringByAppendingPathComponent:@"errFile.html"]; 
        [receivedData writeToFile:errFile atomically:YES];
        NSLog(@"err : %@",errFile);
        NSLog(@"scrittura error file eseguita");

        NSLog(@"receipt non valido");
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"NYC.IT"
                                                  message:@"Downloading error: please retry later!" 
                                                  delegate:self 
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles: nil];
        [alert show];
    }


}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
progressBar.hidden = YES;

// release the connection, and the data object
[connection release];
//[receivedData release];

}

Thanks in Advance...


I dont know about x-code but this is useful library http://www.winimage.com/zLibDll/minizip.html

0

精彩评论

暂无评论...
验证码 换一张
取 消