Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move readProfileFile function away from the UI component #1460

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading