@@ -122,6 +122,12 @@ const removePluginsWrap = (api: types.IExtensionApi) => {
122122 ) ;
123123} ;
124124
125+ const isCorrectGame = ( api : types . IExtensionApi , profileId : string ) => {
126+ const state = api . getState ( ) ;
127+ const profile = selectors . profileById ( state , profileId ) ;
128+ return profile ?. gameId === GAME_ID ;
129+ } ;
130+
125131function main ( context : types . IExtensionContext ) {
126132 context . registerReducer ( [ 'settings' , 'starfield' ] , settingsReducer ) ;
127133 // register a whole game, basic metadata and folder paths
@@ -249,9 +255,7 @@ async function onGameModeActivated(api: types.IExtensionApi) {
249255}
250256
251257async function onDidDeployEvent ( api : types . IExtensionApi , profileId : string , deployment : types . IDeploymentManifest ) : Promise < void > {
252- const state = api . getState ( ) ;
253- const gameId = selectors . profileById ( state , profileId ) ?. gameId ;
254- if ( gameId !== GAME_ID ) {
258+ if ( ! isCorrectGame ( api , profileId ) ) {
255259 return Promise . resolve ( ) ;
256260 }
257261 await testDeprecatedFomod ( api , false ) ;
@@ -261,19 +265,24 @@ async function onDidDeployEvent(api: types.IExtensionApi, profileId: string, dep
261265}
262266
263267async function onWillPurgeEvent ( api : types . IExtensionApi , profileId : string ) : Promise < void > {
268+ if ( ! isCorrectGame ( api , profileId ) ) {
269+ return Promise . resolve ( ) ;
270+ }
264271 const pluginsPath = await resolvePluginsFilePath ( api ) ;
265272 return fs . copyAsync ( pluginsPath , PLUGINS_BACKUP , { overwrite : true } ) . catch ( ( err ) => null ) ;
266273}
267274
268275async function onDidPurgeEvent ( api : types . IExtensionApi , profileId : string ) : Promise < void > {
276+ if ( ! isCorrectGame ( api , profileId ) ) {
277+ return Promise . resolve ( ) ;
278+ }
269279 return linkAsiLoader ( api , ASI_LOADER_BACKUP , TARGET_ASI_LOADER_NAME ) ;
270280}
271281
272282async function onWillDeployEvent ( api : types . IExtensionApi , profileId : any , deployment : types . IDeploymentManifest ) : Promise < void > {
273283 const state = api . getState ( ) ;
274284 const pluginEnabler = util . getSafe ( state , [ 'settings' , 'starfield' , 'pluginEnabler' ] , false ) ;
275- const profile = selectors . activeProfile ( state ) ;
276- if ( profile ?. gameId !== GAME_ID || pluginEnabler === false ) {
285+ if ( ! isCorrectGame ( api , profileId ) || pluginEnabler === false ) {
277286 return Promise . resolve ( ) ;
278287 }
279288 const discovery = selectors . discoveryByGame ( state , GAME_ID ) ;
0 commit comments