Skip to content

Commit

Permalink
await finish dialog when preset-installing collection
Browse files Browse the repository at this point in the history
also load preset files in a predictable order but in practice this will be the same order that it would have been "implicitly" anyway
  • Loading branch information
TanninOne committed Sep 8, 2022
1 parent 75764fd commit 6e46855
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
27 changes: 24 additions & 3 deletions src/extensions/download_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ function init(context: IExtensionContextExt): boolean {
removeDownloadsWithoutFile(store, downloads);

processCommandline(context.api);

presetManager.on('installmod', (stepIn: IPresetStep) => {
const step = stepIn as IPresetStepInstallMod;
log('info', 'preset starting download', { url: step.url });
Expand All @@ -1090,11 +1091,27 @@ function init(context: IExtensionContextExt): boolean {
}
};
context.api.events.on('did-install-dependencies', callback);
}
};

const onDidInstallCollection = (dlId: string, cb: () => void) => {
const callback = (gameId: string, modId: string) => {
const installedDLId =
context.api.getState().persistent.mods[gameId]?.[modId]?.archiveId;
if (installedDLId === dlId) {
context.api.events.off('did-install-collection', callback);
cb();
}
};
context.api.events.on('did-install-collection', callback);
};

let isCollection: boolean = false;

try {
const urlParsed = new NXMUrl(step.url);
if (urlParsed.collectionSlug !== undefined) {
isCollection = true;

const state = context.api.getState();
const games = knownGames(state);
const gameId = convertNXMIdReverse(games, urlParsed.gameId);
Expand All @@ -1103,7 +1120,7 @@ function init(context: IExtensionContextExt): boolean {
.find(modId => mods[modId].attributes?.collectionSlug === urlParsed.collectionSlug);
if (existing !== undefined) {
return new Promise((resolve) => {
onDidInstallDependencies(mods[existing].archiveId, resolve);
onDidInstallCollection(mods[existing].archiveId, resolve);
context.api.events.emit('resume-collection', gameId, existing);
});
}
Expand All @@ -1123,7 +1140,11 @@ function init(context: IExtensionContextExt): boolean {
.then((dlId: string) => {
log('info', 'download finished', { dlId });
return new Promise((resolve) => {
onDidInstallDependencies(dlId, resolve);
if (isCollection) {
onDidInstallCollection(dlId, resolve);
} else {
onDidInstallDependencies(dlId, resolve);
}
context.api.events.emit('start-install-download', dlId);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/types/IPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ export interface IPreset {

export interface IPresetsState {
presets: { [presetId: string]: IPresetState };
processing: string;
processing?: string;
}
4 changes: 3 additions & 1 deletion src/util/PresetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class PresetManager {
let presetFiles: string[] = [];

try {
presetFiles = fs.readdirSync(basePath).filter(fileName => path.extname(fileName) === '.json');
presetFiles = fs.readdirSync(basePath)
.filter(fileName => path.extname(fileName) === '.json')
.sort();
} catch (err) {
log((err.code === 'ENOENT') ? 'debug' : 'error', 'no preset files', { basePath, error: err.message });
}
Expand Down
2 changes: 1 addition & 1 deletion src/validationCode/IPreset.validate.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/validationCode/validation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import validateeBCskdwG from "./IPreset.validate";export function validateIPreset(data): any[] {
var res = validateeBCskdwG(data);
return (res === false) ? validateeBCskdwG.prototype.constructor.errors : [];
import validateLnwojjqti from "./IPreset.validate";export function validateIPreset(data): any[] {
var res = validateLnwojjqti(data);
return (res === false) ? validateLnwojjqti.prototype.constructor.errors : [];
}export function validateIPresetsState(data): any[] {
var res = validateeBCskdwG(data);
return (res === false) ? validateeBCskdwG.prototype.constructor.errors : [];
var res = validateLnwojjqti(data);
return (res === false) ? validateLnwojjqti.prototype.constructor.errors : [];
}

0 comments on commit 6e46855

Please sign in to comment.