Comments (4)
Were you looking for NSFileCreationDate ? its there, in NSFileManager.h (on
iphone SDK 3.0 at least).
BTW: Trying to unzip, I got a bad modification date (in 2010) from your NSDate*
orgDate = [[NSDate alloc]
initWithTimeInterval:(NSTimeInterval)fileInfo.dosDate sinceDate:[self
Date1980] ]
Are you sure that fileInfo.dosDate is actually the number of seconds since
1980? Googling "MSDOS Date
format in pkzip" it seems to be packed date fields (seconds, minutes, hours,
day, etc).
Thanks for posting this.
Original comment by [email protected]
on 13 Jul 2009 at 9:44
from elziparchive.
I don't think it is number of seconds since 1980. I had this same problem and
worked around it with the
following mod to upzipFileTo:overWrite:
-(BOOL) unzipFileTo:(NSString*)path overWrite:(BOOL)overWrite
{
BOOL success = YES;
int ret = unzGoToFirstFile( _unzFile );
unsigned char buffer[4096] = {0};
NSFileManager* fman = [NSFileManager defaultManager];
if( ret!=UNZ_OK )
{
[self outputErrorMessage:@"Failed"];
}
do {
ret = unzOpenCurrentFile( _unzFile );
if( ret!=UNZ_OK )
{
[self outputErrorMessage:@"Error occurs"];
success = NO;
break;
}
// reading data and write to file
int read ;
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:@"/"];
}
NSString* fullPath = [path stringByAppendingPathComponent:strPath];
if( isDirectory )
[fman createDirectoryAtPath:fullPath withIntermediateDirectories:YES attributes:nil error:nil];
else
[fman createDirectoryAtPath:[fullPath stringByDeletingLastPathComponent]
withIntermediateDirectories:YES attributes:nil error:nil];
if( [fman fileExistsAtPath:fullPath] && !isDirectory && !overWrite )
{
if( ![self overWrite:fullPath] )
{
unzCloseCurrentFile( _unzFile );
ret = unzGoToNextFile( _unzFile );
continue;
}
}
FILE* fp = fopen( (const char*)[fullPath UTF8String], "wb");
while( fp )
{
read=unzReadCurrentFile(_unzFile, buffer, 4096);
if( read > 0 )
{
fwrite(buffer, read, 1, fp );
}
else if( read<0 )
{
[self outputErrorMessage:@"Failed to reading zip file"];
break;
}
else
break;
}
if( fp )
{
fclose( fp );
// set the orignal datetime property
if( fileInfo.dosDate!=0 )
{
//NSNumber *secondsSince1980 = [NSNumber numberWithUnsignedLong:fileInfo.dosDate];
//NSDate* orgDate = [[NSDate alloc]
// initWithTimeInterval:[secondsSince1980 doubleValue]
// sinceDate:[self Date1980] ];
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]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *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
NSLog(@"Failed to set attributes");
}
}
//[orgDate release];
//orgDate = nil;
}
}
unzCloseCurrentFile( _unzFile );
ret = unzGoToNextFile( _unzFile );
}while( ret==UNZ_OK && UNZ_OK!=UNZ_END_OF_LIST_OF_FILE );
return success;
}
Original comment by [email protected]
on 22 Jul 2009 at 9:57
from elziparchive.
thanks brad.eaton for your solution.
after doing some deep research, I found some applications will not use
"dosDate" field as the creation date,
instead they use tmz_date section. Now I changed to use tmz_date as well during
compression process.
Original comment by [email protected]
on 21 Oct 2009 at 3:38
from elziparchive.
Thanks for your work.
Original comment by [email protected]
on 4 Dec 2009 at 5:54
from elziparchive.
Related Issues (20)
- Adding large filles problem HOT 2
- Unzip error HOT 1
- Use of deprecated NSString call in ZipArchive class
- minizip - zip.c Value stored to 'err' is never read, unzip.c Value stored to 'lSeek' is never read and Value stored to 'err' is never read
- unable to unzip zipped file when supplying password at zip creation HOT 2
- Unzip cannot handle unicode filenames HOT 1
- UnzipOpenFile always failed
- Assigning a ZipArchiveDelegate to grab the error messages does not work HOT 1
- Compile error:invalid deployment target for -stdlib=libc++ (requires iOS 5.0 or later) HOT 1
- Compile warning HOT 1
- ARC compliance, analyzer warnings, code semantics, etc. HOT 2
- @property (nonatomic, retain) id delegate??????? HOT 1
- ARC, compiler warnings, minor bug fixes, and documentation
- If folder is empty the folder is not added in the zip file
- If ZipArchive had some limit of the size of the package and the number of the package when unzipping?
- not able to unzip files zipped with pkzip on mac
- License terms?
- Zip a folder 2 Gb on Ipad crash the app (Problem Memory)
- Insufficient Entropy (CWE ID 331)
- Error Handling Issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elziparchive.