From 03729ae4c9d57743b0cdc8bd15205922c9b94add Mon Sep 17 00:00:00 2001 From: Vili Manninen Date: Thu, 19 Sep 2024 13:10:02 +0300 Subject: [PATCH] Separate Zip extraction function from Profile Import Ui component --- .../profiles-modals/ImportProfileModal.vue | 29 ++----------------- src/utils/ProfileUtils.ts | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 src/utils/ProfileUtils.ts diff --git a/src/components/profiles-modals/ImportProfileModal.vue b/src/components/profiles-modals/ImportProfileModal.vue index 820c3775..889ab9aa 100644 --- a/src/components/profiles-modals/ImportProfileModal.vue +++ b/src/components/profiles-modals/ImportProfileModal.vue @@ -26,6 +26,7 @@ import ThunderstoreVersion from "../../model/ThunderstoreVersion"; import ManagerInformation from "../../_managerinf/ManagerInformation"; import OnlineModList from "../views/OnlineModList.vue"; import * as PackageDb from '../../r2mm/manager/PackageDexieStore'; +import { extractZippedProfileFile } from "../../utils/ProfileUtils"; let fs: FsProvider; @@ -204,7 +205,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { setTimeout(async () => { await this.downloadImportedProfileMods(parsed.getMods(), async () => { if (files[0].endsWith('.r2z')) { - await this.extractZippedProfileFile(files[0], profileName); + await extractZippedProfileFile(files[0], profileName); } if (this.importUpdateSelection === 'UPDATE') { this.activeProfileName = event.detail; @@ -226,32 +227,6 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { } } - async extractZippedProfileFile(file: string, profileName: string) { - const entries = await ZipProvider.instance.getEntries(file); - for (const entry of entries) { - if (entry.entryName.startsWith('config/') || entry.entryName.startsWith("config\\")) { - await ZipProvider.instance.extractEntryTo( - file, - entry.entryName, - path.join( - Profile.getDirectory(), - profileName, - 'BepInEx' - ) - ); - } else if (entry.entryName.toLowerCase() !== "export.r2x") { - await ZipProvider.instance.extractEntryTo( - file, - entry.entryName, - path.join( - Profile.getDirectory(), - profileName - ) - ) - } - } - } - async downloadImportedProfileMods(modList: ExportMod[], callback?: () => void) { const settings = this.$store.getters['settings']; const ignoreCache = settings.getContext().global.ignoreCache; diff --git a/src/utils/ProfileUtils.ts b/src/utils/ProfileUtils.ts new file mode 100644 index 00000000..ba6a99db --- /dev/null +++ b/src/utils/ProfileUtils.ts @@ -0,0 +1,29 @@ +import ZipProvider from "../providers/generic/zip/ZipProvider"; +import path from "path"; +import Profile from "../model/Profile"; + +export async function extractZippedProfileFile(file: string, profileName: string) { + const entries = await ZipProvider.instance.getEntries(file); + for (const entry of entries) { + if (entry.entryName.startsWith('config/') || entry.entryName.startsWith("config\\")) { + await ZipProvider.instance.extractEntryTo( + file, + entry.entryName, + path.join( + Profile.getDirectory(), + profileName, + 'BepInEx' + ) + ); + } else if (entry.entryName.toLowerCase() !== "export.r2x") { + await ZipProvider.instance.extractEntryTo( + file, + entry.entryName, + path.join( + Profile.getDirectory(), + profileName + ) + ) + } + } +}