Skip to content

Commit

Permalink
Ensure we maintain LO on purge (#35)
Browse files Browse the repository at this point in the history
* Ensure we maintain LO on purge

* LO entry indexes are maintained between deployment events
  • Loading branch information
IDCs authored Dec 20, 2023
1 parent 4cc97cd commit 33d3610
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.6.6] - 2023-12-14

- Added warning when resetting the plugins file.
- Load order is no longer removed when purging mods.

## [0.6.5] - 2023-12-14

- Added Xbox Game Pass specific information to help users avoid/fix the "This library isn't supported" error
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starfield",
"version": "0.6.5",
"version": "0.6.6",
"description": "Vortex Extension for Starfield",
"author": "Nexus Mods",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { util } from 'vortex-api';

export const LOCAL_APP_DATA = path.join(util.getVortexPath('localAppData'), 'Starfield');
export const PLUGINS_TXT = path.join(LOCAL_APP_DATA, 'plugins.txt');
export const PLUGINS_BACKUP = path.join(util.getVortexPath('temp'), path.basename(PLUGINS_TXT) + '.bak');
export const PLUGINS_ENABLER_FILENAME = 'SFPluginsTxtEnabler';
export const NS = 'game-starfield';
export const GAME_ID = 'starfield';
Expand Down
28 changes: 21 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import { getStopPatterns } from './stopPatterns';

import StarFieldLoadOrder from './loadOrder/StarFieldLoadOrder';

// IDs for different stores and nexus
import { GAME_ID, SFSE_EXE, MOD_TYPE_DATAPATH, MOD_TYPE_ASI_MOD, STEAMAPP_ID, XBOX_ID, JUNCTION_NOTIFICATION_ID, TARGET_ASI_LOADER_NAME, ASI_LOADER_BACKUP } from './common';
import { GAME_ID, SFSE_EXE, MOD_TYPE_DATAPATH, MOD_TYPE_ASI_MOD,
STEAMAPP_ID, XBOX_ID, TARGET_ASI_LOADER_NAME,
ASI_LOADER_BACKUP, PLUGINS_TXT, PLUGINS_BACKUP } from './common';

