ObjFW  Check-in [52a1740f5e]

Overview
Comment:OFZooArchiveEntry: Add header type and OS ID
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 52a1740f5e009256ef03b05f3399bbbf0f755cd065c70bde3e743a4812037671
User & Date: js on 2024-03-02 17:13:10
Other Links: manifest | tags
Context
2024-03-02
17:58
Fix documentation for mutable classes check-in: 18045dffca user: js tags: trunk
17:13
OFZooArchiveEntry: Add header type and OS ID check-in: 52a1740f5e user: js tags: trunk
15:06
Fix linker warning on macOS/iOS check-in: ee858ea1fd user: js tags: trunk
Changes

Modified src/OFZooArchive.m from [648d8f6c0c] to [1d909708d8].

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
184
185
186
187
188
189
190









191
192
193
194
195
196
197







-
-
-
-
-
-
-
-
-







	}
	_lastReturnedStream = nil;

	_currentEntry = [[OFZooArchiveEntry alloc]
	    of_initWithStream: _stream
		     encoding: _encoding];

	if (_currentEntry->_nextHeaderOffset == 0) {
		/*
		 * End of archive is marked by a header that has the next
		 * header's offset set to 0.
		 */
		[_currentEntry release];
		_currentEntry = nil;
	}

	return _currentEntry;
}

