Skip to content

Commit

Permalink
feat: use the first custom executable from MO2 when launching the game
Browse files Browse the repository at this point in the history
  • Loading branch information
MattLish committed Feb 9, 2023
1 parent bf60256 commit ec563dc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/__tests__/unit/services/modOrganizer.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { GameService } from "@/main/services/game.service";
import { ProfileService } from "@/main/services/profile.service";
import { SystemService } from "@/main/services/system.service";
import { GraphicsService } from "@/main/services/graphics.service";
import mockFs from "mock-fs";

describe("ModOrganizer service", () => {
let mockEnbService: StubbedInstanceWithSinonAccessor<EnbService>;
Expand All @@ -39,6 +40,10 @@ describe("ModOrganizer service", () => {
mockGraphicsService = createStubInstance(GraphicsService);
});

afterEach(() => {
mockFs.restore();
});

it("should determine if Mod Organizer is running", async () => {
mockSystemService.stubs.isProcessRunning
.withArgs(MO2Names.MO2EXE)
Expand All @@ -57,4 +62,36 @@ describe("ModOrganizer service", () => {

expect(await modOrganizerService.isRunning()).to.eql(true);
});

it("should get the first binary", async () => {
const mockModDirectory = "mock/mod/directory";

mockFs({
[mockModDirectory]: {
[MO2Names.MO2Settings]: `
[customExecutables]
size=1
1\\binary=mock/first/custom/executable.exe
1\\title=SKSE
`,
},
});

mockConfigService.stubs.modDirectory.returns(mockModDirectory);

modOrganizerService = new ModOrganizerService(
mockEnbService,
mockErrorService,
mockConfigService,
mockResolutionService,
mockGameService,
mockProfileService,
mockSystemService,
mockGraphicsService
);

expect(await modOrganizerService.getFirstCustomExecutableTitle()).to.eql(
"SKSE"
);
});
});
10 changes: 8 additions & 2 deletions src/main/services/modOrganizer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { GameService } from "@/main/services/game.service";
import { ProfileService } from "@/main/services/profile.service";
import { SystemService } from "@/main/services/system.service";
import { GraphicsService } from "@/main/services/graphics.service";
import { ModOrganizerIni } from "@/ModOrganizer.ini";

export const enum MO2Names {
MO2EXE = "ModOrganizer.exe",
Expand Down Expand Up @@ -85,7 +86,12 @@ export class ModOrganizerService {
`${this.configService.modDirectory()}/${MO2Names.MO2Settings}`,
"utf-8"
)
);
) as ModOrganizerIni;
}

async getFirstCustomExecutableTitle() {
const settings = await this.readSettings();
return settings["customExecutables"]["1\\title"];
}

async updateSelectedProfile(profile: string) {
Expand Down Expand Up @@ -202,7 +208,7 @@ export class ModOrganizerService {
);
const profile = userPreferences.get(USER_PREFERENCE_KEYS.PRESET);

const mo2Command = `"${MO2Path}" -p "${profile}" "moshortcut://:SKSE"`;
const mo2Command = `"${MO2Path}" -p "${profile}" "moshortcut://:${await this.getFirstCustomExecutableTitle()}"`;
logger.debug(`Executing MO2 command: ${mo2Command}`);

const { stderr } = await promisify(childProcess.exec)(mo2Command);
Expand Down
10 changes: 10 additions & 0 deletions src/types/ModOrganizer.ini.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IIniObject } from "js-ini/lib/interfaces/ini-object";

export interface ModOrganizerIni extends IIniObject {
General: object;
customExecutables: {
size: number;
[key: string]: unknown;
};
Settings: object;
}

0 comments on commit ec563dc

Please sign in to comment.