Skip to content

Commit 9eec207

Browse files
authored
Merge pull request #1474 from ebkr/immutable-profile-pt4-downloadprovider
Refactor download method of download provider to use ImmutableProfile
2 parents ffe8f09 + 46913e0 commit 9eec207

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/components/views/DownloadModModal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ let assignId = 0;
166166
};
167167
DownloadModModal.allVersions.push([currentAssignId, progressObject]);
168168
setTimeout(() => {
169-
ThunderstoreDownloaderProvider.instance.download(profile, tsMod, tsVersion, thunderstorePackages, ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
169+
ThunderstoreDownloaderProvider.instance.download(profile.asImmutableProfile(), tsMod, tsVersion, thunderstorePackages, ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
170170
const assignIndex = DownloadModModal.allVersions.findIndex(([number, val]) => number === currentAssignId);
171171
if (status === StatusEnum.FAILURE) {
172172
if (err !== null) {
@@ -337,7 +337,7 @@ let assignId = 0;
337337
DownloadModModal.allVersions.push([currentAssignId, this.downloadObject]);
338338
this.downloadingMod = true;
339339
setTimeout(() => {
340-
ThunderstoreDownloaderProvider.instance.download(this.profile, tsMod, tsVersion, this.thunderstorePackages, this.ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
340+
ThunderstoreDownloaderProvider.instance.download(this.profile.asImmutableProfile(), tsMod, tsVersion, this.thunderstorePackages, this.ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
341341
const assignIndex = DownloadModModal.allVersions.findIndex(([number, val]) => number === currentAssignId);
342342
if (status === StatusEnum.FAILURE) {
343343
if (err !== null) {

src/providers/ror2/downloading/ThunderstoreDownloaderProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ThunderstoreMod from '../../../model/ThunderstoreMod';
44
import ThunderstoreCombo from '../../../model/ThunderstoreCombo';
55
import R2Error from '../../../model/errors/R2Error';
66
import ExportMod from '../../../model/exports/ExportMod';
7-
import Profile from '../../../model/Profile';
7+
import Profile, { ImmutableProfile } from '../../../model/Profile';
88

99
export default abstract class ThunderstoreDownloaderProvider {
1010

@@ -58,14 +58,16 @@ export default abstract class ThunderstoreDownloaderProvider {
5858
/**
5959
* A top-level method to download the latest version of a mod including its dependencies.
6060
*
61+
* @param profile The profile the mod is downloaded for (needed to prevent dependencies from updating existing mods).
6162
* @param mod The mod to be downloaded.
6263
* @param modVersion The version of the mod to download.
6364
* @param allMods An array of all mods available from the Thunderstore API.
6465
* @param ignoreCache Download mod even if it already exists in the cache.
6566
* @param callback Callback to show the current state of the downloads.
6667
* @param completedCallback Callback to perform final actions against. Only called if {@param callback} has not returned a failed status.
6768
*/
68-
public abstract download(profile: Profile, mod: ThunderstoreMod, modVersion: ThunderstoreVersion, allMods: ThunderstoreMod[], ignoreCache: boolean,
69+
public abstract download(profile: ImmutableProfile, mod: ThunderstoreMod, modVersion: ThunderstoreVersion,
70+
allMods: ThunderstoreMod[], ignoreCache: boolean,
6971
callback: (progress: number, modName: string, status: number, err: R2Error | null) => void,
7072
completedCallback: (modList: ThunderstoreCombo[]) => void): void;
7173

src/r2mm/downloading/BetterThunderstoreDownloader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import PathResolver from '../../r2mm/manager/PathResolver';
1010
import * as path from 'path';
1111
import FsProvider from '../../providers/generic/file/FsProvider';
1212
import FileWriteError from '../../model/errors/FileWriteError';
13-
import Profile from '../../model/Profile';
13+
import { ImmutableProfile } from '../../model/Profile';
1414
import ExportMod from '../../model/exports/ExportMod';
1515
import ThunderstoreDownloaderProvider from '../../providers/ror2/downloading/ThunderstoreDownloaderProvider';
1616
import ManagerInformation from '../../_managerinf/ManagerInformation';
@@ -117,7 +117,7 @@ export default class BetterThunderstoreDownloader extends ThunderstoreDownloader
117117
});
118118
}
119119

120-
public async download(profile: Profile, mod: ThunderstoreMod, modVersion: ThunderstoreVersion,
120+
public async download(profile: ImmutableProfile, mod: ThunderstoreMod, modVersion: ThunderstoreVersion,
121121
allMods: ThunderstoreMod[], ignoreCache: boolean,
122122
callback: (progress: number, modName: string, status: number, err: R2Error | null) => void,
123123
completedCallback: (modList: ThunderstoreCombo[]) => void) {
@@ -128,7 +128,7 @@ export default class BetterThunderstoreDownloader extends ThunderstoreDownloader
128128
combo.setVersion(modVersion);
129129
let downloadCount = 0;
130130

131-
const modList = await ProfileModList.getModList(profile.asImmutableProfile());
131+
const modList = await ProfileModList.getModList(profile);
132132
if (modList instanceof R2Error) {
133133
return callback(0, mod.getName(), StatusEnum.FAILURE, modList);
134134
}

0 commit comments

Comments
 (0)