- (OFStream *)streamForReadingCurrentEntry
{
	if (_mode != modeRead)
		@throw [OFInvalidArgumentException exception];

Modified src/OFZooArchiveEntry+Private.h from [fe9f3783e3] to [b4293f9798].

14
15
16
17
18
19
20
21
22


23
24
25
26
14
15
16
17
18
19
20


21
22
23
24
25
26







-
-
+
+




 */

#import "OFZooArchive.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFZooArchiveEntry ()
- (instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
			 encoding: (OFStringEncoding)encoding
- (nullable instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
				  encoding: (OFStringEncoding)encoding
    OF_METHOD_FAMILY(init) OF_DIRECT;
@end

OF_ASSUME_NONNULL_END

Modified src/OFZooArchiveEntry.h from [424d820999] to [884a79e4f1].

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
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







-
+














+



+
+
+
+
+







/**
 * @class OFZooArchiveEntry OFZooArchiveEntry.h ObjFW/OFZooArchiveEntry.h
 *
 * @brief A class which represents an entry in an Zoo archive.
 */
@interface OFZooArchiveEntry: OFObject <OFArchiveEntry, OFCopying>
{
	uint8_t _compressionMethod;
	uint8_t _headerType, _compressionMethod;
#ifdef OF_ZOO_ARCHIVE_M
@public
#endif
	unsigned long long _nextHeaderOffset, _dataOffset;
@protected
	uint16_t _lastModifiedFileDate, _lastModifiedFileTime;
	uint16_t _CRC16;
	unsigned long long _uncompressedSize, _compressedSize;
	uint16_t _minVersionNeeded;
	bool _deleted;
	OFString *_Nullable _fileComment;
	OFString *_fileName, *_Nullable _directoryName;
	OFNumber *_Nullable _POSIXPermissions;
	int8_t _timeZone;
	uint16_t _operatingSystemIdentifier;
	OF_RESERVE_IVARS(OFZooArchiveEntry, 4)
}

/**
 * @brief The header type of the entry.
 */
@property (readonly, nonatomic) uint8_t headerType;

/**
 * @brief The compression method of the entry.
 */
@property (readonly, nonatomic) uint8_t compressionMethod;

/**
 * @brief The CRC16 of the file.
66
67
68
69
70
71
72





73
74
75
76
77
78
79
80
81
82
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93







+
+
+
+
+










@property (readonly, nonatomic) uint16_t minVersionNeeded;

/**
 * @brief Whether the file was deleted.
 */
@property (readonly, nonatomic, getter=isDeleted) bool deleted;

/**
 * @brief The operating system identifier of the file.
 */
@property (readonly, nonatomic) uint16_t operatingSystemIdentifier;

/**
 * @brief The time zone in which the file was stored, as an offset in hours
 *	  from UTC (as a float).
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFNumber *timeZone;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/OFZooArchiveEntry.m from [f5e97efd24] to [68f5329f4b].

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
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







+


-
-
+
+


-
+
+
+




















-
-
-
+
+
+
+



+
+
+
+
+
+








-
+
+
+
+








-
+







#import "OFDate.h"
#import "OFNumber.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#import "OFString.h"

#import "OFInvalidFormatException.h"
#import "OFUnsupportedVersionException.h"

@implementation OFZooArchiveEntry
@synthesize compressionMethod = _compressionMethod, CRC16 = _CRC16;
@synthesize uncompressedSize = _uncompressedSize;
@synthesize headerType = _headerType, compressionMethod = _compressionMethod;
@synthesize CRC16 = _CRC16, uncompressedSize = _uncompressedSize;
@synthesize compressedSize = _compressedSize;
@synthesize minVersionNeeded = _minVersionNeeded, deleted = _deleted;
@synthesize fileComment = _fileComment, POSIXPermissions = _POSIXPermissions;
@synthesize fileComment = _fileComment;
@synthesize operatingSystemIdentifier = _operatingSystemIdentifier;
@synthesize POSIXPermissions = _POSIXPermissions;

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
			 encoding: (OFStringEncoding)encoding
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		char fileNameBuffer[13];
		uint32_t commentOffset;
		uint16_t commentLength;

		if ([stream readLittleEndianInt32] != 0xFDC4A7DC)
			@throw [OFInvalidFormatException exception];

		/* Type seems to be always 2 */
		if ([stream readInt8] != 2)
			@throw [OFInvalidFormatException exception];
		if ((_headerType = [stream readInt8]) > 2)
			@throw [OFUnsupportedVersionException
			    exceptionWithVersion: [OFString
			    stringWithFormat: @"%u", _headerType]];

		_compressionMethod = [stream readInt8];
		_nextHeaderOffset = [stream readLittleEndianInt32];

		if (_nextHeaderOffset == 0) {
			[self release];
			return nil;
		}

		_dataOffset = [stream readLittleEndianInt32];
		_lastModifiedFileDate = [stream readLittleEndianInt16];
		_lastModifiedFileTime = [stream readLittleEndianInt16];
		_CRC16 = [stream readLittleEndianInt16];
		_uncompressedSize = [stream readLittleEndianInt32];
		_compressedSize = [stream readLittleEndianInt32];
		_minVersionNeeded = [stream readBigEndianInt16];
		_deleted = [stream readInt8];
		/* Unknown. Most likely padding to get to 2 byte alignment? */
		/*
		 * File structure, whatever that is meant to be. Seems to
		 * always be 0.
		 */
		[stream readInt8];
		commentOffset = [stream readLittleEndianInt32];
		commentLength = [stream readLittleEndianInt16];

		[stream readIntoBuffer: fileNameBuffer exactLength: 13];
		if (fileNameBuffer[12] != '\0')
			fileNameBuffer[12] = '\0';

		if ((_minVersionNeeded >> 8) == 2) {
		if (_headerType >= 2) {
			uint16_t extraLength = [stream readLittleEndianInt16];
			uint8_t fileNameLength, directoryNameLength;

			if (extraLength < 10)
				@throw [OFInvalidFormatException exception];

			_timeZone = [stream readInt8];
111
112
113
114
115
116
117
118
119


120
121
122
123
124
125
126
124
125
126
127
128
129
130


131
132
133
134
135
136
137
138
139







-
-
+
+







				_directoryName = [[stream
				    readStringWithLength: directoryNameLength
						encoding: encoding] copy];
				extraLength -= directoryNameLength;
			}

			if (extraLength >= 2) {
				/* System ID */
				[stream readLittleEndianInt16];
				_operatingSystemIdentifier =
				    [stream readLittleEndianInt16];
				extraLength -= 2;
			}

			if (extraLength >= 3) {
				uint8_t attributes[3];

				[stream readIntoBuffer: attributes

Modified utils/ofarc/LHAArchive.m from [f7ef0447c1] to [86289cab8e].

236
237
238
239
240
241
242
243

244
245
246
247
248
249
250
236
237
238
239
240
241
242

243
244
245
246
247
248
249
250







-
+







					    [OFString stringWithFormat: @"%c",
					    entry.operatingSystemIdentifier];

					[OFStdOut writeString: @"\t"];
					[OFStdOut writeLine: OF_LOCALIZED(
					    @"list_osid",
					    @"Operating system identifier: "
					    "%[osid]",
					    @"%[osid]",
					    @"osid", OSID)];
				}
			}

			if (app->_outputLevel >= 3) {
				OFString *extensions =
				    indent(entry.extensions.description);

Modified utils/ofarc/ZooArchive.m from [8b10ea5944] to [5bee585379].

133
134
135
136
137
138
139
140


141
142
143
144

145
146
147
148
149
150
151
133
134
135
136
137
138
139

140
141
142
143
144

145
146
147
148
149
150
151
152







-
+
+



-
+







			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];
			    stringWithFormat: @"%" PRIu8,
			    entry.compressionMethod];
			OFString *CRC16 = [OFString stringWithFormat:
			    @"%04" PRIX16, entry.CRC16];
			OFString *deleted = [OFString stringWithFormat:
			    @"%u", entry.deleted];
			    @"%" PRIu8, entry.deleted];

			[OFStdOut writeString: @"\t"];
			[OFStdOut writeLine: OF_LOCALIZED(
			    @"list_compressed_size",
			    @"["
			    @"    'Compressed: ',"
			    @"    ["
222
223
224
225
226
227
228
229

230
231



232
233
234
235
236
237



















238
239
240
241
242
243
244
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







-
+


+
+
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				    @"comment", entry.fileComment)];
			}
		}

		if (app->_outputLevel >= 2) {
			uint16_t minVersionNeeded = entry.minVersionNeeded;
			OFString *minVersionNeededString = [OFString
			    stringWithFormat: @"%u.%u",
			    stringWithFormat: @"%" PRIu8 @".%" PRIu8,
					      minVersionNeeded >> 8,
					      minVersionNeeded & 0xFF];
			OFString *headerType = [OFString
			    stringWithFormat: @"%" PRIu8,
					      entry.headerType];

			[OFStdOut writeString: @"\t"];
			[OFStdOut writeLine: OF_LOCALIZED(
			    @"list_min_version_needed",
			    @"Minimum version needed: %[version]",
			    @"version", minVersionNeededString)];

			[OFStdOut writeString: @"\t"];
			[OFStdOut writeLine: OF_LOCALIZED(
			    @"list_header_type",
			    @"Header type: %[type]",
			    @"type", headerType)];

			if (entry.headerType >= 2) {
				OFString *OSID =
				    [OFString stringWithFormat: @"%u",
				    entry.operatingSystemIdentifier];

				[OFStdOut writeString: @"\t"];
				[OFStdOut writeLine: OF_LOCALIZED(
				    @"list_osid",
				    @"Operating system identifier: "
				    @"%[osid]",
				    @"osid", OSID)];
			}

			if (entry.POSIXPermissions != nil) {
				OFString *permissionsString = [OFString
				    stringWithFormat: @"%llo",
				    entry.POSIXPermissions
				    .unsignedLongLongValue];

Modified utils/ofarc/localization/de.json from [b069c5c54a] to [0366ea8180].

89
90
91
92
93
94
95

96
97
98
99
100
101
102
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103







+







    ],
    list_posix_permissions: "POSIX-Berechtigungen: %[perm]",
    list_owner_account_id: "Besitzerkontennummer: %[id]",
    list_group_owner_account_id: "Gruppenbesitzerkontennummer: %[id]",
    list_owner_account_name: "Besitzerkontenname: %[name]",
    list_group_owner_account_name: "Gruppenbesitzerkontenname: %[name]",
    list_header_level: "Header-Level: %[level]",
    list_header_type: "Header-Typ: %[type]",
    list_modification_date: "Änderungsdatum: %[date]",
    list_type_normal: "Typ: Normale Datei",
    list_type_hardlink: "Typ: Harter Link",
    list_type_symlink: "Typ: Symbolischer Link",
    list_link_target: "Zieldateiname: %[target]",
    list_type_character_device: "Typ: Zeichenorientiertes Gerät",
    list_type_block_device: "Typ: Blockorientiertes Gerät",