From 6d143f147965a55ea392bfdf51d6ae0b1e98cc98 Mon Sep 17 00:00:00 2001 From: O3H Date: Fri, 18 Oct 2024 12:39:44 +0100 Subject: [PATCH] much better logic for setting `game.installed` Leveraged existing backend function to check whether a path exists (our game in this case) in a platform-independent way so it works regardless of path separator. This now means the config files button, installed tab and open folder button all react properly if the game is moved. TODO: Check for game executable in addition to dir. --- backend/app/app.go | 16 ++++++++++++++-- frontend/src/mocks/GameService.ts | 2 +- frontend/src/stores/game.ts | 6 +++++- frontend/src/views/GameSelection.vue | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/app/app.go b/backend/app/app.go index c613593..d85608d 100644 --- a/backend/app/app.go +++ b/backend/app/app.go @@ -37,11 +37,23 @@ func NewUtils() *Utils { return &Utils{} } -func (util *Utils) WalkDirExt(root string, exts []string) ([]string, error) { +func (u *Utils) ExistsInDir(dir, item string) (bool, error) { + return backend.ExistsInDir(dir, item) +} + +func (u Utils) ExistsAtPath(path string, clean bool) (bool, error) { + if clean { + path = filepath.Clean(path) + } + + return backend.ExistsAtPath(path) +} + +func (u *Utils) WalkDirExt(root string, exts []string) ([]string, error) { return backend.WalkDirExt(root, exts) } -func (util *Utils) ReadFile(path string) (*string, error) { +func (u *Utils) ReadFile(path string) (*string, error) { return backend.ReadFile(path) } diff --git a/frontend/src/mocks/GameService.ts b/frontend/src/mocks/GameService.ts index cedea55..0697c43 100644 --- a/frontend/src/mocks/GameService.ts +++ b/frontend/src/mocks/GameService.ts @@ -4,7 +4,7 @@ export const mockGameList: ThunderstoreGame[] = [{ title: "Lethal Company", identifier: 'lethal-company', image: "LethalCompany.png", - path: "E:\\SteamLibrary\\steamapps\\common\\Lethal Company", + path: "E:/SteamLibrary/steamapps/common/Lethal Company", aliases: ["LC", "LethalCompany"], steamID: 1966720 }, { diff --git a/frontend/src/stores/game.ts b/frontend/src/stores/game.ts index 4079d4d..353e05c 100644 --- a/frontend/src/stores/game.ts +++ b/frontend/src/stores/game.ts @@ -7,6 +7,8 @@ import { thunderstore } from '@backend/models.js' import { GetPersistence } from '@backend/app/Application.js' import { BepinexInstalled } from '@backend/game/GameManager.js' +import { ExistsAtPath } from '@backend/app/Utils.js' + export interface GameState { selectedGame: ThunderstoreGame, games: Map @@ -69,7 +71,9 @@ export const useGameStore = defineStore('GameStore', () => { // Init game props. for (const game of gameList) { game.favourited = await persistence.favourite_games.includes(game.identifier) - game.installed = !!game.path // TODO: Check game executable exists. For now, assume installed if path specified. + + // TODO: Check game executable exists. For now, assume installed if game path is specified and exists. + game.installed = !game.path ? false : await ExistsAtPath(game.path, true) if (game.path) { game.bepinexSetup = await BepinexInstalled(game.path) diff --git a/frontend/src/views/GameSelection.vue b/frontend/src/views/GameSelection.vue index 4fe8ab5..c813931 100644 --- a/frontend/src/views/GameSelection.vue +++ b/frontend/src/views/GameSelection.vue @@ -306,7 +306,7 @@ onMounted(async () => {