37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
static OFArc *app;
static void
setPermissions(OFString *path, OFZIPArchiveEntry *entry)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
if ((entry.versionMadeBy >> 8) ==
OF_ZIP_ARCHIVE_ENTRY_ATTR_COMPAT_UNIX) {
OFNumber *mode = [OFNumber numberWithUnsignedShort:
(entry.versionSpecificAttributes >> 16) & 0777];
of_file_attribute_key_t key =
of_file_attribute_key_posix_permissions;
of_file_attributes_t attributes =
[OFDictionary dictionaryWithObject: mode forKey: key];
[[OFFileManager defaultManager] setAttributes: attributes
ofItemAtPath: path];
}
#endif
}
static void
setModificationDate(OFString *path, OFZIPArchiveEntry *entry)
{
OFDate *modificationDate = entry.modificationDate;
of_file_attributes_t attributes;
if (modificationDate == nil)
return;
attributes = [OFDictionary
dictionaryWithObject: modificationDate
forKey: of_file_attribute_key_modification_date];
[[OFFileManager defaultManager] setAttributes: attributes
ofItemAtPath: path];
}
@implementation ZIPArchive
+ (void)initialize
{
if (self == [ZIPArchive class])
app = (OFArc *)[OFApplication sharedApplication].delegate;
}
+ (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
encoding: (of_string_encoding_t)encoding
{
return [[[self alloc] initWithStream: stream
mode: mode
encoding: encoding] autorelease];
}
- (instancetype)initWithStream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
encoding: (of_string_encoding_t)encoding
{
self = [super init];
@try {
_archive = [[OFZIPArchive alloc] initWithStream: stream
mode: mode];
} @catch (id e) {
|
|
<
<
|
|
>
|
|
|
|
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
static OFArc *app;
static void
setPermissions(OFString *path, OFZIPArchiveEntry *entry)
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
if ((entry.versionMadeBy >> 8) ==
OFZIPArchiveEntryAttributeCompatibilityUNIX) {
OFNumber *mode = [OFNumber numberWithUnsignedShort:
(entry.versionSpecificAttributes >> 16) & 0777];
OFFileAttributes attributes = [OFDictionary
dictionaryWithObject: mode
forKey: OFFilePOSIXPermissions];
[[OFFileManager defaultManager] setAttributes: attributes
ofItemAtPath: path];
}
#endif
}
static void
setModificationDate(OFString *path, OFZIPArchiveEntry *entry)
{
OFDate *modificationDate = entry.modificationDate;
OFFileAttributes attributes;
if (modificationDate == nil)
return;
attributes = [OFDictionary
dictionaryWithObject: modificationDate
forKey: OFFileModificationDate];
[[OFFileManager defaultManager] setAttributes: attributes
ofItemAtPath: path];
}
@implementation ZIPArchive
+ (void)initialize
{
if (self == [ZIPArchive class])
app = (OFArc *)[OFApplication sharedApplication].delegate;
}
+ (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithStream: stream
mode: mode
encoding: encoding] autorelease];
}
- (instancetype)initWithStream: (OF_KINDOF(OFStream *))stream
mode: (OFString *)mode
encoding: (OFStringEncoding)encoding
{
self = [super init];
@try {
_archive = [[OFZIPArchive alloc] initWithStream: stream
mode: mode];
} @catch (id e) {
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
OFString *compressedSize = [OFString
stringWithFormat: @"%" PRIu64,
entry.compressedSize];
OFString *uncompressedSize = [OFString
stringWithFormat: @"%" PRIu64,
entry.uncompressedSize];
OFString *compressionMethod =
of_zip_archive_entry_compression_method_to_string(
entry.compressionMethod);
OFString *CRC32 = [OFString
stringWithFormat: @"%08" PRIX32, entry.CRC32];
OFString *modificationDate = [entry.modificationDate
localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];
[of_stdout writeString: @"\t"];
|
|
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
OFString *compressedSize = [OFString
stringWithFormat: @"%" PRIu64,
entry.compressedSize];
OFString *uncompressedSize = [OFString
stringWithFormat: @"%" PRIu64,
entry.uncompressedSize];
OFString *compressionMethod =
OFZIPArchiveEntryCompressionMethodName(
entry.compressionMethod);
OFString *CRC32 = [OFString
stringWithFormat: @"%08" PRIX32, entry.CRC32];
OFString *modificationDate = [entry.modificationDate
localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];
[of_stdout writeString: @"\t"];
|
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
[of_stdout writeLine: OF_LOCALIZED(
@"list_modification_date",
@"Modification date: %[date]",
@"date", modificationDate)];
if (app->_outputLevel >= 2) {
uint16_t versionMadeBy = entry.versionMadeBy;
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_version_made_by",
@"Version made by: %[version]",
@"version",
of_zip_archive_entry_version_to_string(
versionMadeBy))];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_min_version_needed",
@"Minimum version needed: %[version]",
@"version",
of_zip_archive_entry_version_to_string(
entry.minVersionNeeded))];
if ((versionMadeBy >> 8) ==
OF_ZIP_ARCHIVE_ENTRY_ATTR_COMPAT_UNIX) {
uint32_t mode = entry
.versionSpecificAttributes >> 16;
OFString *modeString = [OFString
stringWithFormat: @"%06o", mode];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_mode",
|
>
>
|
|
|
<
|
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
[of_stdout writeLine: OF_LOCALIZED(
@"list_modification_date",
@"Modification date: %[date]",
@"date", modificationDate)];
if (app->_outputLevel >= 2) {
uint16_t versionMadeBy = entry.versionMadeBy;
OFZIPArchiveEntryAttributeCompatibility UNIX =
OFZIPArchiveEntryAttributeCompatibilityUNIX;
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_version_made_by",
@"Version made by: %[version]",
@"version",
OFZIPArchiveEntryVersionToString(
versionMadeBy))];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_min_version_needed",
@"Minimum version needed: %[version]",
@"version",
OFZIPArchiveEntryVersionToString(
entry.minVersionNeeded))];
if ((versionMadeBy >> 8) == UNIX) {
uint32_t mode = entry
.versionSpecificAttributes >> 16;
OFString *modeString = [OFString
stringWithFormat: @"%06o", mode];
[of_stdout writeString: @"\t"];
[of_stdout writeLine: OF_LOCALIZED(
@"list_mode",
|
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
return;
}
for (OFString *localFileName in files) {
void *pool = objc_autoreleasePoolPush();
OFArray OF_GENERIC (OFString *) *components;
OFString *fileName;
of_file_attributes_t attributes;
bool isDirectory = false;
OFMutableZIPArchiveEntry *entry;
unsigned long long size;
OFStream *output;
components = localFileName.pathComponents;
fileName = [components componentsJoinedByString: @"/"];
attributes = [fileManager
attributesOfItemAtPath: localFileName];
if ([attributes.fileType isEqual: of_file_type_directory]) {
isDirectory = true;
fileName = [fileName stringByAppendingString: @"/"];
}
if (app->_outputLevel >= 0)
[of_stdout writeString: OF_LOCALIZED(@"adding_file",
@"Adding %[file]...",
@"file", fileName)];
entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName];
size = (isDirectory ? 0 : attributes.fileSize);
if (size > INT64_MAX)
@throw [OFOutOfRangeException exception];
entry.compressedSize = (int64_t)size;
entry.uncompressedSize = (int64_t)size;
entry.compressionMethod =
OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_NONE;
entry.modificationDate = attributes.fileModificationDate;
[entry makeImmutable];
output = [_archive streamForWritingEntry: entry];
if (!isDirectory) {
|
|
|
|
|
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
return;
}
for (OFString *localFileName in files) {
void *pool = objc_autoreleasePoolPush();
OFArray OF_GENERIC (OFString *) *components;
OFString *fileName;
OFFileAttributes attributes;
bool isDirectory = false;
OFMutableZIPArchiveEntry *entry;
unsigned long long size;
OFStream *output;
components = localFileName.pathComponents;
fileName = [components componentsJoinedByString: @"/"];
attributes = [fileManager
attributesOfItemAtPath: localFileName];
if ([attributes.fileType isEqual: OFFileTypeDirectory]) {
isDirectory = true;
fileName = [fileName stringByAppendingString: @"/"];
}
if (app->_outputLevel >= 0)
[of_stdout writeString: OF_LOCALIZED(@"adding_file",
@"Adding %[file]...",
@"file", fileName)];
entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName];
size = (isDirectory ? 0 : attributes.fileSize);
if (size > INT64_MAX)
@throw [OFOutOfRangeException exception];
entry.compressedSize = (int64_t)size;
entry.uncompressedSize = (int64_t)size;
entry.compressionMethod =
OFZIPArchiveEntryCompressionMethodNone;
entry.modificationDate = attributes.fileModificationDate;
[entry makeImmutable];
output = [_archive streamForWritingEntry: entry];
if (!isDirectory) {
|