Skip to content

Commit

Permalink
Move readProfileFile function away from the UI component
Browse files Browse the repository at this point in the history
  • Loading branch information
VilppeRiskidev committed Oct 2, 2024
1 parent 413acb8 commit 868f998
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 1 addition & 16 deletions src/components/profiles-modals/ImportProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 () => {
Expand Down
16 changes: 16 additions & 0 deletions src/utils/ProfileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}

0 comments on commit 868f998

Please sign in to comment.