const supportedTools: types.ITool[] = [
{
Expand Down Expand Up @@ -66,10 +67,17 @@ const gameFinderQuery = {
};

const removePluginsWrap = (api: types.IExtensionApi) => {
removePluginsFile()
.then(() => {
forceRefresh(api);
});
api.showDialog('question', 'Reset Plugins File', {
text: 'Are you sure you want to reset the plugins file? This will remove all plugins from your load order, and you will need to re-arrange them!',
}, [
{ label: 'Cancel' },
{ label: 'Reset', action: () => {
removePluginsFile()
.then(() => {
forceRefresh(api);
});
} },
], 'starfield-remove-plugins-dialog');
}

function main(context: types.IExtensionContext) {
Expand Down Expand Up @@ -160,8 +168,9 @@ function main(context: types.IExtensionContext) {
context.once(() => {
//context.api.setStylesheet('starfield', path.join(__dirname, 'starfield.scss'));
context.api.events.on('gamemode-activated', () => onGameModeActivated(context.api));
context.api.onAsync('did-deploy', (profileId: string, deployment: types.IDeploymentManifest) => onDidDeployEvent(context.api, profileId, deployment));
context.api.onAsync('will-deploy', (profileId: string, deployment: types.IDeploymentManifest) => onWillDeployEvent(context.api, profileId, deployment));
context.api.onAsync('did-deploy', (profileId: string, deployment: types.IDeploymentManifest) => onDidDeployEvent(context.api, profileId, deployment));
context.api.onAsync('will-purge', (profileId: string) => onWillPurgeEvent(context.api, profileId));
context.api.onAsync('did-purge', (profileId: string) => onDidPurgeEvent(context.api, profileId));
// context.api.onAsync('intercept-file-changes', (intercepted: types.IFileChange[], cb: (result: types.IFileChange[]) => void) => {
// return onInterceptFileChanges(context.api, intercepted, cb);
Expand Down Expand Up @@ -190,9 +199,14 @@ async function onDidDeployEvent(api: types.IExtensionApi, profileId: string, dep
}
await testDeprecatedFomod(api, false);
await testPluginsEnabler(api);
await fs.removeAsync(PLUGINS_BACKUP).catch(err => null);
return Promise.resolve();
}

async function onWillPurgeEvent(api: types.IExtensionApi, profileId: string): Promise<void> {
return fs.copyAsync(PLUGINS_TXT, PLUGINS_BACKUP, { overwrite: true }).catch(err => null);
}

async function onDidPurgeEvent(api: types.IExtensionApi, profileId: string): Promise<void> {
return linkAsiLoader(api, ASI_LOADER_BACKUP, TARGET_ASI_LOADER_NAME);
}
Expand Down
9 changes: 7 additions & 2 deletions src/loadOrder/StarFieldLoadOrder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fs, selectors, types, util } from 'vortex-api';

import { IPluginRequirement } from '../types';
import {
GAME_ID, PLUGINS_TXT, MOD_TYPE_ASI_MOD, PLUGINS_ENABLER_FILENAME, NATIVE_PLUGINS,
GAME_ID, PLUGINS_TXT, PLUGINS_BACKUP, MOD_TYPE_ASI_MOD, PLUGINS_ENABLER_FILENAME, NATIVE_PLUGINS,
DLL_EXT, ASI_EXT, MOD_TYPE_DATAPATH, SFSE_EXE, TARGET_ASI_LOADER_NAME, DATA_PLUGINS, MISSING_PLUGINS_NOTIFICATION_ID,
} from '../common';
import { download } from '../downloader';
Expand Down Expand Up @@ -56,6 +56,7 @@ export const PLUGIN_REQUIREMENTS: PluginRequirements = {
class StarFieldLoadOrder implements types.ILoadOrderGameInfo {
public gameId: string;
public toggleableEntries?: boolean | undefined;
public clearStateOnPurge?: boolean | undefined;
public usageInstructions?: React.ComponentType<{}>;
public noCollectionGeneration?: boolean | undefined;

Expand All @@ -64,6 +65,7 @@ class StarFieldLoadOrder implements types.ILoadOrderGameInfo {

constructor(api: types.IExtensionApi) {
this.gameId = GAME_ID;
this.clearStateOnPurge = true;
this.toggleableEntries = true;
this.noCollectionGeneration = true;
this.usageInstructions = () => (<InfoPanel onInstallPluginsEnabler={this.mOnInstallPluginsEnabler} />);
Expand Down Expand Up @@ -270,7 +272,10 @@ class StarFieldLoadOrder implements types.ILoadOrderGameInfo {

private async deserializePluginsFile(): Promise<string[]> {
try {
const data = await fs.readFileAsync(PLUGINS_TXT, 'utf8');
const targetFile = await fs.statAsync(PLUGINS_BACKUP)
.then(() => PLUGINS_BACKUP)
.catch(() => PLUGINS_TXT);
const data = await fs.readFileAsync(targetFile, 'utf8');
const lines = data.split('\n').filter(line => line.trim().length > 0);
return Array.from(new Set(lines));
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import { fs, log, selectors, types, util } from 'vortex-api';
import { PLUGINS_TXT, LOCAL_APP_DATA, GAME_ID, MY_GAMES_DATA_WARNING, MISSING_PLUGINS_NOTIFICATION_ID, JUNCTION_NOTIFICATION_ID } from './common';
import { PLUGINS_TXT, LOCAL_APP_DATA, GAME_ID, MY_GAMES_DATA_WARNING, MISSING_PLUGINS_NOTIFICATION_ID, JUNCTION_NOTIFICATION_ID, PLUGINS_BACKUP } from './common';
import turbowalk, { IWalkOptions, IEntry } from 'turbowalk';
import path from 'path';
import { getStopPatterns } from './stopPatterns';
Expand Down Expand Up @@ -124,6 +124,7 @@ export const openAppDataPath = () => {

export const removePluginsFile = async () => {
try {
await fs.removeAsync(PLUGINS_BACKUP).catch(err => null);
await fs.unlinkAsync(PLUGINS_TXT);
} catch (err) {
// File doesn't exist, nothing to do.
Expand Down

0 comments on commit 33d3610

Please sign in to comment.