Skip to content

Commit

Permalink
new option to force download to install programmatically
Browse files Browse the repository at this point in the history
once the download is complete of course
  • Loading branch information
TanninOne committed Sep 8, 2022
1 parent 10f235a commit 75764fd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/extensions/download_management/DownloadObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function progressUpdate(store: Redux.Store<any>, dlId: string, received: number,

export interface IStartDownloadOptions {
// whether the download may be auto-installed if the user has that set up for mods (default: true)
allowInstall?: boolean;
// if set to 'force', the download will be installed independent of the user config
allowInstall?: boolean | 'force';
// whether the url should be opened in the embedded browser if it's html (default: true)
allowOpenHTML?: boolean;
}
Expand Down Expand Up @@ -300,7 +301,7 @@ export class DownloadObserver {
private handleDownloadFinished(id: string,
callback: (error: Error, id: string) => void,
res: IDownloadResult,
allowInstall: boolean) {
allowInstall: boolean | 'force') {
const download = this.mApi.getState().persistent.downloads.files?.[id];
if (download === undefined) {
// The only way for the download entry to be missing at this point
Expand Down Expand Up @@ -337,14 +338,15 @@ export class DownloadObserver {
callback?.(new Error('html result'), id);
return onceFinished();
} else {
return finalizeDownload(this.mApi, id, res.filePath, allowInstall)
return finalizeDownload(this.mApi, id, res.filePath)
.then(() => {
const flattened = flatten(res.metaInfo ?? {});
Object.keys(flattened).forEach(key =>
this.mApi.store.dispatch(setDownloadModInfo(id, key, flattened[key])));

const state = this.mApi.getState();
if ((state.settings.automation?.install && allowInstall)
if ((state.settings.automation?.install && (allowInstall === true))
|| (allowInstall === 'force')
|| (download.modInfo?.['startedAsUpdate'] === true)) {
this.mApi.events.emit('start-install-download', id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/download_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ function checkForUnfinalized(api: IExtensionApi,
const downloadPath = selectors.downloadPathForGame(api.getState(), gameId);
const filePath = path.join(downloadPath, downloads[id].localPath);
if (downloads[id].state === 'finalizing') {
return finalizeDownload(api, id, filePath, false)
return finalizeDownload(api, id, filePath)
.catch(err => {
log('warn', 'failed to properly finalize download', {
fileName: downloads[id].localPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function fileMD5Async(filePath: string,
}

export function finalizeDownload(api: IExtensionApi, id: string,
filePath: string, allowInstall: boolean) {
filePath: string) {
api.store.dispatch(finalizingDownload(id));

let lastProgress: number = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/extensions/nexus_integration/eventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,12 @@ export function onNexusDownload(api: IExtensionApi,
}

export function onGetMyCollections(api: IExtensionApi, nexus: Nexus)
: (gameId: string, count?: number, offset?: number) => Promise<ICollection[]> {
return (gameId: string, count?: number, offset?: number): Promise<ICollection[]> => {
: (gameId: string, count?: number, offset?: number) => Promise<IRevision[]> {
return (gameId: string, count?: number, offset?: number): Promise<IRevision[]> => {
const game = gameById(api.getState(), gameId);
return Promise.resolve(nexus.getMyCollections(
CURRENT_REVISION_INFO, nexusGameId(game), count, offset))
.then(res => res.map(coll => coll.currentRevision))
.catch(err => {
api.showErrorNotification('Failed to get list of collections', err);
return Promise.resolve(undefined);
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/nexus_integration/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export function getCollectionInfo(nexus: Nexus,
},
};

if (revisionNumber <= 1) {
if (revisionNumber <= 0) {
revisionNumber = undefined;
}

Expand Down

0 comments on commit 75764fd

Please sign in to comment.