Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/components/composables/GameSelectionComposable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import ProviderUtils from '../../providers/generic/ProviderUtils';
import R2Error from '../../model/errors/R2Error';
import { getStore } from '../../providers/generic/store/StoreProvider';
import { State } from '../../store';
import { getInstalledSteamAppIds } from '../../r2mm/manager/SteamLibraryScanner';

export function useGameSelectionComposable() {
const store = getStore<State>();
const router = useRouter();

const favourites = ref<string[]>([]);
const installedAppIds = ref<Set<string>>(new Set());
const selectedGame = ref<Game | null>(null);
const selectedPlatform = ref<Platform | null>(null);
const filterText = ref<string>('');
Expand Down Expand Up @@ -66,10 +68,21 @@ export function useGameSelectionComposable() {
.filter((value: Game) => favourites.value.includes(value.settingsIdentifier));
});

const installedGameList = computed(() => {
return filteredGameList.value
.filter((value: Game) => !hiddenGameList.value.includes(value))
.filter((value: Game) => value.storePlatformMetadata.some(
p => [Platform.STEAM, Platform.STEAM_DIRECT].includes(p.storePlatform)
&& p.storeIdentifier != null
&& installedAppIds.value.has(String(p.storeIdentifier))
));
});

const nonFavouriteGameList = computed(() => {
return filteredGameList.value
.filter((value: Game) => !hiddenGameList.value.includes(value))
.filter((value: Game) => !favourites.value.includes(value.settingsIdentifier));
.filter((value: Game) => !favourites.value.includes(value.settingsIdentifier))
.filter((value: Game) => !installedGameList.value.includes(value));
});

