diff --git a/src/components/profiles-modals/ImportProfileModal.vue b/src/components/profiles-modals/ImportProfileModal.vue index c70b1ba95..ec89773ca 100644 --- a/src/components/profiles-modals/ImportProfileModal.vue +++ b/src/components/profiles-modals/ImportProfileModal.vue @@ -13,7 +13,6 @@ import ManifestV2 from "../../model/ManifestV2"; import Profile from "../../model/Profile"; import ThunderstoreCombo from "../../model/ThunderstoreCombo"; import FsProvider from "../../providers/generic/file/FsProvider"; -import ZipProvider from "../../providers/generic/zip/ZipProvider"; import ThunderstoreDownloaderProvider from "../../providers/ror2/downloading/ThunderstoreDownloaderProvider"; import ProfileInstallerProvider from "../../providers/ror2/installing/ProfileInstallerProvider"; import InteractionProvider from "../../providers/ror2/system/InteractionProvider"; @@ -130,7 +129,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { return; } - let read: string | null = await this.readProfileFile(files[0]); + let read: string | null = await ProfileUtils.readProfileFile(files[0]); if (read !== null) { this.profileImportFilePath = files[0]; @@ -166,20 +165,6 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) { this.activeStep = 'ADDING_PROFILE'; } - async readProfileFile(file: string) { - let read = ''; - if (file.endsWith('.r2x')) { - read = (await FsProvider.instance.readFile(file)).toString(); - } else if (file.endsWith('.r2z')) { - const result: Buffer | null = await ZipProvider.instance.readFile(file, "export.r2x"); - if (result === null) { - return null; - } - read = result.toString(); - } - return read; - } - profileCreatedCallback(event: CustomEvent, localListenerId: number, parsed: ExportFormat, files: string[]) { if (this.listenerId === localListenerId) { (async () => { diff --git a/src/utils/ProfileUtils.ts b/src/utils/ProfileUtils.ts index 491bf2ca3..118dd74de 100644 --- a/src/utils/ProfileUtils.ts +++ b/src/utils/ProfileUtils.ts @@ -10,6 +10,7 @@ import Profile from "../model/Profile"; import ThunderstoreMod from "../model/ThunderstoreMod"; import ThunderstoreVersion from "../model/ThunderstoreVersion"; import VersionNumber from "../model/VersionNumber"; +import FsProvider from "../providers/generic/file/FsProvider"; import ZipProvider from "../providers/generic/zip/ZipProvider"; import ProfileInstallerProvider from "../providers/ror2/installing/ProfileInstallerProvider"; import ProfileModList from "../r2mm/mods/ProfileModList"; @@ -71,3 +72,18 @@ export async function parseYamlToExportFormat(yamlContent: string) { }) ); } + +//TODO: Check if instead of returning null/empty strings, there's some errors that should be handled +export async function readProfileFile(file: string) { + let read = ''; + if (file.endsWith('.r2x')) { + read = (await FsProvider.instance.readFile(file)).toString(); + } else if (file.endsWith('.r2z')) { + const result: Buffer | null = await ZipProvider.instance.readFile(file, "export.r2x"); + if (result === null) { + return null; + } + read = result.toString(); + } + return read; +}