@@ -252,33 +252,45 @@ extension = [stream readDataWithCount: size - 2]; if (!parseExtension(entry, extension, encoding, allowFileName)) [entry->_extensions addObject: extension]; - if (entry->_level == 1) { + if (entry->_headerLevel == 1) { if (entry->_compressedSize < size) @throw [OFInvalidFormatException exception]; entry->_compressedSize -= size; } } } @implementation OFLHAArchiveEntry -@synthesize compressionMethod = _compressionMethod; -@synthesize compressedSize = _compressedSize; -@synthesize uncompressedSize = _uncompressedSize, date = _date; -@synthesize level = _level, CRC16 = _CRC16; -@synthesize operatingSystemIdentifier = _operatingSystemIdentifier; -@synthesize fileComment = _fileComment, mode = _mode, UID = _UID, GID = _GID; -@synthesize owner = _owner, group = _group; -@synthesize modificationDate = _modificationDate, extensions = _extensions; ++ (instancetype)entryWithFileName: (OFString *)fileName +{ + return [[[self alloc] initWithFileName: fileName] autorelease]; +} - (instancetype)init { OF_INVALID_INIT_METHOD } + +- (instancetype)initWithFileName: (OFString *)fileName +{ + self = [super init]; + + @try { + _fileName = [fileName copy]; + _compressionMethod = @"-lh0-"; + _date = [[OFDate alloc] initWithTimeIntervalSince1970: 0]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} - (instancetype)of_initWithHeader: (char [21])header stream: (OFStream *)stream encoding: (of_string_encoding_t)encoding { @@ -299,14 +311,14 @@ _uncompressedSize = OF_BSWAP32_IF_BE(_uncompressedSize); memcpy(&date, header + 15, 4); date = OF_BSWAP32_IF_BE(date); - _level = header[20]; + _headerLevel = header[20]; _extensions = [[OFMutableArray alloc] init]; - switch (_level) { + switch (_headerLevel) { case 0: case 1:; void *pool = objc_autoreleasePoolPush(); uint8_t fileNameLength; OFString *tmp; @@ -320,11 +332,11 @@ withString: @"/"]; _fileName = [tmp copy]; _CRC16 = [stream readLittleEndianInt16]; - if (_level == 1) { + if (_headerLevel == 1) { _operatingSystemIdentifier = [stream readInt8]; readExtensions(self, stream, encoding, false); } @@ -340,11 +352,11 @@ readExtensions(self, stream, encoding, true); break; default:; OFString *version = [OFString - stringWithFormat: @"%u", _level]; + stringWithFormat: @"%u", _headerLevel]; @throw [OFUnsupportedVersionException exceptionWithVersion: version]; } @@ -376,18 +388,129 @@ - (id)copy { return [self retain]; } + +- (id)mutableCopy +{ + OFLHAArchiveEntry *copy = [[OFMutableLHAArchiveEntry alloc] + initWithFileName: _fileName]; + + @try { + [copy->_compressionMethod release]; + copy->_compressionMethod = nil; + + [copy->_date release]; + copy->_date = nil; + + copy->_directoryName = [_directoryName copy]; + copy->_compressionMethod = [_compressionMethod copy]; + copy->_compressedSize = _compressedSize; + copy->_uncompressedSize = _uncompressedSize; + copy->_date = [_date copy]; + copy->_headerLevel = _headerLevel; + copy->_CRC16 = _CRC16; + copy->_operatingSystemIdentifier = _operatingSystemIdentifier; + copy->_fileComment = [_fileComment copy]; + copy->_mode = [_mode retain]; + copy->_UID = [_UID retain]; + copy->_GID = [_GID retain]; + copy->_owner = [_owner copy]; + copy->_group = [_group copy]; + copy->_modificationDate = [_modificationDate retain]; + copy->_extensions = [_extensions copy]; + } @catch (id e) { + [copy release]; + @throw e; + } + + return copy; +} - (OFString *)fileName { if (_directoryName == nil) return _fileName; return [_directoryName stringByAppendingString: _fileName]; } + +- (OFString *)compressionMethod +{ + return _compressionMethod; +} + +- (uint32_t)compressedSize +{ + return _compressedSize; +} + +- (uint32_t)uncompressedSize +{ + return _uncompressedSize; +} + +- (OFDate *)date +{ + return _date; +} + +- (uint8_t)headerLevel +{ + return _headerLevel; +} + +- (uint16_t)CRC16 +{ + return _CRC16; +} + +- (uint8_t)operatingSystemIdentifier +{ + return _operatingSystemIdentifier; +} + +- (OFString *)fileComment +{ + return _fileComment; +} + +- (OFNumber *)mode +{ + return _mode; +} + +- (OFNumber *)UID +{ + return _UID; +} + +- (OFNumber *)GID +{ + return _GID; +} + +- (OFString *)owner +{ + return _owner; +} + +- (OFString *)group +{ + return _group; +} + +- (OFDate *)modificationDate +{ + return _modificationDate; +} + +- (OFArray OF_GENERIC(OFData *) *)extensions +{ + return _extensions; +} - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *mode = (_mode == nil @@ -401,11 +524,11 @@ @"\tFile name = %@\n" @"\tCompression method = %@\n" @"\tCompressed size = %" @PRIu32 "\n" @"\tUncompressed size = %" @PRIu32 "\n" @"\tDate = %@\n" - @"\tLevel = %u\n" + @"\tHeader level = %u\n" @"\tCRC16 = %04" @PRIX16 @"\n" @"\tOperating system identifier = %c\n" @"\tComment = %@\n" @"\tMode = %@\n" @"\tUID = %@\n" @@ -414,11 +537,11 @@ @"\tGroup = %@\n" @"\tModification date = %@\n" @"\tExtensions: %@" @">", [self class], [self fileName], _compressionMethod, _compressedSize, - _uncompressedSize, _date, _level, _CRC16, + _uncompressedSize, _date, _headerLevel, _CRC16, _operatingSystemIdentifier, _fileComment, mode, _UID, _GID, _owner, _group, _modificationDate, extensions]; [ret retain];