Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Classes/ZipFileModule.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Originally by TermiT from https://github.com/TermiT/ZipFile
* Updated for Ti SDK 1.7.0 and fixed deprecated functions in minizip
* Updated for Ti SDK 1.7.0 and fixed deprecated functions in minizip
* by Kosso : http://kosso.co.uk
*
* Appcelerator Titanium is Copyright (c) 2009-2010 by Appcelerator, Inc.
Expand All @@ -9,7 +9,7 @@
#import "TiModule.h"
#import "ZipArchive.h"

@interface ZipfileModule : TiModule
@interface ZipfileModule : TiModule
{
}

Expand Down
20 changes: 10 additions & 10 deletions Classes/ZipFileModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ -(void)startup
// this method is called when the module is first loaded
// you *must* call the superclass
[super startup];

NSLog(@"[INFO] %@ loaded",self);
}

Expand All @@ -41,12 +41,12 @@ -(void)shutdown:(id)sender
// this method is called when the module is being unloaded
// typically this is during shutdown. make sure you don't do too
// much processing here or the app will be quit forcibly

// you *must* call the superclass
[super shutdown:sender];
}

#pragma mark Cleanup
#pragma mark Cleanup

-(void)dealloc
{
Expand All @@ -69,7 +69,7 @@ -(void)_listenerAdded:(NSString *)type count:(int)count
{
//if (count == 1 && [type isEqualToString:@"my_event"])
//{
// the first (of potentially many) listener is being added
// the first (of potentially many) listener is being added
// for event named 'my_event'
//}
}
Expand All @@ -92,11 +92,11 @@ -(void)extract:(id)args
NSString *path = [args objectAtIndex:1];

NSFileManager *fileManager = [NSFileManager defaultManager];

if(![fileManager fileExistsAtPath:file]) {
NSLog(@"[DEBUG] Can't find zip file");
}

ZipArchive *zipArchive = [[ZipArchive alloc] init];
if([zipArchive UnzipOpenFile:file]) {
NSLog(@"[DEBUG] zip opened");
Expand All @@ -113,7 +113,7 @@ -(void)extract:(id)args
} else {
NSLog(@"[DEBUG] can't open zip");
}
[zipArchive release];
[zipArchive release];
}


Expand Down Expand Up @@ -156,7 +156,7 @@ -(id)initWithFile:(NSString*)path
[zipArchive release];
zipArchive = nil;
return nil;
}
}
}
return self;
}
Expand All @@ -173,7 +173,7 @@ -(id)initWithExistingFile:(NSString*)path
[zipArchive release];
zipArchive = nil;
return nil;
}
}
}
return self;
}
Expand All @@ -183,7 +183,7 @@ -(id)addFile:(id)args
{
NSString *path = [args objectAtIndex:0];
NSString *newName = [args objectAtIndex:1];

//NSLog(@"[DEBUG] add %@ to zip as %@", path, newName);
return NUMBOOL([zipArchive addFileToZip:path newname:newName]);
}
Expand Down
6 changes: 3 additions & 3 deletions ZipArchive.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// ZipArchive.h
//
//
//
// Created by aish on 08-9-11.
// acsolu@gmail.com
// Copyright 2008 Inc. All rights reserved.
//
// History:
// History:
// 09-11-2008 version 1.0 release
// 10-18-2009 version 1.1 support password protected zip files
// 10-21-2009 version 1.2 fix date bug
Expand All @@ -29,7 +29,7 @@
@private
zipFile _zipFile;
unzFile _unzFile;

NSString* _password;
id _delegate;
}
Expand Down
48 changes: 24 additions & 24 deletions ZipArchive.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// ZipArchive.mm
//
//
//
// Created by aish on 08-9-11.
// acsolu@gmail.com
Expand Down Expand Up @@ -43,7 +43,7 @@ -(void) dealloc
-(BOOL) CreateZipFile2:(NSString*) zipFile
{
_zipFile = zipOpen( (const char*)[zipFile UTF8String], 0 );
if( !_zipFile )
if( !_zipFile )
return NO;
return YES;
}
Expand All @@ -53,7 +53,7 @@ -(BOOL) CreateZipFile2:(NSString*) zipFile
-(BOOL) OpenZipFile2:(NSString*) zipFile
{
_zipFile = zipOpen( (const char*)[zipFile UTF8String], 2 );
if( !_zipFile )
if( !_zipFile )
return NO;
return YES;
}
Expand All @@ -72,7 +72,7 @@ -(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname;
// tm_zip filetime;
time_t current;
time( &current );

zip_fileinfo zipInfo = {0};
// zipInfo.dosDate = (unsigned long) current;
NSError * error;
Expand All @@ -86,7 +86,7 @@ -(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname;
// some application does use dosDate, but tmz_date instead
// zipInfo.dosDate = [fileDate timeIntervalSinceDate:[self Date1980] ];
NSCalendar* currCalendar = [NSCalendar currentCalendar];
uint flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |
uint flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |
NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ;
NSDateComponents* dc = [currCalendar components:flags fromDate:fileDate];
zipInfo.tmz_date.tm_sec = [dc second];
Expand All @@ -97,7 +97,7 @@ -(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname;
zipInfo.tmz_date.tm_year = [dc year];
}
}

int ret ;
NSData* data = nil;
if( [_password length] == 0 )
Expand Down Expand Up @@ -191,7 +191,7 @@ -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite
{
[self OutputErrorMessage:@"Failed"];
}

do{
if( [_password length]==0 )
ret = unzOpenCurrentFile( _unzFile );
Expand All @@ -217,7 +217,7 @@ -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite
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 encoding:NSUTF8StringEncoding];
BOOL isDirectory = NO;
Expand All @@ -229,7 +229,7 @@ -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite
strPath = [strPath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
}
NSString* fullPath = [path stringByAppendingPathComponent:strPath];

if( isDirectory )
[fman createDirectoryAtPath:fullPath withIntermediateDirectories:YES attributes:nil error:nil];
else
Expand All @@ -256,48 +256,48 @@ -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite
[self OutputErrorMessage:@"Failed to reading zip file"];
break;
}
else
break;
else
break;
}
if( fp )
{
fclose( fp );
// set the orignal datetime property
NSDate* orgDate = nil;

//{{ thanks to brad.eaton for the solution
NSDateComponents *dc = [[NSDateComponents alloc] init];

dc.second = fileInfo.tmu_date.tm_sec;
dc.minute = fileInfo.tmu_date.tm_min;
dc.hour = fileInfo.tmu_date.tm_hour;
dc.day = fileInfo.tmu_date.tm_mday;
dc.month = fileInfo.tmu_date.tm_mon+1;
dc.year = fileInfo.tmu_date.tm_year;
NSCalendar *gregorian = [[NSCalendar alloc]

NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];

orgDate = [gregorian dateFromComponents:dc] ;
[dc release];
[gregorian release];
//}}


NSDictionary* attr = [NSDictionary dictionaryWithObject:orgDate forKey:NSFileModificationDate]; //[[NSFileManager defaultManager] fileAttributesAtPath:fullPath traverseLink:YES];
if( attr )
{
// [attr setValue:orgDate forKey:NSFileCreationDate];
if( ![[NSFileManager defaultManager] setAttributes:attr ofItemAtPath:fullPath error:nil] )
{
// cann't set attributes
// cann't set attributes
NSLog(@"Failed to set attributes");
}

}



}
unzCloseCurrentFile( _unzFile );
ret = unzGoToNextFile( _unzFile );
Expand Down Expand Up @@ -337,7 +337,7 @@ -(NSDate*) Date1980
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:comps];

[comps release];
[gregorian release];
return date;
Expand Down
4 changes: 2 additions & 2 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Titanium.UI.setBackgroundColor('#000');

var zipfile = require("zipfile");
var zipfile = require("zipfile");

var win1 = Titanium.UI.createWindow({
var win1 = Titanium.UI.createWindow({
title:'ZipFile test',
backgroundColor:'#fff'
});
Expand Down
30 changes: 15 additions & 15 deletions minizip/mztools.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ uLong* bytesRecovered;
unsigned int fnsize = READ_16(header + 26); /* file name length */
unsigned int extsize = READ_16(header + 28); /* extra field length */
filename[0] = extra[0] = '\0';

/* Header */
if (fwrite(header, 1, 30, fpOut) == 30) {
offset += 30;
} else {
err = Z_ERRNO;
break;
}

/* Filename */
if (fnsize > 0) {
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
Expand Down Expand Up @@ -103,7 +103,7 @@ uLong* bytesRecovered;
break;
}
}

/* Data */
{
int dataSize = cpsize;
Expand Down Expand Up @@ -133,7 +133,7 @@ uLong* bytesRecovered;
}
}
}

/* Central directory entry */
{
char header[46];
Expand All @@ -159,7 +159,7 @@ uLong* bytesRecovered;
/* Header */
if (fwrite(header, 1, 46, fpOutCD) == 46) {
offsetCD += 46;

/* Filename */
if (fnsize > 0) {
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
Expand All @@ -172,7 +172,7 @@ uLong* bytesRecovered;
err = Z_STREAM_ERROR;
break;
}

/* Extra field */
if (extsize > 0) {
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
Expand All @@ -182,7 +182,7 @@ uLong* bytesRecovered;
break;
}
}

/* Comment field */
if (comsize > 0) {
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
Expand All @@ -192,8 +192,8 @@ uLong* bytesRecovered;
break;
}
}


} else {
err = Z_ERRNO;
break;
Expand Down Expand Up @@ -225,17 +225,17 @@ uLong* bytesRecovered;
WRITE_32(header + 12, offsetCD); /* size of CD */
WRITE_32(header + 16, offset); /* offset to CD */
WRITE_16(header + 20, comsize); /* comment */

/* Header */
if (fwrite(header, 1, 22, fpOutCD) == 22) {

/* Comment field */
if (comsize > 0) {
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
err = Z_ERRNO;
}
}

} else {
err = Z_ERRNO;
}
Expand All @@ -257,14 +257,14 @@ uLong* bytesRecovered;
fclose(fpOutCD);
}
}

/* Close */
fclose(fpZip);
fclose(fpOut);

/* Wipe temporary file */
(void)remove(fileOutTmp);

/* Number of recovered entries */
if (err == Z_OK) {
if (nRecovered != NULL) {
Expand Down
Loading