Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: don't CRC32 checksum files by default #1229

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/igir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class Igir {
if (dir2DatPath) {
datsToWrittenFiles.set(filteredDat, [
...(datsToWrittenFiles.get(filteredDat) ?? []),
await File.fileOf({ filePath: dir2DatPath }, ChecksumBitmask.NONE),
await File.fileOf({ filePath: dir2DatPath }),
]);
}

Expand All @@ -172,7 +172,7 @@ export default class Igir {
if (fixdatPath) {
datsToWrittenFiles.set(filteredDat, [
...(datsToWrittenFiles.get(filteredDat) ?? []),
await File.fileOf({ filePath: fixdatPath }, ChecksumBitmask.NONE),
await File.fileOf({ filePath: fixdatPath }),
]);
}

Expand Down
5 changes: 2 additions & 3 deletions src/modules/candidatePatchGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Release from '../types/dats/release.js';
import ROM from '../types/dats/rom.js';
import ArchiveEntry from '../types/files/archives/archiveEntry.js';
import File from '../types/files/file.js';
import { ChecksumBitmask } from '../types/files/fileChecksums.js';
import Patch from '../types/patches/patch.js';
import ReleaseCandidate from '../types/releaseCandidate.js';
import ROMWithFiles from '../types/romWithFiles.js';
Expand Down Expand Up @@ -148,7 +147,7 @@ export default class CandidatePatchGenerator extends Module {
crc32: patch.getCrcAfter(),
fileHeader: outputFile.getFileHeader(),
patch: outputFile.getPatch(),
}, ChecksumBitmask.NONE); // don't calculate anything, the file doesn't exist
});
} else {
const dirName = path.dirname(outputFile.getFilePath());
outputFile = await File.fileOf({
Expand All @@ -157,7 +156,7 @@ export default class CandidatePatchGenerator extends Module {
crc32: patch.getCrcAfter(),
fileHeader: outputFile.getFileHeader(),
patch: outputFile.getPatch(),
}, ChecksumBitmask.NONE); // don't calculate anything, the file doesn't exist
});
}

