Skip to content

Commit

Permalink
Merge pull request #1450 from ebkr/separate-zip-extraction-from-ui-co…
Browse files Browse the repository at this point in the history
…mponent

Separate Zip extraction function from Profile Import Ui component
  • Loading branch information
anttimaki authored Sep 19, 2024
2 parents 351a5b2 + 03729ae commit 968b792
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/components/profiles-modals/ImportProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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 @@ -204,7 +205,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
setTimeout(async () => {
await this.downloadImportedProfileMods(parsed.getMods(), async () => {
if (files[0].endsWith('.r2z')) {
await this.extractZippedProfileFile(files[0], profileName);
await extractZippedProfileFile(files[0], profileName);
}
if (this.importUpdateSelection === 'UPDATE') {
this.activeProfileName = event.detail;
Expand All @@ -226,32 +227,6 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
}
}
async extractZippedProfileFile(file: string, profileName: string) {
const entries = await ZipProvider.instance.getEntries(file);
for (const entry of entries) {
if (entry.entryName.startsWith('config/') || entry.entryName.startsWith("config\\")) {
await ZipProvider.instance.extractEntryTo(
file,
entry.entryName,
path.join(
Profile.getDirectory(),
profileName,
'BepInEx'
)
);
} else if (entry.entryName.toLowerCase() !== "export.r2x") {
await ZipProvider.instance.extractEntryTo(
file,
entry.entryName,
path.join(
Profile.getDirectory(),
profileName
)
)
}
}
}
async downloadImportedProfileMods(modList: ExportMod[], callback?: () => void) {
const settings = this.$store.getters['settings'];
const ignoreCache = settings.getContext().global.ignoreCache;
Expand Down
29 changes: 29 additions & 0 deletions src/utils/ProfileUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ZipProvider from "../providers/generic/zip/ZipProvider";
import path from "path";
import Profile from "../model/Profile";

export async function extractZippedProfileFile(file: string, profileName: string) {
const entries = await ZipProvider.instance.getEntries(file);
for (const entry of entries) {
if (entry.entryName.startsWith('config/') || entry.entryName.startsWith("config\\")) {
await ZipProvider.instance.extractEntryTo(
file,
entry.entryName,
path.join(
Profile.getDirectory(),
profileName,
'BepInEx'
)
);
} else if (entry.entryName.toLowerCase() !== "export.r2x") {
await ZipProvider.instance.extractEntryTo(
file,
entry.entryName,
path.join(
Profile.getDirectory(),
profileName
)
)
}
}
}

0 comments on commit 968b792

Please sign in to comment.