Skip to content

Commit

Permalink
W3: fixed crash when the script merger is missing/misconfigured
Browse files Browse the repository at this point in the history
- For real this time!
- Vortex will now raise the missing script merger notification even if
  the user deletes it manually while Vortex is open.

fixes Nexus-Mods/Vortex#7024
  • Loading branch information
IDCs committed Jan 22, 2021
1 parent c0c5a12 commit d5e22bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions game-witcher3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,20 @@ function testDLC(instructions) {
instruction => !!instruction.destination && instruction.destination.toLowerCase().startsWith('dlc' + path.sep)) !== undefined);
}

function prepareForModding(context, discovery) {
function notifyMissingScriptMerger(api) {
const notifId = 'missing-script-merger';
const api = context.api;
const missingScriptMerger = () => api.sendNotification({
api.sendNotification({
id: notifId,
type: 'info',
message: api.translate('Witcher 3 script merger not installed/configured', { ns: I18N_NAMESPACE }),
message: api.translate('Witcher 3 script merger is missing/misconfigured', { ns: I18N_NAMESPACE }),
allowSuppress: true,
actions: [
{
title: 'More',
action: () => {
api.showDialog('info', 'Witcher 3', {
bbcode: api.translate('Vortex was unable to install the script merger automatically. Unfortunately the tool needs to be downloaded and configured manually. '
+ '[url=https://wiki.nexusmods.com/index.php/Tool_Setup:_Witcher_3_Script_Merger]find out more about how to configure it as a tool for use in Vortex.[/url][br][/br]'
api.showDialog('info', 'Witcher 3 Script Merger', {
bbcode: api.translate('Vortex is unable to resolve the Script Merger\'s location. The tool needs to be downloaded and configured manually. '
+ '[url=https://wiki.nexusmods.com/index.php/Tool_Setup:_Witcher_3_Script_Merger]Find out more about how to configure it as a tool for use in Vortex.[/url][br][/br][br][/br]'
+ 'Note: While script merging works well with the vast majority of mods, there is no guarantee for a satisfying outcome in every single case.', { ns: I18N_NAMESPACE }),
}, [
{ label: 'Cancel', action: () => {
Expand All @@ -482,14 +481,16 @@ function prepareForModding(context, discovery) {
},
],
});
}

function prepareForModding(context, discovery) {
const defaultWSMFilePath = path.join(discovery.path, 'WitcherScriptMerger', 'WitcherScriptMerger.exe');
const scriptMergerPath = util.getSafe(discovery, ['tools', SCRIPT_MERGER_ID, 'path'], defaultWSMFilePath);

const findScriptMerger = (error) => {
log('error', 'failed to download/install script merger', error);
return fs.statAsync(scriptMergerPath)
.catch(() => missingScriptMerger())
.catch(() => notifyMissingScriptMerger(context.api))
};

const ensurePath = (dirpath) =>
Expand Down Expand Up @@ -525,8 +526,8 @@ function getScriptMergerTool(api) {
function runScriptMerger(api) {
const tool = getScriptMergerTool(api);
if (tool?.path === undefined) {
const error = new util.SetupError('Witcher Script Merger is not configured correctly');
api.showErrorNotification('Failed to run tool', error, { allowReport: false });
notifyMissingScriptMerger(api);
return Promise.resolve();
}

return api.runExecutable(tool.path, [], { suggestDeploy: true })
Expand Down Expand Up @@ -898,8 +899,8 @@ function infoComponent(context, props) {

function queryScriptMerge(context, reason) {
const state = context.api.store.getState();
const hasW3MergeScript = util.getSafe(state, ['settings', 'gameMode', 'discovered', GAME_ID, 'tools', SCRIPT_MERGER_ID], undefined);
if (!!hasW3MergeScript && !!hasW3MergeScript.path) {
const scriptMergerTool = util.getSafe(state, ['settings', 'gameMode', 'discovered', GAME_ID, 'tools', SCRIPT_MERGER_ID], undefined);
if (!!scriptMergerTool?.path) {
context.api.sendNotification({
id: 'witcher3-merge',
type: 'warning',
Expand All @@ -926,6 +927,8 @@ function queryScriptMerge(context, reason) {
}
],
});
} else {
notifyMissingScriptMerger(context.api);
}
}

Expand Down Expand Up @@ -1283,7 +1286,7 @@ function main(context) {
return Promise.resolve();
}

if (prevDeployment !== deployment) {
if (JSON.stringify(prevDeployment) !== JSON.stringify(deployment)) {
prevDeployment = deployment;
queryScriptMerge(context, 'Your mods state/load order has changed since the last time you ran '
+ 'the script merger. You may want to run the merger tool and check whether any new script conflicts are '
Expand Down
2 changes: 1 addition & 1 deletion game-witcher3/info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Game: The Witcher 3",
"author": "Black Tree Gaming Ltd.",
"version": "1.2.6",
"version": "1.2.7",
"description": "Support for The Witcher 3"
}

0 comments on commit d5e22bb

Please sign in to comment.