Skip to content

Commit

Permalink
Separate parseYamlToExportFormat function from ImportProfileModal UI …
Browse files Browse the repository at this point in the history
…component
  • Loading branch information
VilppeRiskidev committed Sep 20, 2024
1 parent 968b792 commit 6690cde
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
59 changes: 22 additions & 37 deletions src/components/profiles-modals/ImportProfileModal.vue
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<script lang="ts">
import path from "path";
import { Component } from 'vue-property-decorator';
import { ModalCard } from "../all";
import R2Error from "../../model/errors/R2Error";
import { ProfileImportExport } from "../../r2mm/mods/ProfileImportExport";
import { mixins } from "vue-class-component";
import * as PackageDb from '../../r2mm/manager/PackageDexieStore';
import * as ProfileUtils from "../../utils/ProfileUtils";
import ExportFormat from "../../model/exports/ExportFormat";
import ExportMod from "../../model/exports/ExportMod";
import path from "path";
import Profile from "../../model/Profile";
import FileUtils from "../../utils/FileUtils";
import FsProvider from "../../providers/generic/file/FsProvider";
import ThunderstoreDownloaderProvider from "../../providers/ror2/downloading/ThunderstoreDownloaderProvider";
import StatusEnum from "../../model/enums/StatusEnum";
import ThunderstoreCombo from "../../model/ThunderstoreCombo";
import InteractionProvider from "../../providers/ror2/system/InteractionProvider";
import ManagerInformation from "../../_managerinf/ManagerInformation";
import ManifestV2 from "../../model/ManifestV2";
import ProfileModList from "../../r2mm/mods/ProfileModList";
import { ModalCard } from "../all";
import OnlineModList from "../views/OnlineModList.vue";
import Profile from "../../model/Profile";
import { ProfileImportExport } from "../../r2mm/mods/ProfileImportExport";
import ProfileInstallerProvider from "../../providers/ror2/installing/ProfileInstallerProvider";
import InteractionProvider from "../../providers/ror2/system/InteractionProvider";
import { mixins } from "vue-class-component";
import ProfilesMixin from "../mixins/ProfilesMixin.vue";
import ExportFormat from "../../model/exports/ExportFormat";
import * as yaml from "yaml";
import VersionNumber from "../../model/VersionNumber";
import ZipProvider from "../../providers/generic/zip/ZipProvider";
import ProfileModList from "../../r2mm/mods/ProfileModList";
import R2Error from "../../model/errors/R2Error";
import StatusEnum from "../../model/enums/StatusEnum";
import ThunderstoreCombo from "../../model/ThunderstoreCombo";
import ThunderstoreDownloaderProvider from "../../providers/ror2/downloading/ThunderstoreDownloaderProvider";
import ThunderstoreMod from "../../model/ThunderstoreMod";
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";
import ZipProvider from "../../providers/generic/zip/ZipProvider";
let fs: FsProvider;
Expand Down Expand Up @@ -126,7 +126,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
if (read !== null) {
this.profileImportFilePath = files[0];
this.profileImportContent = await this.parseYamlToExportFormat(read);
this.profileImportContent = await ProfileUtils.parseYamlToExportFormat(read);
if (this.profileToOnlineMods.length === 0) {
this.activeStep = 'NO_PACKAGES_IN_IMPORT';
Expand Down Expand Up @@ -205,7 +205,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
setTimeout(async () => {
await this.downloadImportedProfileMods(parsed.getMods(), async () => {
if (files[0].endsWith('.r2z')) {
await extractZippedProfileFile(files[0], profileName);
await ProfileUtils.extractZippedProfileFile(files[0], profileName);
}
if (this.importUpdateSelection === 'UPDATE') {
this.activeProfileName = event.detail;
Expand Down Expand Up @@ -311,22 +311,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
document.dispatchEvent(new CustomEvent("created-profile", {detail: this.activeProfileName}));
}
async parseYamlToExportFormat(read: string) {
const parsedYaml = await yaml.parse(read);
return new ExportFormat(
parsedYaml.profileName,
parsedYaml.mods.map((mod: any) => {
const enabled = mod.enabled === undefined || mod.enabled;
return new ExportMod(
mod.name,
new VersionNumber(
`${mod.version.major}.${mod.version.minor}.${mod.version.patch}`
),
enabled
);
})
);
}
}
</script>
Expand Down
25 changes: 24 additions & 1 deletion src/utils/ProfileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import ZipProvider from "../providers/generic/zip/ZipProvider";
import path from "path";

import * as yaml from "yaml";

import Profile from "../model/Profile";
import ExportFormat from "src/model/exports/ExportFormat";
import ExportMod from "src/model/exports/ExportMod";
import VersionNumber from "src/model/VersionNumber";
import ZipProvider from "../providers/generic/zip/ZipProvider";

export async function extractZippedProfileFile(file: string, profileName: string) {
const entries = await ZipProvider.instance.getEntries(file);
Expand All @@ -27,3 +33,20 @@ export async function extractZippedProfileFile(file: string, profileName: string
}
}
}

export async function parseYamlToExportFormat(yamlContent: string) {
const parsedYaml = await yaml.parse(yamlContent);
return new ExportFormat(
parsedYaml.profileName,
parsedYaml.mods.map((mod: any) => {
const enabled = mod.enabled === undefined || mod.enabled;
return new ExportMod(
mod.name,
new VersionNumber(
`${mod.version.major}.${mod.version.minor}.${mod.version.patch}`
),
enabled
);
})
);
}

0 comments on commit 6690cde

Please sign in to comment.