From cc27ecb2d7481c4ba3110f8c028921849d21c926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Mon, 30 Sep 2024 15:42:55 +0300 Subject: [PATCH 1/9] Refactor ProfileModList.getModList to use ImmutableProfile To prevent mega commit, call sites still use Profile for now. --- .../importing/LocalFileImportModal.vue | 2 +- src/components/views/DownloadModModal.vue | 8 +++---- src/pages/Manager.vue | 2 +- .../BetterThunderstoreDownloader.ts | 2 +- src/r2mm/mods/CacheUtil.ts | 2 +- src/r2mm/mods/ProfileModList.ts | 24 +++++++++---------- src/store/modules/ProfileModule.ts | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/components/importing/LocalFileImportModal.vue b/src/components/importing/LocalFileImportModal.vue index 1693cda53..ca56ca90a 100644 --- a/src/components/importing/LocalFileImportModal.vue +++ b/src/components/importing/LocalFileImportModal.vue @@ -297,7 +297,7 @@ export default class LocalFileImportModal extends Vue { this.$store.commit("error/handleError", R2Error.fromThrownValue(error)); return; } - const updatedModListResult = await ProfileModList.getModList(profile); + const updatedModListResult = await ProfileModList.getModList(profile.asImmutableProfile()); if (updatedModListResult instanceof R2Error) { this.$store.commit("error/handleError", updatedModListResult); return; diff --git a/src/components/views/DownloadModModal.vue b/src/components/views/DownloadModModal.vue index 6fa1f86e6..7f78017ae 100644 --- a/src/components/views/DownloadModModal.vue +++ b/src/components/views/DownloadModModal.vue @@ -197,7 +197,7 @@ let assignId = 0; ); } } - const modList = await ProfileModList.getModList(profile); + const modList = await ProfileModList.getModList(profile.asImmutableProfile()); if (!(modList instanceof R2Error)) { const err = await ConflictManagementProvider.instance.resolveConflicts(modList, profile); if (err instanceof R2Error) { @@ -250,7 +250,7 @@ let assignId = 0; } } - const modListResult = await ProfileModList.getModList(this.profile); + const modListResult = await ProfileModList.getModList(this.profile.asImmutableProfile()); if (!(modListResult instanceof R2Error)) { const manifestMod = modListResult.find((local: ManifestV2) => local.getName() === this.thunderstoreMod!.getFullName()); if (manifestMod !== undefined) { @@ -379,7 +379,7 @@ let assignId = 0; } } this.downloadingMod = false; - const modList = await ProfileModList.getModList(this.profile); + const modList = await ProfileModList.getModList(this.profile.asImmutableProfile()); if (!(modList instanceof R2Error)) { await this.$store.dispatch('profile/updateModList', modList); const err = await ConflictManagementProvider.instance.resolveConflicts(modList, this.profile); @@ -393,7 +393,7 @@ let assignId = 0; static async installModAfterDownload(profile: Profile, mod: ThunderstoreMod, version: ThunderstoreVersion): Promise { return new Promise(async (resolve, reject) => { const manifestMod: ManifestV2 = new ManifestV2().fromThunderstoreMod(mod, version); - const profileModList = await ProfileModList.getModList(profile); + const profileModList = await ProfileModList.getModList(profile.asImmutableProfile()); if (profileModList instanceof R2Error) { return reject(profileModList); } diff --git a/src/pages/Manager.vue b/src/pages/Manager.vue index 163afc747..8a4f863ca 100644 --- a/src/pages/Manager.vue +++ b/src/pages/Manager.vue @@ -630,7 +630,7 @@ import ModalCard from '../components/ModalCard.vue'; } DownloadModModal.downloadSpecific(this.profile, combo, this.thunderstoreModList, ignoreCache) .then(async value => { - const modList = await ProfileModList.getModList(this.profile); + const modList = await ProfileModList.getModList(this.profile.asImmutableProfile()); if (!(modList instanceof R2Error)) { await this.$store.dispatch('profile/updateModList', modList); } else { diff --git a/src/r2mm/downloading/BetterThunderstoreDownloader.ts b/src/r2mm/downloading/BetterThunderstoreDownloader.ts index 1a943a3e8..84fcc36dc 100644 --- a/src/r2mm/downloading/BetterThunderstoreDownloader.ts +++ b/src/r2mm/downloading/BetterThunderstoreDownloader.ts @@ -128,7 +128,7 @@ export default class BetterThunderstoreDownloader extends ThunderstoreDownloader combo.setVersion(modVersion); let downloadCount = 0; - const modList = await ProfileModList.getModList(profile); + const modList = await ProfileModList.getModList(profile.asImmutableProfile()); if (modList instanceof R2Error) { return callback(0, mod.getName(), StatusEnum.FAILURE, modList); } diff --git a/src/r2mm/mods/CacheUtil.ts b/src/r2mm/mods/CacheUtil.ts index 686cd1da6..c17d392cf 100644 --- a/src/r2mm/mods/CacheUtil.ts +++ b/src/r2mm/mods/CacheUtil.ts @@ -27,7 +27,7 @@ export default class CacheUtil { const activeModSet = new Set(); for (const value of profiles) { const profile = new Profile(value); - const modList = await ProfileModList.getModList(profile); + const modList = await ProfileModList.getModList(profile.asImmutableProfile()); if (modList instanceof R2Error) { continue; } diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index 3d85b55a7..aeef180dd 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -1,5 +1,5 @@ import * as yaml from 'yaml'; -import Profile from '../../model/Profile'; +import Profile, { ImmutableProfile } from '../../model/Profile'; import * as path from 'path'; import FsProvider from '../../providers/generic/file/FsProvider'; @@ -35,7 +35,7 @@ export default class ProfileModList { return this.lock.acquire("acquire", fn); } - public static async getModList(profile: Profile): Promise { + public static async getModList(profile: ImmutableProfile): Promise { const fs = FsProvider.instance; await FileUtils.ensureDirectory(profile.getProfilePath()); if (!await fs.exists(profile.joinToProfilePath('mods.yml'))) { @@ -114,13 +114,13 @@ export default class ProfileModList { public static async addMod(mod: ManifestV2, profile: Profile): Promise { mod.setInstalledAtTime(Number(new Date())); // Set InstalledAt to current epoch millis - let currentModList: ManifestV2[] | R2Error = await this.getModList(profile); + let currentModList: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); if (currentModList instanceof R2Error) { currentModList = []; } const modIndex: number = currentModList.findIndex((search: ManifestV2) => search.getName() === mod.getName()); await this.removeMod(mod, profile); - currentModList = await this.getModList(profile); + currentModList = await this.getModList(profile.asImmutableProfile()); if (currentModList instanceof R2Error) { currentModList = []; } @@ -134,11 +134,11 @@ export default class ProfileModList { if (saveError !== null) { return saveError; } - return this.getModList(profile); + return this.getModList(profile.asImmutableProfile()); } public static async removeMod(mod: ManifestV2, profile: Profile): Promise { - const currentModList: ManifestV2[] | R2Error = await this.getModList(profile); + const currentModList: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); if (currentModList instanceof R2Error) { return currentModList; } @@ -148,11 +148,11 @@ export default class ProfileModList { return saveError; } // Return mod list, or R2 error. We don't care at this point. - return this.getModList(profile); + return this.getModList(profile.asImmutableProfile()); } public static async updateMods(mods: ManifestV2[], profile: Profile, apply: (mod: ManifestV2) => void): Promise { - const list: ManifestV2[] | R2Error = await this.getModList(profile); + const list: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); if (list instanceof R2Error) { return list; } @@ -166,11 +166,11 @@ export default class ProfileModList { if (saveErr instanceof R2Error) { return saveErr; } - return this.getModList(profile); + return this.getModList(profile.asImmutableProfile()); } public static async updateMod(mod: ManifestV2, profile: Profile, apply: (mod: ManifestV2) => Promise): Promise { - const list: ManifestV2[] | R2Error = await this.getModList(profile); + const list: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); if (list instanceof R2Error) { return list; } @@ -181,11 +181,11 @@ export default class ProfileModList { if (saveErr instanceof R2Error) { return saveErr; } - return this.getModList(profile); + return this.getModList(profile.asImmutableProfile()); } private static async createExport(profile: Profile): Promise { - const list: ManifestV2[] | R2Error = await this.getModList(profile); + const list: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); if (list instanceof R2Error) { return list; } diff --git a/src/store/modules/ProfileModule.ts b/src/store/modules/ProfileModule.ts index 724e3975e..53008379c 100644 --- a/src/store/modules/ProfileModule.ts +++ b/src/store/modules/ProfileModule.ts @@ -352,7 +352,7 @@ export default { return; } - const modList = await ProfileModList.getModList(state.activeProfile); + const modList = await ProfileModList.getModList(state.activeProfile.asImmutableProfile()); if (!(modList instanceof R2Error)) { await dispatch('updateModList', modList); @@ -433,7 +433,7 @@ export default { /*** Read profiles mod list from mods.yml in profile directory. */ async updateModListFromFile({dispatch, getters}) { const profile: Profile = getters['activeProfile']; - const mods = await ProfileModList.getModList(profile); + const mods = await ProfileModList.getModList(profile.asImmutableProfile()); if (mods instanceof R2Error) { throw mods; From 152024d4cf9b6af6fa611106e37c709277a1cb35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Mon, 30 Sep 2024 15:55:51 +0300 Subject: [PATCH 2/9] Refactor ProfileModList.saveModList to use ImmutableProfile --- src/components/views/LocalModList.vue | 6 +++--- src/r2mm/mods/ProfileModList.ts | 10 +++++----- src/store/modules/ProfileModule.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/views/LocalModList.vue b/src/components/views/LocalModList.vue index 7a56e47e3..062b3aafc 100644 --- a/src/components/views/LocalModList.vue +++ b/src/components/views/LocalModList.vue @@ -28,7 +28,7 @@ import Draggable from 'vuedraggable'; import { Component, Vue } from 'vue-property-decorator'; import ManifestV2 from '../../model/ManifestV2'; import R2Error from '../../model/errors/R2Error'; -import Profile from '../../model/Profile'; +import { ImmutableProfile } from '../../model/Profile'; import AssociatedModsModal from './LocalModList/AssociatedModsModal.vue'; import DisableModModal from './LocalModList/DisableModModal.vue'; import UninstallModModal from './LocalModList/UninstallModModal.vue'; @@ -46,8 +46,8 @@ import SearchAndSort from './LocalModList/SearchAndSort.vue'; } }) export default class LocalModList extends Vue { - get profile(): Profile { - return this.$store.getters['profile/activeProfile']; + get profile(): ImmutableProfile { + return this.$store.getters['profile/activeProfile'].asImmutableProfile(); } get draggableList(): ManifestV2[] { diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index aeef180dd..62e21b9a8 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -84,7 +84,7 @@ export default class ProfileModList { } } - public static async saveModList(profile: Profile, modList: ManifestV2[]): Promise { + public static async saveModList(profile: ImmutableProfile, modList: ManifestV2[]): Promise { const fs = FsProvider.instance; try { const yamlModList: string = yaml.stringify(modList); @@ -130,7 +130,7 @@ export default class ProfileModList { } else { currentModList.push(mod); } - const saveError: R2Error | null = await this.saveModList(profile, currentModList); + const saveError: R2Error | null = await this.saveModList(profile.asImmutableProfile(), currentModList); if (saveError !== null) { return saveError; } @@ -143,7 +143,7 @@ export default class ProfileModList { return currentModList; } const newModList = currentModList.filter((m: ManifestV2) => m.getName() !== mod.getName()); - const saveError: R2Error | null = await this.saveModList(profile, newModList); + const saveError: R2Error | null = await this.saveModList(profile.asImmutableProfile(), newModList); if (saveError !== null) { return saveError; } @@ -162,7 +162,7 @@ export default class ProfileModList { apply(filteringMod); }); } - const saveErr = await this.saveModList(profile, list); + const saveErr = await this.saveModList(profile.asImmutableProfile(), list); if (saveErr instanceof R2Error) { return saveErr; } @@ -177,7 +177,7 @@ export default class ProfileModList { for (const modToApply of list.filter((filteringMod: ManifestV2) => filteringMod.getName() === mod.getName())) { await apply(modToApply); } - const saveErr = await this.saveModList(profile, list); + const saveErr = await this.saveModList(profile.asImmutableProfile(), list); if (saveErr instanceof R2Error) { return saveErr; } diff --git a/src/store/modules/ProfileModule.ts b/src/store/modules/ProfileModule.ts index 53008379c..acd74815e 100644 --- a/src/store/modules/ProfileModule.ts +++ b/src/store/modules/ProfileModule.ts @@ -3,7 +3,7 @@ import { ActionTree, GetterTree } from 'vuex'; import { State as RootState } from '../index'; import R2Error from '../../model/errors/R2Error'; import ManifestV2 from '../../model/ManifestV2'; -import Profile from "../../model/Profile"; +import Profile, { ImmutableProfile } from "../../model/Profile"; import { SortDirection } from '../../model/real_enums/sort/SortDirection'; import { SortLocalDisabledMods } from '../../model/real_enums/sort/SortLocalDisabledMods'; import { SortNaming } from '../../model/real_enums/sort/SortNaming'; @@ -320,7 +320,7 @@ export default { {dispatch, getters}, params: { mods: ManifestV2[], - profile: Profile, + profile: ImmutableProfile, } ) { const {mods, profile} = params; From d0e96b3ad801161fbd85351a25a7c587a428514c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Mon, 30 Sep 2024 16:00:25 +0300 Subject: [PATCH 3/9] Refactor ProfileModList.removeMod to use ImmutableProfile --- src/r2mm/mods/ProfileModList.ts | 10 +++++----- src/store/modules/ProfileModule.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index 62e21b9a8..6eb1e42fb 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -119,7 +119,7 @@ export default class ProfileModList { currentModList = []; } const modIndex: number = currentModList.findIndex((search: ManifestV2) => search.getName() === mod.getName()); - await this.removeMod(mod, profile); + await this.removeMod(mod, profile.asImmutableProfile()); currentModList = await this.getModList(profile.asImmutableProfile()); if (currentModList instanceof R2Error) { currentModList = []; @@ -137,18 +137,18 @@ export default class ProfileModList { return this.getModList(profile.asImmutableProfile()); } - public static async removeMod(mod: ManifestV2, profile: Profile): Promise { - const currentModList: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); + public static async removeMod(mod: ManifestV2, profile: ImmutableProfile): Promise { + const currentModList: ManifestV2[] | R2Error = await this.getModList(profile); if (currentModList instanceof R2Error) { return currentModList; } const newModList = currentModList.filter((m: ManifestV2) => m.getName() !== mod.getName()); - const saveError: R2Error | null = await this.saveModList(profile.asImmutableProfile(), newModList); + const saveError: R2Error | null = await this.saveModList(profile, newModList); if (saveError !== null) { return saveError; } // Return mod list, or R2 error. We don't care at this point. - return this.getModList(profile.asImmutableProfile()); + return this.getModList(profile); } public static async updateMods(mods: ManifestV2[], profile: Profile, apply: (mod: ManifestV2) => void): Promise { diff --git a/src/store/modules/ProfileModule.ts b/src/store/modules/ProfileModule.ts index acd74815e..01314db8d 100644 --- a/src/store/modules/ProfileModule.ts +++ b/src/store/modules/ProfileModule.ts @@ -394,7 +394,7 @@ export default { // Update mod list status to mods.yml. // TODO: can performance be improved by implementing // a .removeMods(mods, profile) and calling it once outside the loop? - const updatedList = await ProfileModList.removeMod(mod, profile); + const updatedList = await ProfileModList.removeMod(mod, profile.asImmutableProfile()); if (updatedList instanceof R2Error) { throw updatedList; } else { From 5c4d4128c238c695be82bee43b52bc47c949efad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Mon, 30 Sep 2024 16:05:04 +0300 Subject: [PATCH 4/9] Refactor ProfileModList.addMod to use ImmutableProfile --- src/components/views/DownloadModModal.vue | 2 +- src/r2mm/installing/LocalModInstaller.ts | 4 ++-- src/r2mm/mods/ProfileModList.ts | 12 ++++++------ src/utils/ProfileUtils.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/views/DownloadModModal.vue b/src/components/views/DownloadModModal.vue index 7f78017ae..937cf787a 100644 --- a/src/components/views/DownloadModModal.vue +++ b/src/components/views/DownloadModModal.vue @@ -413,7 +413,7 @@ let assignId = 0; } const installError: R2Error | null = await ProfileInstallerProvider.instance.installMod(manifestMod, profile); if (!(installError instanceof R2Error)) { - const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile); + const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile.asImmutableProfile()); if (newModList instanceof R2Error) { return reject(newModList); } diff --git a/src/r2mm/installing/LocalModInstaller.ts b/src/r2mm/installing/LocalModInstaller.ts index 450b84d01..1129c0ef6 100644 --- a/src/r2mm/installing/LocalModInstaller.ts +++ b/src/r2mm/installing/LocalModInstaller.ts @@ -66,7 +66,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider { callback(false, profileInstallResult); return Promise.resolve(); } - const modListInstallResult = await ProfileModList.addMod(manifest, profile); + const modListInstallResult = await ProfileModList.addMod(manifest, profile.asImmutableProfile()); if (modListInstallResult instanceof R2Error) { callback(false, modListInstallResult); return Promise.resolve(); @@ -92,7 +92,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider { callback(false, profileInstallResult); return Promise.resolve(); } - const modListInstallResult = await ProfileModList.addMod(manifest, profile); + const modListInstallResult = await ProfileModList.addMod(manifest, profile.asImmutableProfile()); if (modListInstallResult instanceof R2Error) { callback(false, modListInstallResult); return Promise.resolve(); diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index 6eb1e42fb..0c13c5d44 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -112,15 +112,15 @@ export default class ProfileModList { return null; } - public static async addMod(mod: ManifestV2, profile: Profile): Promise { + public static async addMod(mod: ManifestV2, profile: ImmutableProfile): Promise { mod.setInstalledAtTime(Number(new Date())); // Set InstalledAt to current epoch millis - let currentModList: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); + let currentModList: ManifestV2[] | R2Error = await this.getModList(profile); if (currentModList instanceof R2Error) { currentModList = []; } const modIndex: number = currentModList.findIndex((search: ManifestV2) => search.getName() === mod.getName()); - await this.removeMod(mod, profile.asImmutableProfile()); - currentModList = await this.getModList(profile.asImmutableProfile()); + await this.removeMod(mod, profile); + currentModList = await this.getModList(profile); if (currentModList instanceof R2Error) { currentModList = []; } @@ -130,11 +130,11 @@ export default class ProfileModList { } else { currentModList.push(mod); } - const saveError: R2Error | null = await this.saveModList(profile.asImmutableProfile(), currentModList); + const saveError: R2Error | null = await this.saveModList(profile, currentModList); if (saveError !== null) { return saveError; } - return this.getModList(profile.asImmutableProfile()); + return this.getModList(profile); } public static async removeMod(mod: ManifestV2, profile: ImmutableProfile): Promise { diff --git a/src/utils/ProfileUtils.ts b/src/utils/ProfileUtils.ts index 66d74f0fc..9eff9b5f9 100644 --- a/src/utils/ProfileUtils.ts +++ b/src/utils/ProfileUtils.ts @@ -48,7 +48,7 @@ export async function installModAfterDownload(mod: ThunderstoreMod, version: Thu throw installError; } - const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile); + const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile.asImmutableProfile()); if (newModList instanceof R2Error) { throw newModList; } From 3cc8c3ec930691a7254313bb32289768fd5e3bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Tue, 1 Oct 2024 10:40:33 +0300 Subject: [PATCH 5/9] Refactor ProfileModList.updateMods to use ImmutableProfile --- src/r2mm/mods/ProfileModList.ts | 8 ++++---- src/store/modules/ProfileModule.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index 0c13c5d44..da4e2e75a 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -151,8 +151,8 @@ export default class ProfileModList { return this.getModList(profile); } - public static async updateMods(mods: ManifestV2[], profile: Profile, apply: (mod: ManifestV2) => void): Promise { - const list: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); + public static async updateMods(mods: ManifestV2[], profile: ImmutableProfile, apply: (mod: ManifestV2) => void): Promise { + const list: ManifestV2[] | R2Error = await this.getModList(profile); if (list instanceof R2Error) { return list; } @@ -162,11 +162,11 @@ export default class ProfileModList { apply(filteringMod); }); } - const saveErr = await this.saveModList(profile.asImmutableProfile(), list); + const saveErr = await this.saveModList(profile, list); if (saveErr instanceof R2Error) { return saveErr; } - return this.getModList(profile.asImmutableProfile()); + return this.getModList(profile); } public static async updateMod(mod: ManifestV2, profile: Profile, apply: (mod: ManifestV2) => Promise): Promise { diff --git a/src/store/modules/ProfileModule.ts b/src/store/modules/ProfileModule.ts index 01314db8d..740685908 100644 --- a/src/store/modules/ProfileModule.ts +++ b/src/store/modules/ProfileModule.ts @@ -211,7 +211,7 @@ export default { } // Update mod list status to mods.yml. - const updatedList = await ProfileModList.updateMods(mods, profile, (mod) => mod.disable()); + const updatedList = await ProfileModList.updateMods(mods, profile.asImmutableProfile(), (mod) => mod.disable()); if (updatedList instanceof R2Error) { throw updatedList; } else { @@ -266,7 +266,7 @@ export default { } // Update mod list status to mods.yml. - const updatedList = await ProfileModList.updateMods(mods, profile, (mod) => mod.enable()); + const updatedList = await ProfileModList.updateMods(mods, profile.asImmutableProfile(), (mod) => mod.enable()); if (updatedList instanceof R2Error) { throw updatedList; } else { From 88ca5d16946df29d8f7aca28e3cf3d1607ca8e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Tue, 1 Oct 2024 10:43:20 +0300 Subject: [PATCH 6/9] Refactor ProfileModList.updateMod to use ImmutableProfile --- src/components/profiles-modals/ImportProfileModal.vue | 2 +- src/components/views/DownloadModModal.vue | 2 +- src/r2mm/mods/ProfileModList.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/profiles-modals/ImportProfileModal.vue b/src/components/profiles-modals/ImportProfileModal.vue index 4aeb01345..7fca857a2 100644 --- a/src/components/profiles-modals/ImportProfileModal.vue +++ b/src/components/profiles-modals/ImportProfileModal.vue @@ -257,7 +257,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { for (const imported of modList) { if (imported.getName() == comboMod.getMod().getFullName() && !imported.isEnabled()) { - await ProfileModList.updateMod(installedMod, this.activeProfile, async (modToDisable: ManifestV2) => { + await ProfileModList.updateMod(installedMod, this.activeProfile.asImmutableProfile(), async (modToDisable: ManifestV2) => { // Need to enable temporarily so the manager doesn't think it's re-disabling a disabled mod. modToDisable.enable(); await ProfileInstallerProvider.instance.disableMod(modToDisable, this.activeProfile); diff --git a/src/components/views/DownloadModModal.vue b/src/components/views/DownloadModModal.vue index 937cf787a..e6a27d0c3 100644 --- a/src/components/views/DownloadModModal.vue +++ b/src/components/views/DownloadModModal.vue @@ -422,7 +422,7 @@ let assignId = 0; } if (olderInstallOfMod !== undefined) { if (!olderInstallOfMod.isEnabled()) { - await ProfileModList.updateMod(manifestMod, profile, async mod => { + await ProfileModList.updateMod(manifestMod, profile.asImmutableProfile(), async mod => { mod.disable(); }); await ProfileInstallerProvider.instance.disableMod(manifestMod, profile); diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index da4e2e75a..6feb2d1e9 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -169,19 +169,19 @@ export default class ProfileModList { return this.getModList(profile); } - public static async updateMod(mod: ManifestV2, profile: Profile, apply: (mod: ManifestV2) => Promise): Promise { - const list: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); + public static async updateMod(mod: ManifestV2, profile: ImmutableProfile, apply: (mod: ManifestV2) => Promise): Promise { + const list: ManifestV2[] | R2Error = await this.getModList(profile); if (list instanceof R2Error) { return list; } for (const modToApply of list.filter((filteringMod: ManifestV2) => filteringMod.getName() === mod.getName())) { await apply(modToApply); } - const saveErr = await this.saveModList(profile.asImmutableProfile(), list); + const saveErr = await this.saveModList(profile, list); if (saveErr instanceof R2Error) { return saveErr; } - return this.getModList(profile.asImmutableProfile()); + return this.getModList(profile); } private static async createExport(profile: Profile): Promise { From 32680220fafba0ddf7a6b1ee617f12676f5122f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Tue, 1 Oct 2024 10:45:57 +0300 Subject: [PATCH 7/9] Refactor ProfileModList.createExport to use ImmutableProfile --- src/r2mm/mods/ProfileModList.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index 6feb2d1e9..730e2662a 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -184,8 +184,8 @@ export default class ProfileModList { return this.getModList(profile); } - private static async createExport(profile: Profile): Promise { - const list: ManifestV2[] | R2Error = await this.getModList(profile.asImmutableProfile()); + private static async createExport(profile: ImmutableProfile): Promise { + const list: ManifestV2[] | R2Error = await this.getModList(profile); if (list instanceof R2Error) { return list; } @@ -236,7 +236,7 @@ export default class ProfileModList { if (dir.length === 0) { return new R2Error("Failed to export profile", "No export directory was selected", null); } - const builder = await this.createExport(profile); + const builder = await this.createExport(profile.asImmutableProfile()); if (builder instanceof R2Error) { return builder; } @@ -251,7 +251,7 @@ export default class ProfileModList { const exportDirectory = path.join(PathResolver.MOD_ROOT, 'exports'); await FileUtils.ensureDirectory(exportDirectory); const exportPath = path.join(exportDirectory, `${profile.getProfileName()}.r2z`); - const exportBuilder: R2Error | ZipBuilder = await this.createExport(profile); + const exportBuilder: R2Error | ZipBuilder = await this.createExport(profile.asImmutableProfile()); if (exportBuilder instanceof R2Error) { return exportBuilder; } else { From e7fd48aa06008ea22fdc830e7bdcadf2b686089c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Tue, 1 Oct 2024 10:48:13 +0300 Subject: [PATCH 8/9] Refactor ProfileModList.exportModListToFile to use ImmutableProfile --- src/pages/Manager.vue | 2 +- src/r2mm/mods/ProfileModList.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/Manager.vue b/src/pages/Manager.vue index 8a4f863ca..12f3140c5 100644 --- a/src/pages/Manager.vue +++ b/src/pages/Manager.vue @@ -376,7 +376,7 @@ import ModalCard from '../components/ModalCard.vue'; this.$store.commit('error/handleError', err); return; } - const exportErr = await ProfileModList.exportModListToFile(this.profile); + const exportErr = await ProfileModList.exportModListToFile(this.profile.asImmutableProfile()); if (exportErr instanceof R2Error) { this.$store.commit('error/handleError', exportErr); } diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index 730e2662a..ce6a263d8 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -219,7 +219,7 @@ export default class ProfileModList { return builder; } - public static async exportModListToFile(profile: Profile): Promise { + public static async exportModListToFile(profile: ImmutableProfile): Promise { const exportDirectory = path.join(PathResolver.MOD_ROOT, 'exports'); try { await FileUtils.ensureDirectory(exportDirectory); @@ -236,7 +236,7 @@ export default class ProfileModList { if (dir.length === 0) { return new R2Error("Failed to export profile", "No export directory was selected", null); } - const builder = await this.createExport(profile.asImmutableProfile()); + const builder = await this.createExport(profile); if (builder instanceof R2Error) { return builder; } From d37bb71c0835a0dc0e850fe0cf19df1184c9d3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Tue, 1 Oct 2024 10:51:00 +0300 Subject: [PATCH 9/9] Refactor ProfileModList.exportModListAsCode to use ImmutableProfile This completes refactoring ProfileModList, which no longer relies on the state tracking Profile object. --- src/pages/Manager.vue | 2 +- src/r2mm/mods/ProfileModList.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/Manager.vue b/src/pages/Manager.vue index 12f3140c5..fffb217b9 100644 --- a/src/pages/Manager.vue +++ b/src/pages/Manager.vue @@ -391,7 +391,7 @@ import ModalCard from '../components/ModalCard.vue'; this.$store.commit('error/handleError', err); return; } - const exportErr = await ProfileModList.exportModListAsCode(this.profile, (code: string, err: R2Error | null) => { + const exportErr = await ProfileModList.exportModListAsCode(this.profile.asImmutableProfile(), (code: string, err: R2Error | null) => { if (err !== null) { this.$store.commit('error/handleError', err); } else { diff --git a/src/r2mm/mods/ProfileModList.ts b/src/r2mm/mods/ProfileModList.ts index ce6a263d8..fd195b799 100644 --- a/src/r2mm/mods/ProfileModList.ts +++ b/src/r2mm/mods/ProfileModList.ts @@ -1,5 +1,5 @@ import * as yaml from 'yaml'; -import Profile, { ImmutableProfile } from '../../model/Profile'; +import { ImmutableProfile } from '../../model/Profile'; import * as path from 'path'; import FsProvider from '../../providers/generic/file/FsProvider'; @@ -246,12 +246,12 @@ export default class ProfileModList { return exportPath; } - public static async exportModListAsCode(profile: Profile, callback: (code: string, err: R2Error | null) => void): Promise { + public static async exportModListAsCode(profile: ImmutableProfile, callback: (code: string, err: R2Error | null) => void): Promise { const fs = FsProvider.instance; const exportDirectory = path.join(PathResolver.MOD_ROOT, 'exports'); await FileUtils.ensureDirectory(exportDirectory); const exportPath = path.join(exportDirectory, `${profile.getProfileName()}.r2z`); - const exportBuilder: R2Error | ZipBuilder = await this.createExport(profile.asImmutableProfile()); + const exportBuilder: R2Error | ZipBuilder = await this.createExport(profile); if (exportBuilder instanceof R2Error) { return exportBuilder; } else {