Skip to content
Open
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: 4 additions & 0 deletions src/types/outputFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,13 @@ export default class OutputFactory {
output = path.join(dir, output);
}

const gameNameContainsPathSeparators = /[\\/]/.test(game.getName());

if (
(options.getDirGameSubdir() === GameSubdirMode.MULTIPLE &&
game.getRoms().length > 1 &&
// Game name has directory structure 'built-in' (SMDB)
!gameNameContainsPathSeparators &&
// Output file is an archive
!FileFactory.isExtensionArchive(ext) &&
!(inputFile instanceof ArchiveFile)) ||
Expand Down
31 changes: 31 additions & 0 deletions test/outputFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1041,3 +1041,34 @@ describe('should respect "--dir-game-subdir"', () => {
expect(outputPath.format()).toEqual(path.join(os.devNull, 'game', 'Dummy.rom'));
});
});

describe('multi-rom games with path structure included in game name', () => {
const game = new SingleValueGame({
name: 'Top10/A-D/Cool Game',
roms: [
new ROM({ name: 'Top10/A-D/Cool Game.cue', size: 0, crc32: '' }),
new ROM({ name: 'Top10/A-D/Cool Game (Track 01).bin', size: 0, crc32: '' }),
],
});

it('should not duplicate directory structure for multi-ROM games', async () => {
const options = new Options({
commands: ['copy'],
output: os.devNull,
dirGameSubdir: GameSubdirModeInverted[GameSubdirMode.MULTIPLE].toLowerCase(),
});

const outputPaths = await Promise.all(
game
.getRoms()
.map(async (rom) =>
OutputFactory.getPath(options, dummyDat, game, rom, await rom.toFile()),
),
);

expect(outputPaths[0].format()).toEqual(path.join(os.devNull, 'Top10', 'A-D', 'Cool Game.cue'));
expect(outputPaths[1].format()).toEqual(
path.join(os.devNull, 'Top10', 'A-D', 'Cool Game (Track 01).bin'),
);
});
});
Loading