Skip to content

Commit

Permalink
If the user has install disabled in automation, ask them if they want…
Browse files Browse the repository at this point in the history
… to install or just download
  • Loading branch information
Garethp committed Mar 15, 2021
1 parent 696f009 commit 11938ce
Show file tree
Hide file tree
Showing 6 changed files with 3,961 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules/
dist/
modlist-backup.7z
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
## Changelog

#### Version 0.3.2
* Ask the user if they want to install the mods when they have auto-install disabled in the settings

#### Version 0.3.1
* Cancelling the file selector for creating or restoring backups no longer causes an error (#3)
* Trying to save to an already existing blank text file will no longer cause an error (#5)
Expand Down
4 changes: 2 additions & 2 deletions info.json
@@ -1,6 +1,6 @@
{
"name": "Modlist Backup",
"author": "Garethp",
"version": "0.3.1",
"author": ["Garethp"],
"version": "0.3.2",
"description": "An extension to backup and restore mods"
}
4 changes: 2 additions & 2 deletions package.json
@@ -1,12 +1,12 @@
{
"name": "modlist-backup",
"version": "0.3.1",
"version": "0.3.2",
"description": "An extension to backup and restore mods",
"main": "./dist/index.js",
"repository": "",
"scripts": {
"webpack": "node ./node_modules/webpack/bin/webpack --config webpack.config.js --display-error-details --progress --profile --color",
"bundle7z": "7z a -t7z modlist-backup.7z .\\dist\\index.js .\\dist\\info.json",
"bundle7z": "7z a -t7z modlist-backup.7z ./dist/index.js ./dist/info.json",
"build": "npm run webpack && extractInfo",
"bundle": "npm run build && npm run bundle7z"
},
Expand Down
23 changes: 21 additions & 2 deletions src/index.ts
Expand Up @@ -103,6 +103,10 @@ const init = (context: IExtensionContext) => {

const restoreMods = () => {
const state: IState = api.store.getState();
let shouldInstall = state.settings.automation.install;
const doInstall = "Yes, download and install";
const dontInstall = "No, download only";


// Installed mods with the `mod-update` event requires the user to be a Premium Member internally in Vortex, I think that's because
// this method won't show any ads. Because of this restriction, we're going to run a check now rather than later, to give earlier feedback
Expand All @@ -115,7 +119,7 @@ const init = (context: IExtensionContext) => {
// Ask the user to select their file
api.selectFile({create: false, title: 'Select your backup file to import'})
.then(fileName => {
fs.readFile(path.resolve(fileName), (error, jsonString) => {
fs.readFile(path.resolve(fileName), async (error, jsonString) => {
// We don't want to restore for other games that might be in the modlist but aren't actively being managed
const activeGameId = getActiveGameId(state);

Expand All @@ -124,6 +128,17 @@ const init = (context: IExtensionContext) => {
return;
}

shouldInstall = state.settings.automation.install || await api.showDialog("question", "Automatically install?", {
text: "In your settings, you've disabled automatic installation on download. Would you like to install these mods when they download anyway?"
}, [
{
label: dontInstall,
},
{
label: doInstall
}
]).then(result => result?.action === doInstall)

let mods = JSON.parse(jsonString) as Mod[];

mods = mods
Expand Down Expand Up @@ -153,7 +168,11 @@ const init = (context: IExtensionContext) => {

// `mod-update` is the Vortex internal event that's used for mod updates. Happily, it'll also download and install mods that aren't installed for us
for (const mod of mods) {
api.events.emit('mod-update', mod.game, mod.modId, mod.fileId, mod.source);
if (shouldInstall) {
api.events.emit('mod-update', mod.game, mod.modId, mod.fileId, mod.source);
} else {
api.emitAndAwait('nexus-download', mod.game, mod.modId, mod.fileId);
}
}

api.sendNotification({
Expand Down

0 comments on commit 11938ce

Please sign in to comment.