This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow selecting different game directories
- Loading branch information
1 parent
8dde439
commit b7483d5
Showing
8 changed files
with
118 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,89 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
import pathLib from "path" | ||
import fs from "fs-extra" | ||
import Store from "electron-store" | ||
import { app, dialog, MessageBoxOptions } from "electron" | ||
import { detectGameVersion } from "./detectGameVersion" | ||
import { STEAM_APPS_DIRECTORY } from "./util" | ||
|
||
export const ORIGINAL_GAME_DIRECTORY = pathLib.resolve(STEAM_APPS_DIRECTORY, "Among Us") | ||
const store = new Store<{ | ||
originalGameDirectory: string | ||
}>() | ||
|
||
export const getOriginalGameDirectory = () => store.get("originalGameDirectory") | ||
const setOriginalGameDirectory = (path: string) => store.set("originalGameDirectory", path) | ||
|
||
export const getDirectoryForInstallations = () => pathLib.resolve(store.get("originalGameDirectory"), "..") | ||
|
||
let originalGameVersion: string | ||
export const getOriginalGameVersion = () => originalGameVersion | ||
|
||
export async function detectOriginalGameVersion() { | ||
if (!await fs.pathExists(ORIGINAL_GAME_DIRECTORY)) throw new Error("Among Us could not be found") | ||
originalGameVersion = await detectGameVersion(ORIGINAL_GAME_DIRECTORY) | ||
export const isValidGameDirectory = async (path: string) => fs.pathExists(pathLib.resolve(path, "Among Us.exe")) | ||
|
||
export async function detectOriginalGameVersion(): Promise<boolean> { | ||
if (!await fs.pathExists(getOriginalGameDirectory())) return false | ||
originalGameVersion = await detectGameVersion(getOriginalGameDirectory()) | ||
return true | ||
} | ||
|
||
export async function showOriginalGameDirectorySelectDialog(reason: "user" | "not-automatically" | "invalid") { | ||
if (reason !== "user") { | ||
const options: MessageBoxOptions = { | ||
title: reason === "not-automatically" | ||
? "Among Us could not be automatically detected." | ||
: "Among Us could not be found.", | ||
message: (reason === "not-automatically" ? "Among Us could not be automatically detected. " : "") + | ||
"Please select the directory which contains the game (Among Us.exe).\n\n", | ||
buttons: ["Cancel", "Select"], | ||
type: "error" | ||
} | ||
|
||
const { response } = await dialog.showMessageBox(options) | ||
if (response === 0) app.exit(0) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,no-constant-condition | ||
while (true) { | ||
const { filePaths } = await dialog.showOpenDialog({ | ||
properties: ["openDirectory", "dontAddToRecent"], | ||
buttonLabel: "Select", | ||
title: "Game directory selection" | ||
}) | ||
|
||
if (filePaths.length === 0) { | ||
if (reason === "user") return | ||
app.exit(0) | ||
} else { | ||
const [path] = filePaths | ||
|
||
if (await isValidGameDirectory(path)) { | ||
store.set("originalGameDirectory", path) | ||
app.relaunch() | ||
app.exit() | ||
return | ||
} | ||
|
||
const options: MessageBoxOptions = { | ||
type: "error", | ||
title: "Among Us could not be found.", | ||
message: "Please try again.", | ||
buttons: ["Cancel", "Retry"] | ||
} | ||
|
||
const { response } = await dialog.showMessageBox(options) | ||
if (response === 0) { | ||
if (reason === "user") return | ||
app.exit() | ||
} | ||
} | ||
} | ||
} | ||
|
||
export async function doStartupCheck() { | ||
if (store.has("originalGameDirectory")) { | ||
if (!await isValidGameDirectory(getOriginalGameDirectory())) await showOriginalGameDirectorySelectDialog("invalid") | ||
} else { | ||
const defaultPath = pathLib.resolve("C:\\Program Files (x86)\\Steam\\steamapps\\common", "./Among Us") | ||
if (await isValidGameDirectory(defaultPath)) setOriginalGameDirectory(defaultPath) | ||
else await showOriginalGameDirectorySelectDialog("not-automatically") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,24 @@ | ||
import { app, dialog } from "electron" | ||
import { detectOriginalGameVersion } from "./gameInfo" | ||
import { registerIPC, sendUIModData } from "./ipc" | ||
import { fetchRemoteMods } from "./remoteMods" | ||
import { discoverInstalledMods } from "./installedMods" | ||
import { STEAM_APPS_DIRECTORY } from "./util" | ||
|
||
export function initiateManager() { | ||
registerIPC() | ||
|
||
Promise.all([ | ||
discoverInstalledMods(), | ||
fetchRemoteMods(), | ||
detectOriginalGameVersion() | ||
fetchRemoteMods() | ||
]).then(() => { | ||
sendUIModData() | ||
}) | ||
} | ||
|
||
export async function loadGameVersionOrShowError() { | ||
try { | ||
await detectOriginalGameVersion() | ||
} catch { | ||
dialog.showErrorBox( | ||
"Among Us could not be found", | ||
`Please make sure Among Us is installed in the default location of Steam games. (${STEAM_APPS_DIRECTORY})` | ||
) | ||
|
||
app.exit(1) | ||
} | ||
} | ||
|
||
export { isGameRunning } from "./installedMods" | ||
export { getOriginalGameVersion } from "./gameInfo" | ||
export { STEAM_APPS_DIRECTORY } from "./util" | ||
export { | ||
getOriginalGameVersion, | ||
isValidGameDirectory, | ||
doStartupCheck, | ||
getDirectoryForInstallations, | ||
showOriginalGameDirectorySelectDialog, | ||
detectOriginalGameVersion | ||
} from "./gameInfo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import { getWindow } from "../window" | ||
|
||
export const STEAM_APPS_DIRECTORY = "C:\\Program Files (x86)\\Steam\\steamapps\\common" | ||
|
||
export function send(channel: string, ...arguments_: unknown[]) { | ||
getWindow().webContents.send(channel, ...arguments_) | ||
} |