Skip to content
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
57 changes: 21 additions & 36 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 { mixins } from "vue-class-component";
import { Component } from 'vue-property-decorator';
import { ModalCard } from "../all";

import ManagerInformation from "../../_managerinf/ManagerInformation";
import StatusEnum from "../../model/enums/StatusEnum";
import R2Error from "../../model/errors/R2Error";
import { ProfileImportExport } from "../../r2mm/mods/ProfileImportExport";
import ExportFormat from "../../model/exports/ExportFormat";
import ExportMod from "../../model/exports/ExportMod";
import path from "path";
import ManifestV2 from "../../model/ManifestV2";
import Profile from "../../model/Profile";
import FileUtils from "../../utils/FileUtils";
import ThunderstoreCombo from "../../model/ThunderstoreCombo";
import ThunderstoreMod from "../../model/ThunderstoreMod";
import ThunderstoreVersion from "../../model/ThunderstoreVersion";
import FsProvider from "../../providers/generic/file/FsProvider";
import ZipProvider from "../../providers/generic/zip/ZipProvider";
import ThunderstoreDownloaderProvider from "../../providers/ror2/downloading/ThunderstoreDownloaderProvider";
import StatusEnum from "../../model/enums/StatusEnum";
import ThunderstoreCombo from "../../model/ThunderstoreCombo";
import ManifestV2 from "../../model/ManifestV2";
import ProfileModList from "../../r2mm/mods/ProfileModList";
import ProfileInstallerProvider from "../../providers/ror2/installing/ProfileInstallerProvider";
import InteractionProvider from "../../providers/ror2/system/InteractionProvider";
import { mixins } from "vue-class-component";
import * as PackageDb from '../../r2mm/manager/PackageDexieStore';
import { ProfileImportExport } from "../../r2mm/mods/ProfileImportExport";
import ProfileModList from "../../r2mm/mods/ProfileModList";
import FileUtils from "../../utils/FileUtils";
import * as ProfileUtils from "../../utils/ProfileUtils";
import { ModalCard } from "../all";
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 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";

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 ExportFormat from "../model/exports/ExportFormat";
import ExportMod from "../model/exports/ExportMod";
import Profile from "../model/Profile";
import VersionNumber from "../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
);
})
);
}
Loading