Overview
Comment: | ofzip: Add support for LHA archives |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
c693041e372f15c49d76172d1656c814 |
User & Date: | js on 2018-05-27 09:44:28 |
Other Links: | manifest | tags |
Context
2018-05-27
| ||
11:07 | OFLHAArchiveEntry: Add support for LHA level 0 check-in: 57f9bc6ace user: js tags: trunk | |
09:44 | ofzip: Add support for LHA archives check-in: c693041e37 user: js tags: trunk | |
07:32 | OFLHAArchiveEntry: Keep the method as a string check-in: 1a6e3816c1 user: js tags: trunk | |
Changes
Added utils/ofzip/LHAArchive.h version [beed29a496].
> > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFLHAArchive.h" #import "Archive.h" @interface LHAArchive: OFObject <Archive> { OFLHAArchive *_archive; } @end |
Added utils/ofzip/LHAArchive.m version [7bf18d4f42].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFApplication.h" #import "OFDate.h" #import "OFFileManager.h" #import "OFLocalization.h" #import "OFNumber.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" #import "LHAArchive.h" #import "OFZIP.h" static OFZIP *app; static void setPermissions(OFString *path, OFLHAArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS of_file_attributes_t attributes = [OFDictionary dictionaryWithObject: [entry mode] forKey: of_file_attribute_key_posix_permissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; #endif } @implementation LHAArchive + (void)initialize { if (self == [LHAArchive class]) app = (OFZIP *)[[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 = [[OFLHAArchive alloc] initWithStream: stream mode: mode]; [_archive setEncoding: encoding]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_archive release]; [super dealloc]; } - (void)listFiles { OFLHAArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); [of_stdout writeLine: [entry fileName]]; if (app->_outputLevel >= 1) { OFString *date = [[entry date] localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *compressedSize = [OFString stringWithFormat: @"%" PRIu32, [entry compressedSize]]; OFString *uncompressedSize = [OFString stringWithFormat: @"%" PRIu32, [entry compressedSize]]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, [entry CRC16]]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compressed_size", @"Compressed: %[size] bytes", @"size", compressedSize)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"Uncompressed: %[size] bytes", @"size", uncompressedSize)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_crc16", @"CRC16: %[crc16]", @"crc16", CRC16)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_date", @"Date: %[date]", @"date", date)]; if ([entry mode] != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_mode", @"Mode: %[mode]", @"mode", [entry mode])]; } if ([entry UID] != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_uid", @"UID: %[uid]", @"uid", [entry UID])]; } if ([entry GID] != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED(@"list_gid", @"GID: %[gid]", @"gid", [entry GID])]; } if ([entry owner] != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_owner", @"Owner: %[owner]", @"owner", [entry owner])]; } if ([entry group] != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_group", @"Group: %[group]", @"group", [entry group])]; } if (app->_outputLevel >= 2) { OFString *level = [OFString stringWithFormat: @"%" PRIu8, [entry level]]; OFString *OSID = [OFString stringWithFormat: @"%c", [entry operatingSystemIdentifier]]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_level", @"Level: %[level]", @"level", level)]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_method", @"Method: %[method]", @"method", [entry method])]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_osid", @"Operating system identifier: %[osid]", @"osid", OSID)]; } } objc_autoreleasePoolPop(pool); } } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; bool all = ([files count] == 0); OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; OFLHAArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = [entry fileName]; OFString *outFileName, *directory; OFFile *output; OFStream *stream; uint64_t written = 0, size = [entry uncompressedSize]; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { [of_stderr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [of_stdout writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if ([fileName hasSuffix: @"/"]) { [fileManager createDirectoryAtPath: outFileName createParents: true]; setPermissions(outFileName, entry); if (app->_outputLevel >= 0) { [of_stdout writeString: @"\r"]; [of_stdout writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } goto outer_loop_end; } directory = [outFileName stringByDeletingLastPathComponent]; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (![stream isAtEndOfStream]) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [of_stdout writeString: @"\r"]; [of_stdout writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } if (app->_outputLevel >= 0) { [of_stdout writeString: @"\r"]; [of_stdout writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } outer_loop_end: objc_autoreleasePoolPop(pool); } if ([missing count] > 0) { for (OFString *file in missing) [of_stderr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files_ { OFMutableSet *files; OFLHAArchiveEntry *entry; if ([files_ count] < 1) { [of_stderr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } files = [OFMutableSet setWithArray: files_]; while ((entry = [_archive nextEntry]) != nil) { OFString *fileName = [entry fileName]; OFStream *stream; if (![files containsObject: fileName]) continue; stream = [_archive streamForReadingCurrentEntry]; while (![stream isAtEndOfStream]) { ssize_t length = [app copyBlockFromStream: stream toStream: of_stdout fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [files removeObject: fileName]; [stream close]; if ([files count] == 0) break; } for (OFString *file in files) { [of_stderr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } @end |
Modified utils/ofzip/Makefile from [91d9609a89] to [8aa9b5a67e].
1 2 3 4 5 6 7 8 9 10 11 | include ../../extra.mk PROG = ofzip${PROG_SUFFIX} SRCS = GZIPArchive.m \ OFZIP.m \ TarArchive.m \ ZIPArchive.m DATA = lang/de.json \ lang/languages.json include ../../buildsys.mk | > | 1 2 3 4 5 6 7 8 9 10 11 12 | include ../../extra.mk PROG = ofzip${PROG_SUFFIX} SRCS = GZIPArchive.m \ LHAArchive.m \ OFZIP.m \ TarArchive.m \ ZIPArchive.m DATA = lang/de.json \ lang/languages.json include ../../buildsys.mk |
︙ | ︙ |
Modified utils/ofzip/OFZIP.m from [ea3185f976] to [fe40a35a63].
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #import "OFOptionsParser.h" #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFURL.h" #import "OFZIP.h" #import "GZIPArchive.h" #import "TarArchive.h" #import "ZIPArchive.h" #import "OFCreateDirectoryFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" | > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #import "OFOptionsParser.h" #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFURL.h" #import "OFZIP.h" #import "GZIPArchive.h" #import "LHAArchive.h" #import "TarArchive.h" #import "ZIPArchive.h" #import "OFCreateDirectoryFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" |
︙ | ︙ | |||
69 70 71 72 73 74 75 | @" -h --help Show this help\n" @" -l --list List all files in the archive\n" @" -n --no-clobber Never overwrite files\n" @" -p --print Print one or more files from the " @"archive\n" @" -q --quiet Quiet mode (no output, except " @"errors)\n" | | > | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | @" -h --help Show this help\n" @" -l --list List all files in the archive\n" @" -n --no-clobber Never overwrite files\n" @" -p --print Print one or more files from the " @"archive\n" @" -q --quiet Quiet mode (no output, except " @"errors)\n" @" -t --type Archive type (gz, lha, tar, tgz, " @"zip)\n" @" -v --verbose Verbose output for file list\n" @" -x --extract Extract files")]; } [OFApplication terminateWithStatus: status]; } |
︙ | ︙ | |||
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | if (type == nil || [type isEqual: @"auto"]) { /* This one has to be first for obvious reasons */ if ([path hasSuffix: @".tar.gz"] || [path hasSuffix: @".tgz"] || [path hasSuffix: @".TAR.GZ"] || [path hasSuffix: @".TGZ"]) type = @"tgz"; else if ([path hasSuffix: @".gz"] || [path hasSuffix: @".GZ"]) type = @"gz"; else if ([path hasSuffix: @".tar"] || [path hasSuffix: @".TAR"]) type = @"tar"; else type = @"zip"; } @try { if ([type isEqual: @"gz"]) archive = [GZIPArchive archiveWithStream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"tar"]) archive = [TarArchive archiveWithStream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"tgz"]) { OFStream *GZIPStream = [OFGZIPStream streamWithStream: file | > > > > > > | 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | if (type == nil || [type isEqual: @"auto"]) { /* This one has to be first for obvious reasons */ if ([path hasSuffix: @".tar.gz"] || [path hasSuffix: @".tgz"] || [path hasSuffix: @".TAR.GZ"] || [path hasSuffix: @".TGZ"]) type = @"tgz"; else if ([path hasSuffix: @".gz"] || [path hasSuffix: @".GZ"]) type = @"gz"; else if ([path hasSuffix: @".lha"] || [path hasSuffix: @".lzh"]) type = @"lha"; else if ([path hasSuffix: @".tar"] || [path hasSuffix: @".TAR"]) type = @"tar"; else type = @"zip"; } @try { if ([type isEqual: @"gz"]) archive = [GZIPArchive archiveWithStream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"lha"]) archive = [LHAArchive archiveWithStream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"tar"]) archive = [TarArchive archiveWithStream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"tgz"]) { OFStream *GZIPStream = [OFGZIPStream streamWithStream: file |
︙ | ︙ |
Modified utils/ofzip/TarArchive.m from [ce3e6885bb] to [f7b1262e85].
︙ | ︙ | |||
320 321 322 323 324 325 326 327 328 329 330 | [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); | > < < | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (![stream isAtEndOfStream]) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; |
︙ | ︙ |
Modified utils/ofzip/ZIPArchive.m from [d55c8d68ef] to [7a34fc0000].
︙ | ︙ | |||
107 108 109 110 111 112 113 | OFString *compressedSize = [OFString stringWithFormat: @"%" PRIu64, [entry compressedSize]]; OFString *uncompressedSize = [OFString stringWithFormat: @"%" PRIu64, [entry uncompressedSize]]; OFString *CRC32 = [OFString | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | OFString *compressedSize = [OFString stringWithFormat: @"%" PRIu64, [entry compressedSize]]; OFString *uncompressedSize = [OFString stringWithFormat: @"%" PRIu64, [entry uncompressedSize]]; OFString *CRC32 = [OFString stringWithFormat: @"%08" PRIX32, [entry CRC32]]; OFString *modificationDate = [[entry modificationDate] localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_compressed_size", @"Compressed: %[size] bytes", |
︙ | ︙ |
Modified utils/ofzip/lang/de.json from [8e600ce35e] to [6ac8dc5514].
︙ | ︙ | |||
11 12 13 14 15 16 17 | " -f --force Existierende Dateien überschreiben\n", " -h --help Diese Hilfe anzeigen\n", " -l --list Alle Dateien im Archiv auflisten\n", " -n --no-clobber Dateien niemals überschreiben\n", " -p --print Eine oder mehr Dateien aus dem Archiv ausgeben", "\n", " -q --quiet Ruhiger Modus (keine Ausgabe außer Fehler)\n", | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | " -f --force Existierende Dateien überschreiben\n", " -h --help Diese Hilfe anzeigen\n", " -l --list Alle Dateien im Archiv auflisten\n", " -n --no-clobber Dateien niemals überschreiben\n", " -p --print Eine oder mehr Dateien aus dem Archiv ausgeben", "\n", " -q --quiet Ruhiger Modus (keine Ausgabe außer Fehler)\n", " -t --type Archiv-Typ (gz, lha, tar, tgz, zip)\n", " -v --verbose Ausführlicher Modus für Datei-Liste\n", " -x --extract Dateien entpacken" ], "2_options_mutually_exclusive": [ "Fehler: -%[shortopt1] / --%[longopt1] und ", "-%[shortopt2] / --%[longopt2] schließen sich gegenseitig aus!" ], |
︙ | ︙ | |||
83 84 85 86 87 88 89 90 91 92 93 94 95 96 | "list_device_minor": "Minor-Nummer des Geräts: %[minor]", "list_type_directory": "Typ: Verzeichnis", "list_type_fifo": "Typ: FIFO", "list_type_contiguous_file": "Typ: Zusammenhängende Datei", "list_type_unknown": "Typ: Unbekannt", "list_compressed_size": "Komprimierte Größe: %[size] Bytes", "list_uncompressed_size": "Unkomprimierte Größe: %[size] Bytes", "list_version_made_by": "Erstellt mit Version: %[version]", "list_min_version_needed": "Mindestens benötigte Version: %[version]", "list_general_purpose_bit_flag": "General Purpose Bit Flag: %[gpbf]", "list_extra_field": "Extra-Feld: %[extra]", "list_comment": "Kommentar: %[comment]", "refusing_to_extract_file": "Verweigere Entpacken von %[file]!", "file_not_in_archive": "Datei %[file] ist nicht im Archiv!", | > > > | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | "list_device_minor": "Minor-Nummer des Geräts: %[minor]", "list_type_directory": "Typ: Verzeichnis", "list_type_fifo": "Typ: FIFO", "list_type_contiguous_file": "Typ: Zusammenhängende Datei", "list_type_unknown": "Typ: Unbekannt", "list_compressed_size": "Komprimierte Größe: %[size] Bytes", "list_uncompressed_size": "Unkomprimierte Größe: %[size] Bytes", "list_date": "Datum: %[date]", "list_method": "Methode: %[method]", "list_osid": "Betriebssystem-Identifikator: %[osid]", "list_version_made_by": "Erstellt mit Version: %[version]", "list_min_version_needed": "Mindestens benötigte Version: %[version]", "list_general_purpose_bit_flag": "General Purpose Bit Flag: %[gpbf]", "list_extra_field": "Extra-Feld: %[extra]", "list_comment": "Kommentar: %[comment]", "refusing_to_extract_file": "Verweigere Entpacken von %[file]!", "file_not_in_archive": "Datei %[file] ist nicht im Archiv!", |
︙ | ︙ |