From 71df8ea5876b73c0a4ca57699cd068e560a30cfc Mon Sep 17 00:00:00 2001 From: Cade Ayres Date: Sat, 7 Sep 2024 17:12:10 +0100 Subject: [PATCH 1/2] Shows a summary of packages to be installed when importing a profile --- src/components/ModalCard.vue | 8 +- .../profiles-modals/ImportProfileModal.vue | 107 ++++++++++-------- src/components/views/OnlineModList.vue | 11 +- src/css/custom.scss | 8 ++ 4 files changed, 82 insertions(+), 52 deletions(-) diff --git a/src/components/ModalCard.vue b/src/components/ModalCard.vue index 283bfafd8..1e184e187 100644 --- a/src/components/ModalCard.vue +++ b/src/components/ModalCard.vue @@ -5,9 +5,11 @@ - + diff --git a/src/components/profiles-modals/ImportProfileModal.vue b/src/components/profiles-modals/ImportProfileModal.vue index 0517615c5..202b338d2 100644 --- a/src/components/profiles-modals/ImportProfileModal.vue +++ b/src/components/profiles-modals/ImportProfileModal.vue @@ -25,12 +25,13 @@ import ZipProvider from "../../providers/generic/zip/ZipProvider"; import ThunderstoreMod from "../../model/ThunderstoreMod"; import ThunderstoreVersion from "../../model/ThunderstoreVersion"; import ManagerInformation from "../../_managerinf/ManagerInformation"; +import OnlineModList from 'components/views/OnlineModList.vue'; let fs: FsProvider; @Component({ - components: {ModalCard} + components: { OnlineModList, ModalCard} }) export default class ImportProfileModal extends mixins(ProfilesMixin) { private importUpdateSelection: "IMPORT" | "UPDATE" | null = null; @@ -39,7 +40,9 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { private isProfileBeingImported: boolean = false; private listenerId: number = 0; private newProfileName: string = ''; - private activeStep: 'IMPORT_UPDATE_SELECTION' | 'FILE_SELECTION' | 'FILE_CODE_SELECTION' | 'IMPORT_CODE' | 'IMPORT_FILE' | 'ADDING_PROFILE' = 'IMPORT_UPDATE_SELECTION'; + private profileImportFilePath: string | null = null; + private profileImportContent: ExportFormat | null = null; + private activeStep: 'IMPORT_UPDATE_SELECTION' | 'FILE_SELECTION' | 'FILE_CODE_SELECTION' | 'IMPORT_CODE' | 'IMPORT_FILE' | 'ADDING_PROFILE' | 'REVIEW_IMPORT' = 'IMPORT_UPDATE_SELECTION'; @@ -65,12 +68,23 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { } } + get profileToOnlineMods() { + if (!this.profileImportContent) { + return []; + } + return this.profileImportContent.getMods() + .map(mod => this.$store.getters['tsMods/tsMod'](mod)) + .filter(mod => !!mod) + } + closeModal() { this.activeStep = 'IMPORT_UPDATE_SELECTION'; this.listenerId = 0; this.newProfileName = ''; this.importUpdateSelection = null; this.profileImportCode = ''; + this.profileImportFilePath = null; + this.profileImportContent = null; this.$store.commit('closeImportProfileModal'); } @@ -92,7 +106,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { title: 'Import Profile', filters: [{ name: "*", - extensions: ["r2z", "r2x"] + extensions: ["r2z"] }], buttonLabel: 'Import' }).then((value: string[]) => { @@ -120,25 +134,26 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { return; } - if (files[0].endsWith(".json")) { - return await this.importAlternativeManagerProfile(files[0]); - } - let read: string | null = await this.readProfileFile(files[0]); if (read !== null) { - const parsed: ExportFormat = await this.parseYamlToExportFormat(read); - - const localListenerId = this.listenerId + 1; - this.listenerId = localListenerId; - document.addEventListener('created-profile', ((event: CustomEvent) => - this.profileCreatedCallback(event, localListenerId, parsed, files) - ) as EventListener, {once: true}); - this.newProfileName = parsed.getProfileName(); - this.activeStep = 'ADDING_PROFILE'; + this.profileImportFilePath = files[0]; + this.profileImportContent = await this.parseYamlToExportFormat(read); + this.activeStep = 'REVIEW_IMPORT'; } } + async installProfileHandler() { + const profileContent = this.profileImportContent; + const localListenerId = this.listenerId + 1; + this.listenerId = localListenerId; + document.addEventListener('created-profile', ((event: CustomEvent) => + this.profileCreatedCallback(event, localListenerId, profileContent!, [this.profileImportFilePath!]) + ) as EventListener, {once: true}); + this.newProfileName = profileContent!.getProfileName(); + this.activeStep = 'ADDING_PROFILE'; + } + async installModAfterDownload(mod: ThunderstoreMod, version: ThunderstoreVersion): Promise { const manifestMod: ManifestV2 = new ManifestV2().fromThunderstoreMod(mod, version); const installError: R2Error | null = await ProfileInstallerProvider.instance.installMod(manifestMod, this.activeProfile); @@ -168,29 +183,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { return read; } - async importAlternativeManagerProfile(file: string) { - try { - const fileString = (await FsProvider.instance.readFile(file)).toString(); - const jsonContent = JSON.parse(fileString.trim()); - const ror2Itf = jsonContent as Itf_RoR2MM; - if (ror2Itf.name != undefined && ror2Itf.packages != undefined) { - this.newProfileName = ror2Itf.name; - this.activeStep = 'ADDING_PROFILE'; - const itfPackages: string[] = ror2Itf.packages; - document.addEventListener("created-profile", ((() => { - const packages = itfPackages.map(value => ExportMod.fromFullString(value)); - setTimeout(() => { - this.downloadImportedProfileMods(packages); - }, 100); - }) as EventListener), {once: true}); - } - } catch (e) { - const err = R2Error.fromThrownValue(e, 'Failed to import profile'); - this.$store.commit('error/handleError', err); - } - } - - profileCreatedCallback(event: CustomEvent, localListenerId: number, parsed: { getMods: () => ExportMod[]; }, files: string[]) { + profileCreatedCallback(event: CustomEvent, localListenerId: number, parsed: ExportFormat, files: string[]) { if (this.listenerId === localListenerId) { (async () => { let profileName: string = event.detail; @@ -351,10 +344,11 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { } +