Skip to content

Commit ebeebc2

Browse files
committed
DUMPER-COMPANION: Also dump the dates from HFS
1 parent eef5afd commit ebeebc2

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

dumper-companion/src/hfs/directory.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class AbstractFolder {
4141
_namedict: {[key: string]: Uint8Array};
4242
_maindict: {[name: string]: FileOrFolder};
4343

44+
crdate: number;
45+
mddate: number;
46+
bkdate: number;
47+
4448
constructor() {
4549
this._namedict = {}; // key string to raw name
4650
this._maindict = {}; // key string to contents
@@ -86,28 +90,37 @@ export class AbstractFolder {
8690
return res;
8791
}
8892

89-
dumpToZip(zipDir: ZipDirectoryEntry, lang: Language, puny: boolean, forceMacBinary: boolean, log: (string) => void): void {
93+
dumpToZip(zipDir: ZipDirectoryEntry, lang: Language, puny: boolean, forceMacBinary: boolean, log: (string) => void): ZipDirectoryEntry {
9094
for (const [name, child] of this.items()) {
9195
const encodedName = encodeFileName(name, lang, puny, log);
9296
if (child instanceof AbstractFolder) {
93-
child.dumpToZip(zipDir.addDirectory(encodedName), lang, puny, forceMacBinary, log);
97+
child.dumpToZip(zipDir.addDirectory(encodedName, {
98+
lastModDate: hfs_ts_to_date(child.mddate),
99+
}), lang, puny, forceMacBinary, log);
94100
} else {
95-
zipDir.addUint8Array(encodedName, forceMacBinary ? child.toMacBinary(name) : child.toBinary(name));
101+
zipDir.addUint8Array(encodedName, forceMacBinary ? child.toMacBinary(name) : child.toBinary(name), {
102+
lastModDate: hfs_ts_to_date(child.mddate),
103+
});
96104
}
97105
}
106+
return zipDir;
98107
}
99108
}
100109

110+
function hfs_ts_to_date(hfs_ts) {
111+
const HFS_UTC_OFFSET = 2082844800;
112+
if (!hfs_ts) {
113+
return new Date();
114+
}
115+
return new Date((hfs_ts - HFS_UTC_OFFSET) * 1000);
116+
}
117+
101118

102119
export class MacFolder extends AbstractFolder {
103120
flags: number;
104121
x: number;
105122
y: number;
106123

107-
crdate: number;
108-
mddate: number;
109-
bkdate: number;
110-
111124
constructor() {
112125
super();
113126

dumper-companion/src/hfs/main.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ function _get_every_extent(nblocks: number, firstrecord: Uint8Array, cnid: numbe
5858

5959

6060
export class Volume extends AbstractFolder {
61-
crdate: number;
62-
mddate: number;
63-
bkdate: number;
6461
name: string;
6562

6663
constructor() {

0 commit comments

Comments
 (0)