From 14dfadac4c97c2efcb702f8d1b4ed33a4bb7c06a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Wed, 16 Oct 2024 09:13:39 +0300 Subject: [PATCH 1/2] Improve profile import performance - Don't track the profile status to mods.yml file as the mods are installed. The old implementation that did this was wildly inefficient with the number of disk operations it used. In the end the work is in vain, as the mods.yml will be copied from the imported profile in a later step - Rename the two helper methods to clarify they're to be used when importing a profile, and to unify the naming --- src/utils/ProfileUtils.ts | 43 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/utils/ProfileUtils.ts b/src/utils/ProfileUtils.ts index 03e8aef9..53f754e9 100644 --- a/src/utils/ProfileUtils.ts +++ b/src/utils/ProfileUtils.ts @@ -14,7 +14,6 @@ import FsProvider from "../providers/generic/file/FsProvider"; import ZipProvider from "../providers/generic/zip/ZipProvider"; import ProfileInstallerProvider from "../providers/ror2/installing/ProfileInstallerProvider"; import * as PackageDb from '../r2mm/manager/PackageDexieStore'; -import ProfileModList from "../r2mm/mods/ProfileModList"; export async function exportModsToCombos(exportMods: ExportMod[], community: string): Promise { const tsMods = await PackageDb.getPackagesByNames(community, exportMods.map((m) => m.getName())); @@ -44,7 +43,7 @@ export async function exportModsToCombos(exportMods: ExportMod[], community: str return combos; } -async function extractImportedProfileConfigs( +async function extractConfigsToImportedProfile( file: string, profileName: string, progressCallback: (status: string) => void @@ -78,7 +77,11 @@ async function extractImportedProfileConfigs( } } -async function installModsToProfile( +/** + * Install mods to target profile without syncing changes to mods.yml file. + * Syncing is futile, as the mods.yml is copied from the imported profile. + */ +async function installModsToImportedProfile( comboList: ThunderstoreCombo[], modList: ExportMod[], profile: ImmutableProfile, @@ -87,25 +90,15 @@ async function installModsToProfile( const disabledMods = modList.filter((m) => !m.isEnabled()).map((m) => m.getName()); 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); - if (installError instanceof R2Error) { - throw installError; - } - - const newModList: ManifestV2[] | R2Error = await ProfileModList.addMod(manifestMod, profile); - if (newModList instanceof R2Error) { - throw newModList; - } + const manifestMod = new ManifestV2().fromThunderstoreMod(comboMod.getMod(), comboMod.getVersion()); + throwForR2Error( + await ProfileInstallerProvider.instance.installMod(manifestMod, profile) + ); if (disabledMods.includes(manifestMod.getName())) { - await ProfileModList.updateMod(manifestMod, profile, async (modToDisable: ManifestV2) => { - // Need to enable temporarily so the manager doesn't think it's re-disabling a disabled mod. - modToDisable.enable(); - await ProfileInstallerProvider.instance.disableMod(modToDisable, profile); - modToDisable.disable(); - }); + throwForR2Error( + await ProfileInstallerProvider.instance.disableMod(manifestMod, profile) + ); } const progress = Math.floor((index/comboList.length) * 100); @@ -153,8 +146,8 @@ export async function populateImportedProfile( await FileUtils.recursiveRemoveDirectoryIfExists(profile.getProfilePath()); } - await installModsToProfile(comboList, exportModList, profile, progressCallback); - await extractImportedProfileConfigs(zipPath, profile.getProfileName(), progressCallback); + await installModsToImportedProfile(comboList, exportModList, profile, progressCallback); + await extractConfigsToImportedProfile(zipPath, profile.getProfileName(), progressCallback); if (isUpdate) { progressCallback('Applying changes to updated profile...'); @@ -178,3 +171,9 @@ export async function readProfileFile(file: string) { } return read; } + +function throwForR2Error(maybeError: unknown) { + if (maybeError instanceof R2Error) { + throw maybeError; + } +} From 842dcbca0e604bec8d249ed2cffb2891afef705d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Wed, 16 Oct 2024 10:13:56 +0300 Subject: [PATCH 2/2] Fix off by one error in progress indicator --- src/utils/ProfileUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/ProfileUtils.ts b/src/utils/ProfileUtils.ts index 53f754e9..939bdc25 100644 --- a/src/utils/ProfileUtils.ts +++ b/src/utils/ProfileUtils.ts @@ -72,7 +72,7 @@ async function extractConfigsToImportedProfile( ) } - const progress = Math.floor((index/zipEntries.length) * 100); + const progress = Math.floor(((index + 1) / zipEntries.length) * 100); progressCallback(`Copying configs to profile: ${progress}%`); } } @@ -101,7 +101,7 @@ async function installModsToImportedProfile( ); } - const progress = Math.floor((index/comboList.length) * 100); + const progress = Math.floor(((index + 1) / comboList.length) * 100); progressCallback(`Copying mods to profile: ${progress}%`); } }