From 61645973aac95bded3b7aff5ddc82f10d9137029 Mon Sep 17 00:00:00 2001 From: Christian Emmer <10749361+emmercm@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:17:07 -0700 Subject: [PATCH 1/2] Fix: minimum for number of games with path characters --- src/modules/argumentsParser.ts | 4 +++- src/types/dats/dat.ts | 8 +++++++- src/types/dats/logiqx/header.ts | 7 ++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/modules/argumentsParser.ts b/src/modules/argumentsParser.ts index ee4880114..07bad83c3 100644 --- a/src/modules/argumentsParser.ts +++ b/src/modules/argumentsParser.ts @@ -396,10 +396,12 @@ export default class ArgumentsParser { } const needOutput = ['copy', 'move', 'extract', 'zip', 'clean'].filter((command) => checkArgv._.includes(command)); if (!checkArgv.output && needOutput.length > 0) { - throw new Error(`Missing required option for command${needOutput.length !== 1 ? 's' : ''} ${needOutput.join(', ')}: --output`); + // TODO(cememr): print help message + throw new Error(`Missing required option for command${needOutput.length !== 1 ? 's' : ''} ${needOutput.join(', ')}: --output `); } const needClean = ['clean-exclude', 'clean-dry-run'].filter((option) => checkArgv[option]); if (!checkArgv._.includes('clean') && needClean.length > 0) { + // TODO(cememr): print help message throw new Error(`Missing required command for option${needClean.length !== 1 ? 's' : ''} ${needClean.join(', ')}: clean`); } return true; diff --git a/src/types/dats/dat.ts b/src/types/dats/dat.ts index 60ecba9d3..28b519ca7 100644 --- a/src/types/dats/dat.ts +++ b/src/types/dats/dat.ts @@ -1,3 +1,4 @@ +import { Memoize } from 'typescript-memoize'; import xml2js from 'xml2js'; import FsPoly from '../../polyfill/fsPoly.js'; @@ -62,6 +63,7 @@ export default abstract class DAT { return this.getHeader().getName(); } + @Memoize() getNameShort(): string { return this.getName() // Prefixes @@ -86,9 +88,13 @@ export default abstract class DAT { return this.getHeader().getDescription(); } + @Memoize() getRomNamesContainDirectories(): boolean { return this.getHeader().getRomNamesContainDirectories() - || this.isBiosDat(); + // Assume BIOS DATs know what they're doing with path characters + || this.isBiosDat() + // At least 50% of games have at least one ROM with path characters + || this.getGames().filter((game) => game.getRoms().some((rom) => rom.getName().match(/[\\/]/) !== null)).length > this.getGames().length / 2; } /** diff --git a/src/types/dats/logiqx/header.ts b/src/types/dats/logiqx/header.ts index c22c44d29..481d0fa30 100644 --- a/src/types/dats/logiqx/header.ts +++ b/src/types/dats/logiqx/header.ts @@ -78,7 +78,7 @@ export default class Header implements HeaderOptions { @Transform(({ value }) => value || undefined) readonly clrMamePro?: ClrMamePro; - readonly romNamesContainDirectories: boolean = true; + readonly romNamesContainDirectories: boolean; constructor(options?: HeaderOptions) { this.name = options?.name ?? ''; @@ -89,10 +89,7 @@ export default class Header implements HeaderOptions { this.url = options?.url; this.comment = options?.comment; this.clrMamePro = options?.clrMamePro; - - this.romNamesContainDirectories = options?.romNamesContainDirectories !== undefined - ? options?.romNamesContainDirectories - : false; + this.romNamesContainDirectories = options?.romNamesContainDirectories ?? false; } /** From 5abc6637bb996579d1b2c64121bad59cb6a944a1 Mon Sep 17 00:00:00 2001 From: Christian Emmer <10749361+emmercm@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:31:37 -0700 Subject: [PATCH 2/2] Fix --- src/types/dats/dat.ts | 7 ++++--- src/types/dats/logiqx/header.ts | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/types/dats/dat.ts b/src/types/dats/dat.ts index 28b519ca7..cba16c2d4 100644 --- a/src/types/dats/dat.ts +++ b/src/types/dats/dat.ts @@ -90,11 +90,12 @@ export default abstract class DAT { @Memoize() getRomNamesContainDirectories(): boolean { - return this.getHeader().getRomNamesContainDirectories() + return this.getHeader().getRomNamesContainDirectories() ?? ( // Assume BIOS DATs know what they're doing with path characters - || this.isBiosDat() + this.isBiosDat() // At least 50% of games have at least one ROM with path characters - || this.getGames().filter((game) => game.getRoms().some((rom) => rom.getName().match(/[\\/]/) !== null)).length > this.getGames().length / 2; + || this.getGames().filter((game) => game.getRoms().some((rom) => rom.getName().match(/[\\/]/) !== null)).length > this.getGames().length / 2 + ); } /** diff --git a/src/types/dats/logiqx/header.ts b/src/types/dats/logiqx/header.ts index 481d0fa30..1a7d8bf7c 100644 --- a/src/types/dats/logiqx/header.ts +++ b/src/types/dats/logiqx/header.ts @@ -78,7 +78,7 @@ export default class Header implements HeaderOptions { @Transform(({ value }) => value || undefined) readonly clrMamePro?: ClrMamePro; - readonly romNamesContainDirectories: boolean; + readonly romNamesContainDirectories?: boolean; constructor(options?: HeaderOptions) { this.name = options?.name ?? ''; @@ -89,7 +89,7 @@ export default class Header implements HeaderOptions { this.url = options?.url; this.comment = options?.comment; this.clrMamePro = options?.clrMamePro; - this.romNamesContainDirectories = options?.romNamesContainDirectories ?? false; + this.romNamesContainDirectories = options?.romNamesContainDirectories; } /** @@ -129,7 +129,7 @@ export default class Header implements HeaderOptions { return this.clrMamePro; } - getRomNamesContainDirectories(): boolean { + getRomNamesContainDirectories(): boolean | undefined { return this.romNamesContainDirectories; }