Skip to content

Commit

Permalink
Added ability to select game store when manually choosing game folder (
Browse files Browse the repository at this point in the history
  • Loading branch information
IDCs committed Apr 2, 2024
1 parent c60b232 commit fbd4b8d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/extensions/gamemode_management/GameModeManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable */
import { setNextProfile } from '../../actions';
import { addNotification, showDialog } from '../../actions/notifications';
import { IDiscoveredTool } from '../../types/IDiscoveredTool';
import { ThunkStore } from '../../types/IExtensionContext';
import { IExtensionApi, ThunkStore } from '../../types/IExtensionContext';
import { IGame } from '../../types/IGame';
import { GameEntryNotFound, IGameStore } from '../../types/IGameStore';
import { IState } from '../../types/IState';
Expand Down Expand Up @@ -55,17 +56,20 @@ export interface IGameStub {
* @class GameModeManager
*/
class GameModeManager {
private mApi: IExtensionApi;
private mStore: ThunkStore<IState>;
private mKnownGames: IGame[];
private mGameStubs: IGameStub[];
private mKnownGameStores: IGameStore[];
private mActiveSearch: Promise<void>;
private mOnGameModeActivated: (mode: string) => void;

constructor(extensionGames: IGame[],
constructor(api: IExtensionApi,
extensionGames: IGame[],
gameStubs: IGameStub[],
gameStoreExtensions: IGameStore[],
onGameModeActivated: (mode: string) => void) {
this.mApi = api;
this.mStore = null;
this.mKnownGames = extensionGames;
this.mGameStubs = gameStubs;
Expand Down Expand Up @@ -376,7 +380,7 @@ class GameModeManager {
}

private reloadStoreGames() {
return GameStoreHelper.reloadGames();
return GameStoreHelper.reloadGames(this.mApi);
}

private isValidGame(game: IGameStored): boolean {
Expand Down
35 changes: 32 additions & 3 deletions src/extensions/gamemode_management/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { showDialog } from '../../actions/notifications';
import { setDialogVisible } from '../../actions/session';
import OptionsFilter, { ISelectOption } from '../../controls/table/OptionsFilter';
Expand Down Expand Up @@ -42,7 +43,7 @@ import { IDiscoveryResult } from './types/IDiscoveryResult';
import { IGameStored } from './types/IGameStored';
import { IModType } from './types/IModType';
import getDriveList from './util/getDriveList';
import { getGame, getGameStore } from './util/getGame';
import { getGame, getGameStore, getGameStores } from './util/getGame';
import { getModType, getModTypeExtensions, registerModType } from './util/modTypeExtensions';
import ProcessMonitor from './util/ProcessMonitor';
import queryGameInfo from './util/queryGameInfo';
Expand Down Expand Up @@ -202,6 +203,34 @@ function findGamePath(game: IGame, selectedPath: string,
findGamePath(game, path.dirname(selectedPath), depth + 1, maxDepth));
}

function manualGameStoreSelection(api: IExtensionApi, correctedGamePath: string): Promise<{ store: string, corrected: string }> {
const gameStores = getGameStores();
return GameStoreHelper.identifyStore(correctedGamePath)
.then((storeId) => {
const detectedStore = gameStores.find(store => store.id === storeId);
return api.showDialog('question', 'Choose a Game Store', {
bbcode: api.translate('The currently identified game store for your selected game directory is: "{{gameStore}}".[br][/br][br][/br]'
+ 'If this is not the correct game store, please choose below. (Games can have game store specific folder structures)[br][/br][br][/br]',
{ replace: { gameStore: detectedStore?.name || 'Unknown' } }),
choices: gameStores.map((store) => ({ id: store.id, text: store.name, value: store.id === storeId }))
.concat({ id: 'other', text: 'Other', value: storeId === undefined }),
}, [
{ label: 'Select' },
])
.then((res) => {
const selected = Object.keys(res.input).find(iter => res.input[iter]);
if (selected === undefined) {
return Promise.reject(new UserCanceled());
}
if (selected === 'other') {
return { store: storeId, corrected: correctedGamePath };
} else {
return { store: selected, corrected: correctedGamePath };
}
});
})
}

function browseGameLocation(api: IExtensionApi, gameId: string): Promise<void> {
const state: IState = api.store.getState();

Expand Down Expand Up @@ -230,8 +259,7 @@ function browseGameLocation(api: IExtensionApi, gameId: string): Promise<void> {
.then(result => {
if (result !== undefined) {
findGamePath(game, result, 0, searchDepth(game.requiredFiles || []))
.then((corrected: string) => GameStoreHelper.identifyStore(corrected)
.then(store => ({ corrected, store })))
.then((corrected: string) => manualGameStoreSelection(api, corrected))
.then(({ corrected, store }) => {
let executable = game.executable(corrected);
if (executable === game.executable()) {
Expand Down Expand Up @@ -679,6 +707,7 @@ function init(context: IExtensionContext): boolean {
context.api.ext['awaitProfileSwitch'] = () => awaitProfileSwitch(context.api);

$.gameModeManager = new GameModeManagerImpl(
context.api,
$.extensionGames,
$.extensionStubs,
gameStoreLaunchers,
Expand Down
16 changes: 14 additions & 2 deletions src/util/GameStoreHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface IStoreQuery {
}

class GameStoreHelper {
private mApi: IExtensionApi;
private mStores: IGameStore[];
private mStoresDict: { [storeId: string]: IGameStore };

Expand Down Expand Up @@ -260,8 +261,16 @@ class GameStoreHelper {
return undefined;
});

public reloadGames(): Bluebird<void> {
public reloadGames(api?: IExtensionApi): Bluebird<void> {
if (!!api && !this.mApi) {
this.mApi = api;
}
const stores = this.getStores().filter(store => !!store);
this.mApi?.sendNotification({
id: 'gamestore-reload',
type: 'activity',
message: 'Loading game stores...',
});
log('info', 'reloading game store games', stores.map(store => store.id)
.join(', '));
return Bluebird.each(stores, (store: IGameStore) =>
Expand All @@ -275,7 +284,10 @@ class GameStoreHelper {
return Bluebird.resolve();
})
: Bluebird.resolve())
.then(() => Bluebird.resolve());
.then(() => {
this.mApi?.dismissNotification('gamestore-reload');
return Bluebird.resolve()
});
}

/**
Expand Down

0 comments on commit fbd4b8d

Please sign in to comment.