feat: block executable 1:N game

This commit is contained in:
Zamitto 2024-09-14 15:29:52 -03:00
parent fcc24d6b94
commit 939133fcc3
8 changed files with 37 additions and 5 deletions

View File

@ -126,7 +126,9 @@
"stats": "Stats",
"download_count": "Downloads",
"player_count": "Active players",
"download_error": "This download option is not available"
"download_error": "This download option is not available",
"download": "Download",
"executable_path_in_use": "Executable already in use by \"{{game}}\""
},
"activation": {
"title": "Activate Hydra",

View File

@ -122,7 +122,9 @@
"stats": "Estatísticas",
"download_count": "Downloads",
"player_count": "Jogadores ativos",
"download_error": "Essa opção de download falhou"
"download_error": "Essa opção de download falhou",
"download": "Baixar",
"executable_path_in_use": "Executável em uso por \"{{game}}\""
},
"activation": {
"title": "Ativação",

View File

@ -111,7 +111,9 @@
"download_paused": "Transferência pausada",
"last_downloaded_option": "Última opção transferida",
"create_shortcut_success": "Atalho criado com sucesso",
"create_shortcut_error": "Erro ao criar atalho"
"create_shortcut_error": "Erro ao criar atalho",
"download": "Transferir",
"executable_path_in_use": "Executável em uso por \"{{game}}\""
},
"activation": {
"title": "Ativação",

View File

@ -22,6 +22,7 @@ import "./library/open-game-executable-path";
import "./library/open-game-installer";
import "./library/open-game-installer-path";
import "./library/update-executable-path";
import "./library/verify-executable-path";
import "./library/remove-game";
import "./library/remove-game-from-library";
import "./misc/open-external";

View File

@ -0,0 +1,13 @@
import { gameRepository } from "@main/repository";
import { registerEvent } from "../register-event";
const verifyExecutablePathInUse = async (
_event: Electron.IpcMainInvokeEvent,
executablePath: string
) => {
return gameRepository.findOne({
where: { executablePath },
});
};
registerEvent("verifyExecutablePathInUse", verifyExecutablePathInUse);

View File

@ -75,6 +75,8 @@ contextBridge.exposeInMainWorld("electron", {
ipcRenderer.invoke("createGameShortcut", id),
updateExecutablePath: (id: number, executablePath: string) =>
ipcRenderer.invoke("updateExecutablePath", id, executablePath),
verifyExecutablePathInUse: (executablePath: string) =>
ipcRenderer.invoke("verifyExecutablePathInUse", executablePath),
getLibrary: () => ipcRenderer.invoke("getLibrary"),
openGameInstaller: (gameId: number) =>
ipcRenderer.invoke("openGameInstaller", gameId),

View File

@ -71,6 +71,7 @@ declare global {
) => Promise<void>;
createGameShortcut: (id: number) => Promise<boolean>;
updateExecutablePath: (id: number, executablePath: string) => Promise<void>;
verifyExecutablePathInUse: (executablePath: string) => Promise<Game>;
getLibrary: () => Promise<LibraryGame[]>;
openGameInstaller: (gameId: number) => Promise<boolean>;
openGameInstallerPath: (gameId: number) => Promise<boolean>;

View File

@ -57,8 +57,17 @@ export function GameOptionsModal({
const path = await selectGameExecutable();
if (path) {
await window.electron.updateExecutablePath(game.id, path);
updateGame();
const gameUsingPath =
await window.electron.verifyExecutablePathInUse(path);
if (gameUsingPath) {
showErrorToast(
t("executable_path_in_use", { game: gameUsingPath.title })
);
return;
}
window.electron.updateExecutablePath(game.id, path).then(updateGame);
}
};