@@ -18,10 +18,11 @@ #include "config.h" #include #import "OFApplication.h" +#import "OFData.h" #import "OFDate.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFSet.h" @@ -39,13 +40,13 @@ static void setPermissions(OFString *path, OFZIPArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS - if (([entry versionMadeBy] >> 8) == + if ((entry.versionMadeBy >> 8) == OF_ZIP_ARCHIVE_ENTRY_ATTR_COMPAT_UNIX) { - uint16_t mode = [entry versionSpecificAttributes] >> 16; + uint16_t mode = entry.versionSpecificAttributes >> 16; of_file_attribute_key_t key = of_file_attribute_key_posix_permissions; of_file_attributes_t attributes = [OFDictionary dictionaryWithObject: [OFNumber numberWithUInt16: mode] forKey: key]; @@ -58,11 +59,11 @@ @implementation ZIPArchive + (void)initialize { if (self == [ZIPArchive class]) - app = (OFArc *)[[OFApplication sharedApplication] delegate]; + app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (of_string_encoding_t)encoding @@ -96,28 +97,28 @@ [super dealloc]; } - (void)listFiles { - for (OFZIPArchiveEntry *entry in [_archive entries]) { + for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); - [of_stdout writeLine: [entry fileName]]; + [of_stdout writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *compressedSize = [OFString stringWithFormat: @"%" PRIu64, - [entry compressedSize]]; + entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%" PRIu64, - [entry uncompressedSize]]; + entry.uncompressedSize]; OFString *compressionMethod = of_zip_archive_entry_compression_method_to_string( - [entry compressionMethod]); + entry.compressionMethod); OFString *CRC32 = [OFString - stringWithFormat: @"%08" PRIX32, [entry CRC32]]; - OFString *modificationDate = [[entry modificationDate] + 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", @@ -142,11 +143,11 @@ @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; if (app->_outputLevel >= 2) { - uint16_t versionMadeBy = [entry versionMadeBy]; + uint16_t versionMadeBy = entry.versionMadeBy; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_version_made_by", @"Version made by: %[version]", @@ -157,16 +158,16 @@ [of_stdout writeLine: OF_LOCALIZED( @"list_min_version_needed", @"Minimum version needed: %[version]", @"version", of_zip_archive_entry_version_to_string( - [entry minVersionNeeded]))]; + entry.minVersionNeeded))]; if ((versionMadeBy >> 8) == OF_ZIP_ARCHIVE_ENTRY_ATTR_COMPAT_UNIX) { - uint32_t mode = [entry - versionSpecificAttributes] >> 16; + uint32_t mode = entry + .versionSpecificAttributes >> 16; OFString *modeString = [OFString stringWithFormat: @"%06o", mode]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_mode", @@ -175,34 +176,34 @@ } } if (app->_outputLevel >= 3) { OFString *GPBF = [OFString stringWithFormat: - @"%04" PRIx16, - [entry generalPurposeBitFlag]]; + @"%04" PRIx16, entry.generalPurposeBitFlag]; [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_general_purpose_bit_flag", @"General purpose bit flag: %[gpbf]", @"gpbf", GPBF)]; - if ([entry extraField] != nil) { + if (entry.extraField != nil) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_extra_field", @"Extra field: %[extra]", - @"extra", [entry extraField])]; + @"extra", + entry.extraField.description)]; } } - if ([[entry fileComment] length] > 0) { + if (entry.fileComment.length > 0) { [of_stdout writeString: @"\t"]; [of_stdout writeLine: OF_LOCALIZED( @"list_comment", @"Comment: %[comment]", - @"comment", [entry fileComment])]; + @"comment", entry.fileComment)]; } } objc_autoreleasePoolPop(pool); } @@ -209,21 +210,21 @@ } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; - bool all = ([files count] == 0); + bool all = (files.count == 0); OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; - for (OFZIPArchiveEntry *entry in [_archive entries]) { + for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); - OFString *fileName = [entry fileName]; + OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFStream *stream; OFFile *output; - uint64_t written = 0, size = [entry uncompressedSize]; + uint64_t written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; @@ -259,11 +260,11 @@ } goto outer_loop_end; } - directory = [outFileName stringByDeletingLastPathComponent]; + directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName @@ -273,11 +274,11 @@ stream = [_archive streamForReadingFile: fileName]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); - while (![stream isAtEndOfStream]) { + while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; if (length < 0) { @@ -315,11 +316,11 @@ outer_loop_end: objc_autoreleasePoolPop(pool); } - if ([missing count] > 0) { + 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)]; @@ -330,11 +331,11 @@ - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files { OFStream *stream; - if ([files count] < 1) { + if (files.count < 1) { [of_stderr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } @@ -341,23 +342,23 @@ for (OFString *path in files) { @try { stream = [_archive streamForReadingFile: path]; } @catch (OFOpenItemFailedException *e) { - if ([e errNo] == ENOENT) { + if (e.errNo == ENOENT) { [of_stderr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", - @"file", [e path])]; + @"file", e.path)]; app->_exitStatus = 1; continue; } @throw e; } - while (![stream isAtEndOfStream]) { + while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: of_stdout fileName: path]; if (length < 0) { @@ -372,11 +373,11 @@ - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; - if ([files count] < 1) { + if (files.count < 1) { [of_stderr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } @@ -389,17 +390,17 @@ bool isDirectory = false; OFMutableZIPArchiveEntry *entry; uintmax_t size; OFStream *output; - components = [localFileName pathComponents]; + components = localFileName.pathComponents; fileName = [components componentsJoinedByString: @"/"]; attributes = [fileManager attributesOfItemAtPath: localFileName]; - if ([[attributes fileType] isEqual: of_file_type_directory]) { + if ([attributes.fileType isEqual: of_file_type_directory]) { isDirectory = true; fileName = [fileName stringByAppendingString: @"/"]; } if (app->_outputLevel >= 0) @@ -407,24 +408,20 @@ @"Adding %[file]...", @"file", fileName)]; entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName]; - if (isDirectory) - size = 0; - else - size = [attributes fileSize]; - + size = (isDirectory ? 0 : attributes.fileSize); if (size > INT64_MAX) @throw [OFOutOfRangeException exception]; - [entry setCompressedSize: (int64_t)size]; - [entry setUncompressedSize: (int64_t)size]; + entry.compressedSize = (int64_t)size; + entry.uncompressedSize = (int64_t)size; - [entry setCompressionMethod: - OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_NONE]; - [entry setModificationDate: [attributes fileModificationDate]]; + entry.compressionMethod = + OF_ZIP_ARCHIVE_ENTRY_COMPRESSION_METHOD_NONE; + entry.modificationDate = attributes.fileModificationDate; [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; @@ -433,11 +430,11 @@ int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; - while (![input isAtEndOfStream]) { + while (!input.atEndOfStream) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName];