From 29b30bebd19002cde1b224b81ebd1f90b4948c15 Mon Sep 17 00:00:00 2001 From: prostarz Date: Tue, 7 Jan 2025 21:14:22 +0000 Subject: [PATCH] feat(launcher): read shortcut links on windows --- backend/handlers/launcher/gameProcessLauncher.ts | 4 ++-- backend/handlers/launcher/utils.ts | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/handlers/launcher/gameProcessLauncher.ts b/backend/handlers/launcher/gameProcessLauncher.ts index 1b65dfa..091d48d 100644 --- a/backend/handlers/launcher/gameProcessLauncher.ts +++ b/backend/handlers/launcher/gameProcessLauncher.ts @@ -6,7 +6,7 @@ import windoww from "../../utils/window"; import { AchievementItem } from "../achievements/item"; import { logger } from "../logging"; import { gamesLaunched } from "./games_launched"; -import { spawnSync } from "./utils"; +import { getRealPath, spawnSync } from "./utils"; interface Options { game_path: string; @@ -50,7 +50,7 @@ class GameProcessLauncher { throw new Error(`Invalid game path: ${game_path}`); } - this.gamePath = game_path; + this.gamePath = getRealPath(game_path); this.gameId = game_id; this.gameArgs = game_args; this.gameCommand = game_command; diff --git a/backend/handlers/launcher/utils.ts b/backend/handlers/launcher/utils.ts index 4781296..038c5f8 100644 --- a/backend/handlers/launcher/utils.ts +++ b/backend/handlers/launcher/utils.ts @@ -1,12 +1,13 @@ import child_process from "child_process"; +import { shell } from "electron"; import path from "path"; -export function spawnSync( +export const spawnSync = ( command: string, programPath: string, args: string[], options: child_process.SpawnOptions -) { +) => { let cmd = programPath; if (typeof options.cwd === "string") { @@ -19,4 +20,13 @@ export function spawnSync( // @ts-expect-error env: { ...process.env, WINEDEBUG: "fixme-all" }, }); -} +}; + +export const getRealPath = (path: string) => { + try { + if (process.platform !== "win32" && !path.endsWith(".lnk")) return path; + return shell.readShortcutLink(path).target; + } catch (error) { + return path; + } +};