Skip to content

Commit 25ebc4d

Browse files
committed
Clean up ThunderstoreDownloaderProvider
Remove references to settings and active game from the download provider, as these were mostly used to only access the setting telling whether to ignore the cached mod downloads. Instead pass the settings as a boolean argument. Implement related changes to provider implementation and their callsites. In downloadAndSave, switch to checking the variable for ignoring the cache first, before checking if the mod actually exists on the disk, as this might reduce the number of unnecessary file operations.
1 parent afc6b91 commit 25ebc4d

File tree

5 files changed

+66
-58
lines changed

5 files changed

+66
-58
lines changed

src/components/profiles-modals/ImportProfileModal.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import ZipProvider from "../../providers/generic/zip/ZipProvider";
2525
import ThunderstoreMod from "../../model/ThunderstoreMod";
2626
import ThunderstoreVersion from "../../model/ThunderstoreVersion";
2727
import ManagerInformation from "../../_managerinf/ManagerInformation";
28+
import * as PackageDb from '../../r2mm/manager/PackageDexieStore';
2829
2930
let fs: FsProvider;
3031
@@ -179,8 +180,8 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
179180
const itfPackages: string[] = ror2Itf.packages;
180181
document.addEventListener("created-profile", ((() => {
181182
const packages = itfPackages.map(value => ExportMod.fromFullString(value));
182-
setTimeout(() => {
183-
this.downloadImportedProfileMods(packages);
183+
setTimeout(async () => {
184+
await this.downloadImportedProfileMods(packages);
184185
}, 100);
185186
}) as EventListener), {once: true});
186187
}
@@ -205,8 +206,8 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
205206
}
206207
if (parsed.getMods().length > 0) {
207208
this.isProfileBeingImported = true;
208-
setTimeout(() => {
209-
this.downloadImportedProfileMods(parsed.getMods(), async () => {
209+
setTimeout(async () => {
210+
await this.downloadImportedProfileMods(parsed.getMods(), async () => {
210211
if (files[0].endsWith('.r2z')) {
211212
await this.extractZippedProfileFile(files[0], profileName);
212213
}
@@ -256,11 +257,19 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
256257
}
257258
}
258259
259-
downloadImportedProfileMods(modList: ExportMod[], callback?: () => void) {
260+
async downloadImportedProfileMods(modList: ExportMod[], callback?: () => void) {
261+
const settings = this.$store.getters['settings'];
262+
const ignoreCache = settings.getContext().global.ignoreCache;
263+
const allMods = await PackageDb.getPackagesByNames(
264+
this.$store.state.activeGame.internalFolderName,
265+
modList.map((m) => m.getName())
266+
);
267+
260268
this.percentageImported = 0;
261269
ThunderstoreDownloaderProvider.instance.downloadImportedMods(
262-
this.$store.state.activeGame,
263270
modList,
271+
allMods,
272+
ignoreCache,
264273
this.downloadProgressCallback,
265274
async (comboList: ThunderstoreCombo[]) => {
266275
await this.downloadCompletedCallback(comboList, modList, callback);

src/components/views/DownloadModModal.vue

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,17 @@ let assignId = 0;
152152
return this.$store.getters['profile/activeProfile'];
153153
}
154154
155-
public static async downloadSpecific(game: Game, profile: Profile, combo: ThunderstoreCombo, thunderstorePackages: ThunderstoreMod[]): Promise<void> {
155+
get ignoreCache(): boolean {
156+
const settings = this.$store.getters['settings'];
157+
return settings.getContext().global.ignoreCache;
158+
}
159+
160+
public static async downloadSpecific(
161+
profile: Profile,
162+
combo: ThunderstoreCombo,
163+
thunderstorePackages: ThunderstoreMod[],
164+
ignoreCache: boolean
165+
): Promise<void> {
156166
return new Promise((resolve, reject) => {
157167
const tsMod = combo.getMod();
158168
const tsVersion = combo.getVersion();
@@ -166,7 +176,7 @@ let assignId = 0;
166176
};
167177
DownloadModModal.allVersions.push([currentAssignId, progressObject]);
168178
setTimeout(() => {
169-
ThunderstoreDownloaderProvider.instance.download(game, profile, tsMod, tsVersion, thunderstorePackages, (progress: number, modName: string, status: number, err: R2Error | null) => {
179+
ThunderstoreDownloaderProvider.instance.download(profile, tsMod, tsVersion, thunderstorePackages, ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
170180
const assignIndex = DownloadModModal.allVersions.findIndex(([number, val]) => number === currentAssignId);
171181
if (status === StatusEnum.FAILURE) {
172182
if (err !== null) {
@@ -280,7 +290,7 @@ let assignId = 0;
280290
}
281291
282292
// TODO: rethink how this method and provider's downloadLatestOfAll()
283-
// access the active game, local mod list and TS mod list.
293+
// access the local mod list and TS mod list.
284294
async downloadLatest() {
285295
this.closeModal();
286296
const modsWithUpdates: ThunderstoreCombo[] = this.$store.getters['profile/modsWithUpdates'];
@@ -295,7 +305,7 @@ let assignId = 0;
295305
this.downloadObject = progressObject;
296306
DownloadModModal.allVersions.push([currentAssignId, this.downloadObject]);
297307
this.downloadingMod = true;
298-
ThunderstoreDownloaderProvider.instance.downloadLatestOfAll(this.activeGame, modsWithUpdates, this.thunderstorePackages, (progress: number, modName: string, status: number, err: R2Error | null) => {
308+
ThunderstoreDownloaderProvider.instance.downloadLatestOfAll(modsWithUpdates, this.thunderstorePackages, this.ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
299309
const assignIndex = DownloadModModal.allVersions.findIndex(([number, val]) => number === currentAssignId);
300310
if (status === StatusEnum.FAILURE) {
301311
if (err !== null) {
@@ -337,7 +347,7 @@ let assignId = 0;
337347
DownloadModModal.allVersions.push([currentAssignId, this.downloadObject]);
338348
this.downloadingMod = true;
339349
setTimeout(() => {
340-
ThunderstoreDownloaderProvider.instance.download(this.activeGame, this.profile, tsMod, tsVersion, this.thunderstorePackages, (progress: number, modName: string, status: number, err: R2Error | null) => {
350+
ThunderstoreDownloaderProvider.instance.download(this.profile, tsMod, tsVersion, this.thunderstorePackages, this.ignoreCache, (progress: number, modName: string, status: number, err: R2Error | null) => {
341351
const assignIndex = DownloadModModal.allVersions.findIndex(([number, val]) => number === currentAssignId);
342352
if (status === StatusEnum.FAILURE) {
343353
if (err !== null) {

src/pages/Manager.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
615615
616616
async created() {
617617
this.launchParametersModel = this.settings.getContext().gameSpecific.launchParameters;
618+
const ignoreCache = this.settings.getContext().global.ignoreCache;
618619
619620
InteractionProvider.instance.hookModInstallProtocol(async data => {
620621
const combo: ThunderstoreCombo | R2Error = ThunderstoreCombo.fromProtocol(data, this.thunderstoreModList);
@@ -625,7 +626,7 @@ import CategoryFilterModal from '../components/modals/CategoryFilterModal.vue';
625626
});
626627
return;
627628
}
628-
DownloadModModal.downloadSpecific(this.activeGame, this.profile, combo, this.thunderstoreModList)
629+
DownloadModModal.downloadSpecific(this.profile, combo, this.thunderstoreModList, ignoreCache)
629630
.then(async value => {
630631
const modList = await ProfileModList.getModList(this.profile);
631632
if (!(modList instanceof R2Error)) {

src/providers/ror2/downloading/ThunderstoreDownloaderProvider.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import ProviderUtils from '../../generic/ProviderUtils';
22
import ThunderstoreVersion from '../../../model/ThunderstoreVersion';
33
import ThunderstoreMod from '../../../model/ThunderstoreMod';
44
import ThunderstoreCombo from '../../../model/ThunderstoreCombo';
5-
import ManifestV2 from '../../../model/ManifestV2';
65
import R2Error from '../../../model/errors/R2Error';
76
import ExportMod from '../../../model/exports/ExportMod';
8-
import ManagerSettings from '../../../r2mm/manager/ManagerSettings';
9-
import Game from '../../../model/game/Game';
107
import Profile from '../../../model/Profile';
118

129
export default abstract class ThunderstoreDownloaderProvider {
@@ -48,39 +45,40 @@ export default abstract class ThunderstoreDownloaderProvider {
4845
/**
4946
* A top-level method to download the latest version of all mods passed in, including their dependencies.
5047
*
51-
* @param game Currently selected game
5248
* @param modsWithUpdate An array of ThunderstoreCombo objects to be updated.
5349
* @param allMods An array of all mods available from the Thunderstore API.
50+
* @param ignoreCache Download mod even if it already exists in the cache.
5451
* @param callback Callback to show the current state of the downloads.
5552
* @param completedCallback Callback to perform final actions against. Only called if {@param callback} has not returned a failed status.
5653
*/
57-
public abstract downloadLatestOfAll(game: Game, modsWithUpdate: ThunderstoreCombo[], allMods: ThunderstoreMod[],
54+
public abstract downloadLatestOfAll(modsWithUpdate: ThunderstoreCombo[], allMods: ThunderstoreMod[], ignoreCache: boolean,
5855
callback: (progress: number, modName: string, status: number, err: R2Error | null) => void,
5956
completedCallback: (modList: ThunderstoreCombo[]) => void): void;
6057

6158
/**
6259
* A top-level method to download the latest version of a mod including its dependencies.
6360
*
64-
* @param game Currently selected game
6561
* @param mod The mod to be downloaded.
6662
* @param modVersion The version of the mod to download.
6763
* @param allMods An array of all mods available from the Thunderstore API.
64+
* @param ignoreCache Download mod even if it already exists in the cache.
6865
* @param callback Callback to show the current state of the downloads.
6966
* @param completedCallback Callback to perform final actions against. Only called if {@param callback} has not returned a failed status.
7067
*/
71-
public abstract download(game: Game, profile: Profile, mod: ThunderstoreMod, modVersion: ThunderstoreVersion, allMods: ThunderstoreMod[],
68+
public abstract download(profile: Profile, mod: ThunderstoreMod, modVersion: ThunderstoreVersion, allMods: ThunderstoreMod[], ignoreCache: boolean,
7269
callback: (progress: number, modName: string, status: number, err: R2Error | null) => void,
7370
completedCallback: (modList: ThunderstoreCombo[]) => void): void;
7471

7572
/**
7673
* A top-level method to download exact versions of exported mods.
7774
*
78-
* @param game Currently selected game
7975
* @param modList An array of {@class ExportMod} mods to download.
76+
* @param allMods An array of all mods available from the Thunderstore API.
77+
* @param ignoreCache Download mod even if it already exists in the cache.
8078
* @param callback See {@method download}.
8179
* @param completedCallback See {@method download}
8280
*/
83-
public abstract downloadImportedMods(game: Game, modList: ExportMod[],
81+
public abstract downloadImportedMods(modList: ExportMod[], allMods: ThunderstoreMod[], ignoreCache: boolean,
8482
callback: (progress: number, modName: string, status: number, err: R2Error | null) => void,
8583
completedCallback: (mods: ThunderstoreCombo[]) => void): void;
8684

@@ -97,28 +95,27 @@ export default abstract class ThunderstoreDownloaderProvider {
9795
* Iterate the {@class ThunderstoreCombo} array to perform the download for each mod.
9896
* Progress to the next one recursively once the callback received has been successful.
9997
*
100-
* @param settings Instance of ManagerSettings.
101-
* @param entries IterableIterator of entries for {@class ThunderstoreCombo} mods to download.
102-
* @param callback See {@method download}
98+
* @param entries IterableIterator of entries for {@class ThunderstoreCombo} mods to download.
99+
* @param ignoreCache Should mod be downloaded even if it already exists in the cache?
100+
* @param callback See {@method download}
103101
*/
104-
public abstract queueDownloadDependencies(settings: ManagerSettings, entries: IterableIterator<[number, ThunderstoreCombo]>, callback: (progress: number, modName: string, status: number, err: R2Error | null) => void): void
102+
public abstract queueDownloadDependencies(entries: IterableIterator<[number, ThunderstoreCombo]>, ignoreCache: boolean, callback: (progress: number, modName: string, status: number, err: R2Error | null) => void): void
105103

106104
/**
107105
* Generate the total count of mods to be downloaded. Cached mods are not included in this count unless download cache is disabled.
108106
*
109-
* @param settings Instance of ManagerSettings.
110107
* @param list List of mods generated by a dependency building method including the primary mod to be downloaded.
111108
*/
112-
public abstract calculateInitialDownloadSize(settings: ManagerSettings, list: ThunderstoreCombo[]): number;
109+
public abstract calculateInitialDownloadSize(list: ThunderstoreCombo[]): number;
113110

114111
/**
115112
* Perform the download of the given {@class ThunderstoreCombo}.
116113
*
117-
* @param combo The current mod to download.
118-
* @param settings Instance of ManagerSettings.
119-
* @param callback See {@method download}
114+
* @param combo The current mod to download.
115+
* @param ignoreCache Should mod be downloaded even if it already exists in the cache?
116+
* @param callback See {@method download}
120117
*/
121-
public abstract downloadAndSave(combo: ThunderstoreCombo, settings: ManagerSettings, callback: (progress: number, status: number, err: R2Error | null) => void): void;
118+
public abstract downloadAndSave(combo: ThunderstoreCombo, ignoreCache: boolean, callback: (progress: number, status: number, err: R2Error | null) => void): void;
122119

123120
/**
124121
* Save the download buffer to a zip file in the cache.

0 commit comments

Comments
 (0)