// Build a new ROM from the output file's info
Expand Down
6 changes: 4 additions & 2 deletions src/types/files/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class File implements FileProps {

static async fileOf(
fileProps: FileProps,
checksumBitmask: number = ChecksumBitmask.CRC32,
checksumBitmask: number = ChecksumBitmask.NONE,
): Promise<File> {
let finalSize = fileProps.size;
let finalCrcWithHeader = fileProps.crc32;
Expand Down Expand Up @@ -152,7 +152,9 @@ export default class File implements FileProps {
return new File({
filePath: fileProps.filePath,
size: finalSize,
checksumBitmask,
// We were told not to calculate any checksums (default behavior), but some might have been
// provided, so let {@link getChecksumBitmask()} figure it out
checksumBitmask: checksumBitmask !== ChecksumBitmask.NONE ? checksumBitmask : undefined,
crc32: finalCrcWithHeader,
crc32WithoutHeader: finalCrcWithoutHeader,
md5: finalMd5WithHeader,
Expand Down
21 changes: 17 additions & 4 deletions test/modules/candidateWriter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import LogiqxDAT from '../../src/types/dats/logiqx/logiqxDat.js';
import Archive from '../../src/types/files/archives/archive.js';
import ArchiveEntry from '../../src/types/files/archives/archiveEntry.js';
import File from '../../src/types/files/file.js';
import { ChecksumBitmask } from '../../src/types/files/fileChecksums.js';
import FileFactory from '../../src/types/files/fileFactory.js';
import Options, { GameSubdirMode, OptionsProps } from '../../src/types/options.js';
import ProgressBarFake from '../console/progressBarFake.js';
Expand Down Expand Up @@ -782,7 +783,10 @@ describe('extract', () => {
);
expect(outputFiles).toHaveLength(1);
expect(outputFiles[0][0]).toEqual(expectedFileName);
const outputFile = await File.fileOf({ filePath: path.join(outputTemp, outputFiles[0][0]) });
const outputFile = await File.fileOf(
{ filePath: path.join(outputTemp, outputFiles[0][0]) },
ChecksumBitmask.CRC32,
);
expect(outputFile.getCrc32()).toEqual(expectedCrc);
});
});
Expand Down Expand Up @@ -815,7 +819,10 @@ describe('extract', () => {
);
expect(outputFiles).toHaveLength(1);
expect(outputFiles[0][0]).toEqual(expectedFileName);
const outputFile = await File.fileOf({ filePath: path.join(outputTemp, outputFiles[0][0]) });
const outputFile = await File.fileOf(
{ filePath: path.join(outputTemp, outputFiles[0][0]) },
ChecksumBitmask.CRC32,
);
expect(outputFile.getCrc32()).toEqual(expectedCrc);
});
});
Expand Down Expand Up @@ -1142,7 +1149,10 @@ describe('raw', () => {
);
expect(outputFiles).toHaveLength(1);
expect(outputFiles[0][0]).toEqual(expectedFileName);
const outputFile = await File.fileOf({ filePath: path.join(outputTemp, outputFiles[0][0]) });
const outputFile = await File.fileOf(
{ filePath: path.join(outputTemp, outputFiles[0][0]) },
ChecksumBitmask.CRC32,
);
expect(outputFile.getCrc32()).toEqual(expectedCrc);
});
});
Expand Down Expand Up @@ -1171,7 +1181,10 @@ describe('raw', () => {
);
expect(outputFiles).toHaveLength(1);
expect(outputFiles[0][0]).toEqual(expectedFileName);
const outputFile = await File.fileOf({ filePath: path.join(outputTemp, outputFiles[0][0]) });
const outputFile = await File.fileOf(
{ filePath: path.join(outputTemp, outputFiles[0][0]) },
ChecksumBitmask.CRC32,
);
expect(outputFile.getCrc32()).toEqual(expectedCrc);
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/types/files/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('getCrc32', () => {
['./test/fixtures/roms/raw/foobar.lnx', 'b22c9747'],
['./test/fixtures/roms/raw/loremipsum.rom', '70856527'],
])('should hash the full file: %s', async (filePath, expectedCrc) => {
const file = await File.fileOf({ filePath });
const file = await File.fileOf({ filePath }, ChecksumBitmask.CRC32);
expect(file.getCrc32()).toEqual(expectedCrc);
expect(file.getCrc32WithoutHeader()).toEqual(expectedCrc);
expect(file.getMd5()).toBeUndefined();
Expand All @@ -152,7 +152,7 @@ describe('getCrc32WithoutHeader', () => {
['./test/fixtures/roms/headered/allpads.nes', '9180a163'],
['./test/fixtures/roms/headered/speed_test_v51.smc', '9adca6cc'],
])('should hash the full file when no header given: %s', async (filePath, expectedCrc) => {
const file = await File.fileOf({ filePath });
const file = await File.fileOf({ filePath }, ChecksumBitmask.CRC32);
expect(file.getCrc32()).toEqual(expectedCrc);
expect(file.getCrc32WithoutHeader()).toEqual(expectedCrc);
expect(file.getMd5()).toBeUndefined();
Expand All @@ -167,7 +167,7 @@ describe('getCrc32WithoutHeader', () => {
['./test/fixtures/roms/raw/fizzbuzz.nes', '370517b5'],
['./test/fixtures/roms/raw/foobar.lnx', 'b22c9747'],
])('should hash the full file when header is given but not present in file: %s', async (filePath, expectedCrc) => {
const file = await (await File.fileOf({ filePath }))
const file = await (await File.fileOf({ filePath }, ChecksumBitmask.CRC32))
.withFileHeader(ROMHeader.headerFromFilename(filePath) as ROMHeader);
expect(file.getCrc32()).toEqual(expectedCrc);
expect(file.getCrc32WithoutHeader()).toEqual(expectedCrc);
Expand All @@ -183,7 +183,7 @@ describe('getCrc32WithoutHeader', () => {
['./test/fixtures/roms/headered/allpads.nes', '6339abe6'],
['./test/fixtures/roms/headered/speed_test_v51.smc', '8beffd94'],
])('should hash the file without the header when header is given and present in file: %s', async (filePath, expectedCrc) => {
const file = await (await File.fileOf({ filePath }))
const file = await (await File.fileOf({ filePath }, ChecksumBitmask.CRC32))
.withFileHeader(ROMHeader.headerFromFilename(filePath) as ROMHeader);
expect(file.getCrc32()).not.toEqual(file.getCrc32WithoutHeader());
expect(file.getCrc32WithoutHeader()).toEqual(expectedCrc);
Expand Down
Loading