function isFavourited(game: Game): boolean {
Expand Down Expand Up @@ -145,6 +158,7 @@ export function useGameSelectionComposable() {
settings.value = await ManagerSettings.getSingleton(GameManager.defaultGame);
const globalSettings = settings.value.getContext().global;
favourites.value = globalSettings.favouriteGames || [];
installedAppIds.value = await getInstalledSteamAppIds();

const lastGame = GameManager.findByFolderName(globalSettings.lastSelectedGame);
if (lastGame) markAsSelectedGame(lastGame);
Expand Down Expand Up @@ -190,6 +204,7 @@ export function useGameSelectionComposable() {
isSettingDefaultPlatform,
hiddenGameList,
favouriteGameList,
installedGameList,
nonFavouriteGameList,
isFavourited,
isGameSelected,
Expand Down
35 changes: 31 additions & 4 deletions src/components/game-selection/GameSelectionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
@click="markAsSelectedGame(game)"
@toggle-favourite="toggleFavourite(game)"
/>
<GameSelectionListItem
v-for="game of installedGameList"
:key="game.settingsIdentifier"
:game="game"
:is-selected="isGameSelected(game)"
:is-favourited="isFavourited(game)"
@click="markAsSelectedGame(game)"
@toggle-favourite="toggleFavourite(game)"
/>
<GameSelectionListItem
v-for="game of nonFavouriteGameList"
:key="game.settingsIdentifier"
Expand Down Expand Up @@ -56,8 +65,27 @@
</template>


<template v-if="nonFavouriteGameList.length > 0">
<template v-if="installedGameList.length > 0">
<hr v-if="favouriteGameList.length > 0"/>
<GameSelectionSection title="Installed Games" :count="installedGameList.length" :default-open="true">
<div class="game-cards-container">
<GameSelectionCard
v-for="game of installedGameList"
:key="game.settingsIdentifier"
:game="game"
:is-selected="isGameSelected(game)"
:is-favourited="isFavourited(game)"
:active-tab="activeTab"
@select="emit('select-game', $event)"
@set-default="emit('set-default-game', $event)"
@toggle-favourite="toggleFavourite($event)"
/>
</div>
</GameSelectionSection>
</template>

<template v-if="nonFavouriteGameList.length > 0">
<hr v-if="favouriteGameList.length > 0 || installedGameList.length > 0"/>
<GameSelectionSection
:title="`${capitalize(activeTab)}s`"
:count="nonFavouriteGameList.length"
Expand Down Expand Up @@ -149,14 +177,13 @@ const emit = defineEmits<{
}>();

const mergedGameList = computed(() => {
const favourites = favouriteGameList.value;
const others = nonFavouriteGameList.value;
return [...favourites, ...others];
return [...favouriteGameList.value, ...installedGameList.value, ...nonFavouriteGameList.value];
})

const {
hiddenGameList,
favouriteGameList,
installedGameList,
nonFavouriteGameList,
activeTab,
viewMode,
Expand Down
86 changes: 86 additions & 0 deletions src/r2mm/manager/SteamLibraryScanner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as vdf from '@node-steam/vdf';
import R2Error from '../../model/errors/R2Error';
import FsProvider from '../../providers/generic/file/FsProvider';
import PlatformInterceptorProvider from '../../providers/generic/game/platform_interceptor/PlatformInterceptorProvider';
import { Platform } from '../../model/schema/ThunderstoreSchema';
import path from '../../providers/node/path/path';

export async function getInstalledSteamAppIds(): Promise<Set<string>> {
try {
const resolver = PlatformInterceptorProvider.instance.getDirectoryResolverForPlatform(Platform.STEAM);
if (resolver === undefined) return new Set();
const steamPath = await resolver.getSteamDirectory();
if (steamPath instanceof R2Error) return new Set();

const fs = FsProvider.instance;
const steamappsSubPaths = ['steamapps', path.join('steam', 'steamapps'), path.join('root', 'steamapps')];

let rootSteamapps: string | undefined;
for (const sub of steamappsSubPaths) {
const candidate = path.join(steamPath, sub);
if (await fs.exists(candidate)) {
rootSteamapps = candidate;
break;
}
}

if (rootSteamapps === undefined) return new Set();

const locations: string[] = [rootSteamapps];

try {
const files = await fs.readdir(rootSteamapps);
for (const file of files) {
if (file.toLowerCase() !== 'libraryfolders.vdf') continue;
const raw = (await fs.readFile(path.join(rootSteamapps, file))).toString();
const parsed: any = vdf.parse(raw);
const folders = parsed.libraryfolders ?? parsed.LibraryFolders;
if (!folders) continue;
for (const key of Object.keys(folders)) {
if (isNaN(Number(key))) continue;
const entry = folders[key];
const folderPath = typeof entry === 'string' ? entry : entry?.path;
if (typeof folderPath === 'string') {
locations.push(path.join(folderPath, 'steamapps'));
}
}
}
} catch {
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣤⣀⣀⠀⠀⣀⡠⠴⠒⠚⠉⠉⠓⠒⠦⣄⣶⠒⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡷⢬⣉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠠⡌⠻⣧⢻⣧⣤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣖⠗⡋⢹⠀⠀⢰⡄⠀⠀⢸⣷⡀⠀⣠⠽⣆⢼⣇⢻⣸⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡜⣡⣶⢋⡏⠙⢢⣏⣇⠀⠀⠈⣇⡵⡏⠀⠀⢹⡏⢾⣿⠃⢿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⢿⢻⣏⣿⡇⡄⣾⠀⠹⡄⠄⠀⡇⠀⠹⣤⠈⠹⣿⣾⢸⠀⢘⣷⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣴⣯⣿⣽⣿⣷⢸⡗⠦⣄⡹⣼⣄⣿⣴⠛⠹⡄⡇⣿⣿⠾⠚⢹⢿⢽⣽⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣞⣾⣿⢿⣯⢻⢻⡴⠞⠁⠈⠻⣿⣌⡉⠓⣿⣰⡿⠀⠀⠀⠸⡜⡾⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡴⣡⠊⢸⣹⠁⠈⠙⣾⡄⠁⠀⢰⠛⠉⠉⠉⢳⣀⣿⣿⠃⠀⠀⣀⣀⣧⣿⡞⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠋⡴⠁⠀⠸⢿⣤⣤⣤⣹⣿⣷⣶⣾⣷⣶⣶⣺⣋⣽⣿⣷⠶⠟⠛⠋⢧⠀⠀⠸⡜⣷⠀⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡜⠁⡰⠁⠀⠀⢠⡿⠀⠀⠀⠉⠉⠉⠙⢻⡟⣹⣿⠃⣿⠋⠁⠀⠀⠀⠀⠀⠸⡄⠀⠀⢣⠹⣧⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠏⡀⢠⠇⠀⠀⢠⡿⠁⠀⠀⠀⠀⣤⣶⡴⠚⢻⠡⣸⠀⢹⣆⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠸⡄⢻⣇⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⢀⡏⣼⠁⢸⠀⠀⠀⣾⠃⠀⠀⠀⠀⠀⢻⣿⣧⣀⣬⠋⠁⠀⣠⣿⣶⣆⠀⠀⠀⠀⠀⡇⠀⠀⠀⡇⠈⣿⡀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⣸⣸⣿⠀⡇⠀⢰⣸⡟⠀⠀⠀⣀⣠⠴⠚⣟⣻⣧⣯⣗⣤⣾⣿⣿⡿⠋⠀⠀⠀⠀⣸⣤⠀⠀⠀⡇⡆⢻⠃⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⣿⡿⢸⡀⣇⠀⣸⣿⡁⠀⣾⣻⡁⣀⣤⣶⠟⠋⠉⠛⢿⣋⣻⡏⠉⠀⠀⠀⠀⠀⢰⣿⡇⠀⠀⠀⣷⡇⣸⡄⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠿⠇⠀⢧⢸⠀⣿⡿⠇⠀⠈⠛⠛⠋⠉⠀⠀⠀⠀⠀⡟⠀⣿⠇⠀⠀⠀⠀⠀⢠⣿⣿⡇⠀⠀⣰⡿⣧⣿⠃⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣄⣹⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡇⠀⣿⠀⠀⠀⠀⠀⠀⣸⡿⢸⠁⢠⣾⠋⢰⣿⡏⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣶⣶⡿⠀⠀⠀⠀⠀⠀⠉⠁⢸⣶⡟⠁⠀⠾⠟⠀⠀⠀⠀⠀⠀⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i couldn't resist, lmk if you want it removed LOL

}

const appIds = new Set<string>();
const manifestPattern = /^appmanifest_(\d+)\.acf$/i;

for (const location of locations) {
if (!(await fs.exists(location))) continue;
const files = await fs.readdir(location);
for (const file of files) {
const match = file.match(manifestPattern);
if (match) appIds.add(match[1]);
}
}

return appIds;
} catch (e) {
console.warn('SteamLibraryScanner: failed to scan Steam library', e);
return new Set();
}
}