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

Add subdirectory executable support to direct game runner #1270

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
30 changes: 27 additions & 3 deletions src/r2mm/launching/runners/multiplatform/DirectGameRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import GameDirectoryResolverProvider from '../../../../providers/ror2/game/GameD
import FsProvider from '../../../../providers/generic/file/FsProvider';
import LoggerProvider, { LogSeverity } from '../../../../providers/ror2/logging/LoggerProvider';
import { exec } from 'child_process';
import path from 'path'

export default class DirectGameRunner extends GameRunnerProvider {

Expand All @@ -32,16 +33,39 @@ export default class DirectGameRunner extends GameRunnerProvider {

async start(game: Game, args: string): Promise<void | R2Error> {
return new Promise(async (resolve, reject) => {
const fs = FsProvider.instance;
const settings = await ManagerSettings.getSingleton(game);
let gameDir = await GameDirectoryResolverProvider.instance.getDirectory(game);
if (gameDir instanceof R2Error) {
return resolve(gameDir);
}

gameDir = await FsProvider.instance.realpath(gameDir);
// Search through the registered game executable *relative* paths until a valid match has been found.
// Note that this doesn't do any validation to assert that the file is an actual executable, but that's ok.
let gameExecutable = undefined;
for (const exeItem of game.exeName) {
const absExePath = path.join(gameDir, exeItem);
if (!(await fs.exists(absExePath))) {
continue;
}

const stat = await fs.lstat(absExePath);
if (!stat.isFile()) {
continue;
}

const gameExecutable = (await FsProvider.instance.readdir(gameDir))
.filter((x: string) => game.exeName.includes(x))[0];
gameExecutable = absExePath;
break;
}

if (gameExecutable == undefined) {
const err = new R2Error(
"Error finding game executable",
"Failed to find a valid game executable within the game directory",
`Ensure that one of the following executables exists within ${gameDir}: ${game.exeName}`,
);
return reject(err);
}

LoggerProvider.instance.Log(LogSeverity.INFO, `Running command: ${gameDir}/${gameExecutable} ${args} ${settings.getContext().gameSpecific.launchParameters}`);

Expand Down