Skip to content

Commit

Permalink
much better logic for setting game.installed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Owen3H committed Oct 18, 2024
1 parent cb570bd commit d50cf5f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
16 changes: 14 additions & 2 deletions backend/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/mocks/GameService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/stores/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ThunderstoreGame>
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/GameSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ onMounted(async () => {
<Button
outlined plain
icon="pi pi-folder"
v-if="game.path"
v-if="game.installed"
v-tooltip.top="tooltipOpts(t('tooltips.game-selection.open-folder-location'))"
@click="openLink(`file://${game.path}`)"
/>
Expand Down

0 comments on commit d50cf5f

Please sign in to comment.