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

Show progress of each step in the profile import modal #1480

Merged
merged 1 commit into from
Oct 14, 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
19 changes: 12 additions & 7 deletions src/components/profiles-modals/ImportProfileModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import OnlineModList from "../views/OnlineModList.vue";
})
export default class ImportProfileModal extends mixins(ProfilesMixin) {
private importUpdateSelection: "IMPORT" | "UPDATE" | null = null;
private percentageImported: number = 0;
private importPhaseDescription: string = 'Downloading mods: 0%';
private profileImportCode: string = '';
private listenerId: number = 0;
private newProfileName: string = '';
Expand Down Expand Up @@ -163,8 +163,10 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
}

this.activeStep = 'PROFILE_IS_BEING_IMPORTED';
this.percentageImported = 0;
const progressCallback = (progress: number) => this.percentageImported = Math.floor(progress);
this.importPhaseDescription = 'Downloading mods: 0%';
const progressCallback = (progress: number|string) => typeof progress === "number"
? this.importPhaseDescription = `Downloading mods: ${Math.floor(progress)}%`
: this.importPhaseDescription = progress;
const community = this.$store.state.activeGame.internalFolderName;
const settings = this.$store.getters['settings'];
const ignoreCache = settings.getContext().global.ignoreCache;
Expand All @@ -173,7 +175,7 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
try {
const comboList = await ProfileUtils.exportModsToCombos(mods, community);
await ThunderstoreDownloaderProvider.instance.downloadImportedMods(comboList, ignoreCache, progressCallback);
await ProfileUtils.populateImportedProfile(comboList, mods, targetProfileName, isUpdate, zipPath);
await ProfileUtils.populateImportedProfile(comboList, mods, targetProfileName, isUpdate, zipPath, progressCallback);
} catch (e) {
this.closeModal();
this.$store.commit('error/handleError', R2Error.fromThrownValue(e));
Expand Down Expand Up @@ -359,11 +361,14 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {

<ModalCard v-else-if="activeStep === 'PROFILE_IS_BEING_IMPORTED'" key="PROFILE_IS_BEING_IMPORTED" :is-active="isOpen" :canClose="false">
<template v-slot:header>
<h2 class="modal-title">{{percentageImported}}% imported</h2>
<h2 class="modal-title">{{importPhaseDescription}}</h2>
</template>
<template v-slot:footer>
<p>This may take a while, as mods are being downloaded.<br>
Please do not close {{appName}}.</p>
<p>
This may take a while, as files are being downloaded, extracted, and copied.
<br><br>
Please do not close {{appName}}.
</p>
</template>
</ModalCard>
</template>
Expand Down
35 changes: 27 additions & 8 deletions src/utils/ProfileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ export async function exportModsToCombos(exportMods: ExportMod[], community: str
return combos;
}

export async function extractImportedProfileConfigs(file: string, profileName: string) {
const entries = await ZipProvider.instance.getEntries(file);
for (const entry of entries) {
async function extractImportedProfileConfigs(
file: string,
profileName: string,
progressCallback: (status: string) => void
) {
const zipEntries = await ZipProvider.instance.getEntries(file);

for (const [index, entry] of zipEntries.entries()) {
if (entry.entryName.startsWith('config/') || entry.entryName.startsWith("config\\")) {
await ZipProvider.instance.extractEntryTo(
file,
Expand All @@ -67,13 +72,21 @@ export async function extractImportedProfileConfigs(file: string, profileName: s
)
)
}

const progress = Math.floor((index/zipEntries.length) * 100);
progressCallback(`Copying configs to profile: ${progress}%`);
}
}

export async function installModsToProfile(comboList: ThunderstoreCombo[], modList: ExportMod[], profile: ImmutableProfile) {
async function installModsToProfile(
comboList: ThunderstoreCombo[],
modList: ExportMod[],
profile: ImmutableProfile,
progressCallback: (status: string) => void
) {
const disabledMods = modList.filter((m) => !m.isEnabled()).map((m) => m.getName());

for (const comboMod of comboList) {
for (const [index, comboMod] of comboList.entries()) {
const manifestMod: ManifestV2 = new ManifestV2().fromThunderstoreMod(comboMod.getMod(), comboMod.getVersion());

const installError: R2Error | null = await ProfileInstallerProvider.instance.installMod(manifestMod, profile);
Expand All @@ -94,6 +107,9 @@ export async function installModsToProfile(comboList: ThunderstoreCombo[], modLi
modToDisable.disable();
});
}

const progress = Math.floor((index/comboList.length) * 100);
progressCallback(`Copying mods to profile: ${progress}%`);
}
}

Expand Down Expand Up @@ -127,18 +143,21 @@ export async function populateImportedProfile(
exportModList: ExportMod[],
profileName: string,
isUpdate: boolean,
zipPath: string
zipPath: string,
progressCallback: (status: string) => void
) {
const profile = new ImmutableProfile(isUpdate ? '_profile_update' : profileName);

if (isUpdate) {
progressCallback('Cleaning up...');
await FileUtils.recursiveRemoveDirectoryIfExists(profile.getProfilePath());
}

await installModsToProfile(comboList, exportModList, profile);
await extractImportedProfileConfigs(zipPath, profile.getProfileName());
await installModsToProfile(comboList, exportModList, profile, progressCallback);
await extractImportedProfileConfigs(zipPath, profile.getProfileName(), progressCallback);

if (isUpdate) {
progressCallback('Applying changes to updated profile...');
const targetProfile = new ImmutableProfile(profileName);
await FileUtils.recursiveRemoveDirectoryIfExists(targetProfile.getProfilePath());
await FsProvider.instance.rename(profile.getProfilePath(), targetProfile.getProfilePath());
Expand Down
Loading