Skip to content

Commit

Permalink
Refactor: prefer chdman and maxcso from $PATH (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Mar 3, 2025
1 parent 5a1784b commit d3be267
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/types/files/archives/chd/chd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Readable } from 'node:stream';
import util from 'node:util';

import { Mutex } from 'async-mutex';
import chdman, { CHDInfo, CHDType } from 'chdman';
import chdman, { CHDInfo, ChdmanBinaryPreference, CHDType } from 'chdman';
import { Memoize } from 'typescript-memoize';

import Temp from '../../../../globals/temp.js';
Expand Down Expand Up @@ -124,11 +124,13 @@ export default class Chd extends Archive {
await chdman.extractRaw({
inputFilename: this.getFilePath(),
outputFilename: this.tempSingletonFilePath,
binaryPreference: ChdmanBinaryPreference.PREFER_PATH_BINARY,
});
} else if (info.type === CHDType.HARD_DISK) {
await chdman.extractHd({
inputFilename: this.getFilePath(),
outputFilename: this.tempSingletonFilePath,
binaryPreference: ChdmanBinaryPreference.PREFER_PATH_BINARY,
});
} else if (info.type === CHDType.CD_ROM) {
const cueFile = `${this.tempSingletonFilePath}.cue`;
Expand All @@ -137,13 +139,15 @@ export default class Chd extends Archive {
inputFilename: this.getFilePath(),
outputFilename: cueFile,
outputBinFilename: this.tempSingletonFilePath,
binaryPreference: ChdmanBinaryPreference.PREFER_PATH_BINARY,
});
await FsPoly.rm(cueFile, { force: true });
} else if (info.type === CHDType.GD_ROM) {
this.tempSingletonFilePath = path.join(this.tempSingletonDirPath, 'track.gdi');
await chdman.extractCd({
inputFilename: this.getFilePath(),
outputFilename: this.tempSingletonFilePath,
binaryPreference: ChdmanBinaryPreference.PREFER_PATH_BINARY,
});
// Apply TOSEC-style CRLF line separators to the .gdi file
await util.promisify(fs.writeFile)(
Expand All @@ -156,6 +160,7 @@ export default class Chd extends Archive {
await chdman.extractDvd({
inputFilename: this.getFilePath(),
outputFilename: this.tempSingletonFilePath,
binaryPreference: ChdmanBinaryPreference.PREFER_PATH_BINARY,
});
} else {
throw new ExpectedError(`couldn't detect CHD type for: ${this.getFilePath()}`);
Expand Down Expand Up @@ -208,6 +213,9 @@ export default class Chd extends Archive {

@Memoize()
async getInfo(): Promise<CHDInfo> {
return chdman.info({ inputFilename: this.getFilePath() });
return chdman.info({
inputFilename: this.getFilePath(),
binaryPreference: ChdmanBinaryPreference.PREFER_PATH_BINARY,
});
}
}
8 changes: 6 additions & 2 deletions src/types/files/archives/maxcso/maxcso.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';

import maxcso from 'maxcso';
import maxcso, { MaxcsoBinaryPreference } from 'maxcso';

import { ChecksumBitmask } from '../../fileChecksums.js';
import Archive from '../archive.js';
Expand All @@ -12,7 +12,10 @@ export default abstract class Maxcso extends Archive {
const size = (await maxcso.header(this.getFilePath())).uncompressedSize;
let crc32: string | undefined;
if (checksumBitmask === ChecksumBitmask.NONE || checksumBitmask & ChecksumBitmask.CRC32) {
crc32 = await maxcso.uncompressedCrc32({ inputFilename: this.getFilePath() });
crc32 = await maxcso.uncompressedCrc32({
inputFilename: this.getFilePath(),
binaryPreference: MaxcsoBinaryPreference.PREFER_PATH_BINARY,
});
}

return [
Expand All @@ -32,6 +35,7 @@ export default abstract class Maxcso extends Archive {
return maxcso.decompress({
inputFilename: this.getFilePath(),
outputFilename: extractedFilePath,
binaryPreference: MaxcsoBinaryPreference.PREFER_PATH_BINARY,
});
}
}

0 comments on commit d3be267

Please sign in to comment.