Overview
Comment: | ofarc: Add support for Zoo archives |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
aaf991863afd5ad1e8a8dfa3480047a0 |
User & Date: | js on 2024-02-28 20:13:53 |
Other Links: | manifest | tags |
Context
2024-02-28
| ||
20:27 | OFZooArchive: Throw exception for mode `w` / `a` check-in: a22b485eaf user: js tags: trunk | |
20:13 | ofarc: Add support for Zoo archives check-in: aaf991863a user: js tags: trunk | |
00:41 | Fix missing import check-in: 4f9e27d416 user: js tags: trunk | |
Changes
Modified utils/ofarc/Makefile from [75fcfbcaa1] to [9ffce288e6].
1 2 3 4 5 6 7 | include ../../extra.mk PROG = ofarc${PROG_SUFFIX} SRCS = GZIPArchive.m \ LHAArchive.m \ OFArc.m \ TarArchive.m \ | | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | include ../../extra.mk PROG = ofarc${PROG_SUFFIX} SRCS = GZIPArchive.m \ LHAArchive.m \ OFArc.m \ TarArchive.m \ ZIPArchive.m \ ZooArchive.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofarc |
︙ | ︙ |
Modified utils/ofarc/OFArc.m from [e196e4c527] to [b277cdf39b].
︙ | ︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #import "OFStdIOStream.h" #import "OFArc.h" #import "GZIPArchive.h" #import "LHAArchive.h" #import "TarArchive.h" #import "ZIPArchive.h" #import "OFCreateDirectoryFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" | > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #import "OFStdIOStream.h" #import "OFArc.h" #import "GZIPArchive.h" #import "LHAArchive.h" #import "TarArchive.h" #import "ZIPArchive.h" #import "ZooArchive.h" #import "OFCreateDirectoryFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" |
︙ | ︙ | |||
57 58 59 60 61 62 63 | [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", @"Options:\n" @" -a --append Append to archive\n" @" -c --create Create archive\n" @" -C --directory= Extract into the specified " @"directory\n" | | | | | 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 | [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", @"Options:\n" @" -a --append Append to archive\n" @" -c --create Create archive\n" @" -C --directory= Extract into the specified " @"directory\n" @" -E --encoding= The encoding used by the archive\n" @" (only tar, lha and zoo files)\n" @" -f --force Force / overwrite files\n" @" -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, zoo)\n" @" -v --verbose Verbose output for file list\n" @" -x --extract Extract files")]; } [OFApplication terminateWithStatus: status]; } |
︙ | ︙ | |||
552 553 554 555 556 557 558 559 | @"file", e.path, @"error", error)]; [OFApplication terminateWithStatus: 1]; } } if (type == nil || [type isEqual: @"auto"]) { /* This one has to be first for obvious reasons */ | > > | | | | | > | | > > | 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | @"file", e.path, @"error", error)]; [OFApplication terminateWithStatus: 1]; } } if (type == nil || [type isEqual: @"auto"]) { OFString *lowercasePath = path.lowercaseString; /* This one has to be first for obvious reasons */ if ([lowercasePath hasSuffix: @".tar.gz"] || [lowercasePath hasSuffix: @".tgz"]) type = @"tgz"; else if ([lowercasePath hasSuffix: @".gz"]) type = @"gz"; else if ([lowercasePath hasSuffix: @".lha"] || [lowercasePath hasSuffix: @".lzh"] || [lowercasePath hasSuffix: @".lzs"] || [lowercasePath hasSuffix: @".pma"]) type = @"lha"; else if ([lowercasePath hasSuffix: @".tar"]) type = @"tar"; else if ([lowercasePath hasSuffix: @".zoo"]) type = @"zoo"; else type = @"zip"; } @try { if ([type isEqual: @"gz"]) archive = [GZIPArchive archiveWithPath: path |
︙ | ︙ | |||
595 596 597 598 599 600 601 602 603 604 605 606 607 608 | archive = [TarArchive archiveWithPath: path stream: GZIPStream mode: modeString encoding: encoding]; } else if ([type isEqual: @"zip"]) archive = [ZIPArchive archiveWithPath: path stream: file mode: modeString encoding: encoding]; else { [OFStdErr writeLine: OF_LOCALIZED( @"unknown_archive_type", @"Unknown archive type: %[type]", @"type", type)]; | > > > > > | 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | archive = [TarArchive archiveWithPath: path stream: GZIPStream mode: modeString encoding: encoding]; } else if ([type isEqual: @"zip"]) archive = [ZIPArchive archiveWithPath: path stream: file mode: modeString encoding: encoding]; else if ([type isEqual: @"zoo"]) archive = [ZooArchive archiveWithPath: path stream: file mode: modeString encoding: encoding]; else { [OFStdErr writeLine: OF_LOCALIZED( @"unknown_archive_type", @"Unknown archive type: %[type]", @"type", type)]; |
︙ | ︙ |
Added utils/ofarc/ZooArchive.h version [934a7d265c].
> > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * 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 "OFZooArchive.h" #import "Archive.h" @interface ZooArchive: OFObject <Archive> { OFZooArchive *_archive; } @end |
Added utils/ofarc/ZooArchive.m version [f7ecaea67e].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * 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" #include <errno.h> #import "OFApplication.h" #import "OFDate.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFString.h" #import "ZooArchive.h" #import "OFArc.h" #import "OFSetItemAttributesFailedException.h" static OFArc *app; static void setModificationDate(OFString *path, OFZooArchiveEntry *entry) { OFFileAttributes attributes = [OFDictionary dictionaryWithObject: entry.modificationDate forKey: OFFileModificationDate]; @try { [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @catch (OFSetItemAttributesFailedException *e) { if (e.errNo != EISDIR) @throw e; } } @implementation ZooArchive + (void)initialize { if (self == [ZooArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithPath: (OFString *)path stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithPath: path stream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithPath: (OFString *)path stream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [[OFZooArchive alloc] initWithStream: stream mode: mode]; if (encoding != OFStringEncodingAutodetect) _archive.encoding = encoding; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_archive release]; [super dealloc]; } - (void)listFiles { OFZooArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *compressedSize = [OFString stringWithFormat: @"%llu", entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%llu", entry.uncompressedSize]; OFString *compressionMethod = [OFString stringWithFormat: @"%u", entry.compressionMethod]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, entry.CRC16]; OFString *deleted = [OFString stringWithFormat: @"%u", entry.deleted]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" @" 'Compressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", compressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"[" @" 'Uncompressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", uncompressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", @"method", compressionMethod)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_crc16", @"CRC16: %[crc16]", @"crc16", CRC16)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_deleted", @"[" @" 'Deleted: '," @" [" @" {'deleted == 0': 'No'}," @" {'': 'Yes'}" @" ]" @"]".objectByParsingJSON, @"deleted", deleted)]; if (entry.fileComment.length > 0) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_comment", @"Comment: %[comment]", @"comment", entry.fileComment)]; } } 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]; OFZooArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFFile *output; OFStream *stream; unsigned long long 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) { [OFStdErr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; 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"]; while (!stream.atEndOfStream) { 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]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } [output close]; setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut 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) [OFStdErr 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; OFZooArchiveEntry *entry; if (files_.count < 1) { [OFStdErr 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.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: OFStdOut fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [files removeObject: fileName]; [stream close]; if (files.count == 0) break; } for (OFString *file in files) { [OFStdErr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } @end |
Modified utils/ofarc/localization/de.json from [6342f66425] to [f7f6a86a4c].
︙ | ︙ | |||
14 15 16 17 18 19 20 | "Benutzung: %[prog] -[acCfhlnpqtvx] archiv.zip [datei1 datei2 ...]" ], full_usage: [ "Optionen:\n", " -a --append Zu Archiv hinzufügen\n", " -c --create Archiv erstellen\n", " -C --directory= In angegebenes Verzeichnis entpacken\n", | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | "Benutzung: %[prog] -[acCfhlnpqtvx] archiv.zip [datei1 datei2 ...]" ], full_usage: [ "Optionen:\n", " -a --append Zu Archiv hinzufügen\n", " -c --create Archiv erstellen\n", " -C --directory= In angegebenes Verzeichnis entpacken\n", " -E --encoding= Das Encoding des Archivs (nur tar-, ", "lha- und zoo-Dateien)\n", " -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, zoo)\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!" ], |
︙ | ︙ | |||
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | list_osid: "Betriebssystem-Identifikator: %[osid]", list_extensions: "Erweiterungen: %[extensions]", 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!", print_no_file_specified: [ "Benötige eine oder mehrere Dateien zum Ausgeben!" ], add_no_file_specified: [ "Benötige eine oder mehrere Dateien zum Hinzufügen!" ], adding_file: "Füge %[file] hinzu...", adding_file_percent: "Füge %[file] hinzu... %[percent]%", adding_file_done: "Füge %[file] hinzu... fertig", } | > > > > > > > | 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 | list_osid: "Betriebssystem-Identifikator: %[osid]", list_extensions: "Erweiterungen: %[extensions]", 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]", list_deleted: [ "Gelöscht: ", [ {"deleted == 0": "Nein"}, {"": "Ja"} ] ], refusing_to_extract_file: "Verweigere Entpacken von %[file]!", file_not_in_archive: "Datei %[file] ist nicht im Archiv!", print_no_file_specified: [ "Benötige eine oder mehrere Dateien zum Ausgeben!" ], add_no_file_specified: [ "Benötige eine oder mehrere Dateien zum Hinzufügen!" ], adding_file: "Füge %[file] hinzu...", adding_file_percent: "Füge %[file] hinzu... %[percent]%", adding_file_done: "Füge %[file] hinzu... fertig", } |