Skip to content

Commit

Permalink
Merge pull request #45 from Nexus-Mods/1.12.x
Browse files Browse the repository at this point in the history
Added error logging for failed ASI INI merges
  • Loading branch information
insomnious authored Aug 12, 2024
2 parents 9974ff1 + c35091b commit b33359b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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.8.8] - 2024-08-xx

- Improved error logging for failed ASI INI merges
- Improved error handling of LOOT errors
- Fixed potential attempts to write invalid mod entries to plugins file

## [0.8.7] - 2024-07-30

- Fixed native plugins added to plugins.txt file when Starfield.ccc is present
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.8.7",
"version": "0.8.8",
"description": "Vortex Extension for Starfield",
"author": "Nexus Mods",
"private": true,
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import {
forceRefresh,
getGameVersionAsync,
getGameVersionSync,
serializePluginsFile,
lootSortingAllowed,
resolvePluginsFilePath,
lootSort,
switchToLoot,
} from './util';
import { toggleJunction, setup } from './setup';
import { raiseJunctionDialog, testFolderJunction, testLooseFiles, testDeprecatedFomod, testPluginsEnabler } from './tests';
Expand Down
3 changes: 2 additions & 1 deletion src/merges/iniMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import { parse, stringify } from 'ini-comments';
import { GAME_ID, ASI_MOD_INI_NAME } from '../common';
import { sanitizeIni, deepMerge } from '../util';
import { fs, types } from 'vortex-api';
import { fs, log, types } from 'vortex-api';

export function testASIMergeIni(game: types.IGame, discovery:
types.IDiscoveryResult): types.IMergeFilter | undefined {
Expand Down Expand Up @@ -34,6 +34,7 @@ export async function mergeASIIni(filePath: string, mergeDir: string): Promise<v
});
return Promise.resolve();
} catch (err) {
log('error', 'Error merging INI', { message: err.message, filePath, mergeDir });
return Promise.reject(err);
}
}
30 changes: 22 additions & 8 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,20 @@ export function forceRefresh(api: types.IExtensionApi) {

export async function serializePluginsFile(api: types.IExtensionApi, plugins: types.ILoadOrderEntry[]): Promise<void> {
const nativePlugins = await resolveNativePlugins(api);
const data = plugins.map(plugin => {
const data: string[] = plugins.reduce((acc, plugin) => {
if (plugin?.name === undefined) {
// how?
return acc;
}
// Strip the native plugins from whatever we write to the file as it's uneccessary.
if (nativePlugins.includes(plugin.name.toLowerCase())) {
return '';
return acc;
}
const invalid = plugin.data?.isInvalid ? '#' : '';
const enabled = plugin.enabled ? '*' : '';
return `${invalid}${enabled}${plugin.name}`
});
acc.push(`${invalid}${enabled}${plugin.name}`);
return acc;
}, []);
data.splice(0, 0, '# This file was automatically generated by Vortex. Do not edit this file.');
const pluginsFile = await resolvePluginsFilePath(api);
await fs.writeFileAsync(pluginsFile, data.filter(plug => !!plug).join('\n'), { encoding: 'utf8' });
Expand Down Expand Up @@ -485,10 +490,14 @@ export const resolveNativePlugins = async (api: types.IExtensionApi): Promise<st
try {
await fs.statAsync(cccFilePath);
const data = await fs.readFileAsync(cccFilePath, 'utf8');
const lines = data.split('\r\n').filter(plugin => plugin !== '').map(l => l.toLowerCase());
const lines: string[] = data.split('\r\n').filter(plugin => plugin !== '').map(l => l.toLowerCase());
for (const native of defaultNatives) {
if (!lines.includes(native)) {
lines.push(native);
if (native === NATIVE_PLUGINS[0]) {
lines.unshift(native);
} else {
lines.push(native);
}
}
}
return lines;
Expand All @@ -515,9 +524,14 @@ export async function lootSort(api: types.IExtensionApi) {
isInvalid: false,
},
});
const onSortCallback = async (sorted: string[]) => {
const onSortCallback = async (err: Error, result: string[]) => {
if (err) {
api.showErrorNotification('LOOT sort failed', err.message);
api.dismissNotification('starfield-fblo-loot-sorting');
return;
}
api.dismissNotification('starfield-fblo-loot-sorting');
serializePluginsFile(api, sorted.map(toLOEntry));
serializePluginsFile(api, result.map(toLOEntry));
forceRefresh(api);
};
if (api.ext.lootSortAsync !== undefined) {
Expand Down

0 comments on commit b33359b

Please sign in to comment.