Skip to content

Commit

Permalink
Fix: info command not parsing metadata on Windows (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Jul 23, 2024
1 parent f3fd13d commit e767eed
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/chdman/chdmanInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
}
}

const metadata = [...output.matchAll(/metadata: +(.+)\n +(.+)/gi)]
const metadata = [...output.matchAll(/metadata: +(.+)\r?\n +(.+)/gi)]
.map((match, index_) => {
const tag = match[1].match(/tag='([\d a-z]+)'/i)?.at(1)?.trim() ?? '';
const index = Number.parseInt(
Expand All @@ -76,7 +76,7 @@ export default {
});

const metadataTags = new Set(metadata.map((m) => m.tag));
let type = CHDType.UNKNOWN;
let type = CHDType.RAW;
if (metadataTags.has('GDDD')) {
type = CHDType.HARD_DISK;
} else if (metadataTags.has('CHCD') || metadataTags.has('CHTR') || metadataTags.has('CHT2')) {
Expand Down
1 change: 0 additions & 1 deletion src/chdman/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ export enum CHDType {
GD_ROM,
DVD_ROM,
// LASER_DISC,
UNKNOWN,
}
2 changes: 1 addition & 1 deletion test/chdman/chdmanBin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ChdmanBin from '../../src/chdman/chdmanBin.js';

test('should print the help message', async () => {
it('should print the help message', async () => {
try {
await ChdmanBin.run(['help']);
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion test/chdman/chdmanCd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import fs from 'node:fs';
import ChdmanCd from '../../src/chdman/chdmanCd.js';
import ChdmanInfo from '../../src/chdman/chdmanInfo.js';
import TestUtil from '../testUtil.js';
import { CHDType } from '../../src/chdman/common.js';

test('should fail on nonexistent file', async () => {
it('should fail on nonexistent file', async () => {
const temporaryChd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.chd`;
const temporaryCue = `${temporaryChd}.cue`;
const temporaryBin = `${temporaryChd}.bin`;
Expand Down Expand Up @@ -60,6 +61,7 @@ test.each([
expect(info.ratio).toBeGreaterThan(0);
expect(info.sha1).toBeTruthy();
expect(info.dataSha1).toBeTruthy();
expect(info.type).toEqual(CHDType.CD_ROM);

await ChdmanCd.extractCd({
inputFilename: temporaryChd,
Expand Down
4 changes: 3 additions & 1 deletion test/chdman/chdmanDvd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import crypto from 'node:crypto';
import ChdmanInfo from '../../src/chdman/chdmanInfo.js';
import TestUtil from '../testUtil.js';
import ChdmanDvd from '../../src/chdman/chdmanDvd.js';
import { CHDType } from '../../src/chdman/common.js';

// https://unix.stackexchange.com/a/33634

test('should fail on nonexistent file', async () => {
it('should fail on nonexistent file', async () => {
const temporaryChd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.chd`;
const temporaryIso = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.iso`;

Expand Down Expand Up @@ -58,6 +59,7 @@ test.each([
expect(info.ratio).toBeGreaterThan(0);
expect(info.sha1).toBeTruthy();
expect(info.dataSha1).toBeTruthy();
expect(info.type).toEqual(CHDType.DVD_ROM);

await ChdmanDvd.extractDvd({
inputFilename: temporaryChd,
Expand Down
4 changes: 3 additions & 1 deletion test/chdman/chdmanHd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import fs from 'node:fs';
import ChdmanHd from '../../src/chdman/chdmanHd.js';
import ChdmanInfo from '../../src/chdman/chdmanInfo.js';
import TestUtil from '../testUtil.js';
import { CHDType } from '../../src/chdman/common.js';

// https://unix.stackexchange.com/a/33634

test('should fail on nonexistent file', async () => {
it('should fail on nonexistent file', async () => {
const temporaryChd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.chd`;
const temporaryHd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.hd`;

Expand Down Expand Up @@ -60,6 +61,7 @@ test.each([
expect(info.ratio).toBeGreaterThan(0);
expect(info.sha1).toBeTruthy();
expect(info.dataSha1).toBeTruthy();
expect(info.type).toEqual(CHDType.HARD_DISK);

await ChdmanHd.extractHd({
inputFilename: temporaryChd,
Expand Down
4 changes: 3 additions & 1 deletion test/chdman/chdmanRaw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import fs from 'node:fs';
import ChdmanInfo from '../../src/chdman/chdmanInfo.js';
import TestUtil from '../testUtil.js';
import ChdmanRaw from '../../src/chdman/chdmanRaw.js';
import { CHDType } from '../../src/chdman/common.js';

test('should fail on nonexistent file', async () => {
it('should fail on nonexistent file', async () => {
const temporaryChd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.chd`;
const temporaryRaw = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.hd`;

Expand Down Expand Up @@ -61,6 +62,7 @@ test.each([
expect(info.ratio).toBeGreaterThan(0);
expect(info.sha1).toBeTruthy();
expect(info.dataSha1).toBeTruthy();
expect(info.type).toEqual(CHDType.RAW);

await ChdmanRaw.extractRaw({
inputFilename: temporaryChd,
Expand Down

0 comments on commit e767eed

Please sign in to comment.