Skip to content

Commit c829494

Browse files
committed
Remove last uses of Profile from ProfileInstallerProvider
ImmutableProfile objects will now be used with uninstallation operations, as changing the target profile in the middle of the operation would result in disaster.
1 parent 1c25b7c commit c829494

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

src/providers/ror2/installing/ProfileInstallerProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ProviderUtils from '../../generic/ProviderUtils';
22
import ManifestV2 from '../../../model/ManifestV2';
33
import R2Error from '../../../model/errors/R2Error';
4-
import Profile, { ImmutableProfile } from '../../../model/Profile';
4+
import { ImmutableProfile } from '../../../model/Profile';
55

66
export default abstract class ProfileInstallerProvider {
77

@@ -21,7 +21,7 @@ export default abstract class ProfileInstallerProvider {
2121
* Removes a mod from the profile. Does not affect the mod list display.
2222
* @param mod
2323
*/
24-
public abstract uninstallMod(mod: ManifestV2, profile: Profile): Promise<R2Error | null>;
24+
public abstract uninstallMod(mod: ManifestV2, profile: ImmutableProfile): Promise<R2Error | null>;
2525

2626
/**
2727
* Disable files to prevent the mod from loading.

src/r2mm/installing/LocalModInstaller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider {
6060
}
6161
}
6262
await FsProvider.instance.writeFile(path.join(cacheDirectory, manifest.getName(), manifest.getVersionNumber().toString(), "mm_v2_manifest.json"), JSON.stringify(manifest));
63-
await ProfileInstallerProvider.instance.uninstallMod(manifest, profile);
63+
await ProfileInstallerProvider.instance.uninstallMod(manifest, profile.asImmutableProfile());
6464
const profileInstallResult = await ProfileInstallerProvider.instance.installMod(manifest, profile.asImmutableProfile());
6565
if (profileInstallResult instanceof R2Error) {
6666
callback(false, profileInstallResult);
@@ -86,7 +86,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider {
8686
const fileSafe = file.split("\\").join("/");
8787
await FsProvider.instance.copyFile(fileSafe, path.join(modCacheDirectory, path.basename(fileSafe)));
8888
await FsProvider.instance.writeFile(path.join(modCacheDirectory, "mm_v2_manifest.json"), JSON.stringify(manifest));
89-
await ProfileInstallerProvider.instance.uninstallMod(manifest, profile);
89+
await ProfileInstallerProvider.instance.uninstallMod(manifest, profile.asImmutableProfile());
9090
const profileInstallResult = await ProfileInstallerProvider.instance.installMod(manifest, profile.asImmutableProfile());
9191
if (profileInstallResult instanceof R2Error) {
9292
callback(false, profileInstallResult);

src/r2mm/installing/profile_installers/GenericProfileInstaller.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ProfileInstallerProvider from '../../../providers/ror2/installing/ProfileInstallerProvider';
22
import ManifestV2 from '../../../model/ManifestV2';
3-
import Profile, { ImmutableProfile } from '../../../model/Profile';
3+
import { ImmutableProfile } from '../../../model/Profile';
44
import FileTree from '../../../model/file/FileTree';
55
import R2Error from '../../../model/errors/R2Error';
66
import ModLoaderPackageMapping from '../../../model/installing/ModLoaderPackageMapping';
@@ -157,11 +157,10 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
157157
return this.installForManifestV2(args);
158158
}
159159

160-
private getInstallArgs(mod: ManifestV2, profile: Profile|ImmutableProfile): InstallArgs {
161-
const immutable = profile instanceof Profile ? profile.asImmutableProfile() : profile;
160+
private getInstallArgs(mod: ManifestV2, profile: ImmutableProfile): InstallArgs {
162161
const cacheDirectory = path.join(PathResolver.MOD_ROOT, 'cache');
163162
const packagePath = path.join(cacheDirectory, mod.getName(), mod.getVersionNumber().toString());
164-
return {mod, profile: immutable, packagePath};
163+
return {mod, profile, packagePath};
165164
}
166165

167166
private getModLoader(mod: ManifestV2): ModLoaderPackageMapping|undefined {
@@ -182,7 +181,7 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
182181
}
183182
}
184183

185-
private async uninstallPackageZip(mod: ManifestV2, profile: Profile) {
184+
private async uninstallPackageZip(mod: ManifestV2, profile: ImmutableProfile) {
186185
const fs = FsProvider.instance;
187186

188187
const recursiveDelete = async (mainPath: string, match: string) => {
@@ -200,7 +199,7 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
200199
await recursiveDelete(profile.getProfilePath(), `${mod.getName()}.ts.zip`);
201200
}
202201

203-
private async uninstallSubDir(mod: ManifestV2, profile: Profile): Promise<R2Error | null> {
202+
private async uninstallSubDir(mod: ManifestV2, profile: ImmutableProfile): Promise<R2Error | null> {
204203
const activeGame = GameManager.activeGame;
205204
const fs = FsProvider.instance;
206205

@@ -255,7 +254,7 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
255254
return Promise.resolve(null);
256255
}
257256

258-
private async uninstallState(mod: ManifestV2, profile: Profile): Promise<R2Error | null> {
257+
private async uninstallState(mod: ManifestV2, profile: ImmutableProfile): Promise<R2Error | null> {
259258
const stateFilePath = profile.joinToProfilePath("_state", `${mod.getName()}-state.yml`);
260259
if (await FsProvider.instance.exists(stateFilePath)) {
261260
const read = await FsProvider.instance.readFile(stateFilePath);
@@ -273,7 +272,7 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
273272
return Promise.resolve(null);
274273
}
275274

276-
async uninstallMod(mod: ManifestV2, profile: Profile): Promise<R2Error | null> {
275+
async uninstallMod(mod: ManifestV2, profile: ImmutableProfile): Promise<R2Error | null> {
277276
// Support for installer specific uninstall methods are rolled out
278277
// gradually and therefore might not be defined yet.
279278
try {
@@ -309,7 +308,7 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
309308
* implements a custom uninstallation method.
310309
* @return true if mod loader was uninstalled
311310
*/
312-
async uninstallModLoaderWithInstaller(mod: ManifestV2, profile: Profile): Promise<boolean> {
311+
async uninstallModLoaderWithInstaller(mod: ManifestV2, profile: ImmutableProfile): Promise<boolean> {
313312
const modLoader = this.getModLoader(mod);
314313
const installerId = modLoader ? GetInstallerIdForLoader(modLoader.loaderType) : null;
315314
return this.uninstallWithInstaller(installerId, mod, profile);
@@ -320,15 +319,15 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
320319
* uninstallation method.
321320
* @return true if mod was uninstalled
322321
*/
323-
async uninstallModWithInstaller(mod: ManifestV2, profile: Profile): Promise<boolean> {
322+
async uninstallModWithInstaller(mod: ManifestV2, profile: ImmutableProfile): Promise<boolean> {
324323
const installerId = GetInstallerIdForPlugin(GameManager.activeGame.packageLoader);
325324
return this.uninstallWithInstaller(installerId, mod, profile);
326325
}
327326

328327
private async uninstallWithInstaller(
329328
installerId: PackageInstallerId | null,
330329
mod: ManifestV2,
331-
profile: Profile
330+
profile: ImmutableProfile
332331
): Promise<boolean> {
333332
const installer = installerId ? PackageInstallers[installerId] : undefined;
334333

src/store/modules/ProfileModule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,15 @@ export default {
383383
onProgress?: (mod: ManifestV2) => void,
384384
}
385385
) {
386-
const profile = getters.activeProfileOrThrow;
386+
const profile = getters.activeProfileOrThrow.asImmutableProfile();
387387
await dispatch('uninstallModsFromProfile', {...params, profile});
388388
},
389389

390390
async uninstallModsFromProfile(
391391
{dispatch},
392392
params: {
393393
mods: ManifestV2[],
394-
profile: Profile,
394+
profile: ImmutableProfile,
395395
onProgress?: (mod: ManifestV2) => void,
396396
}
397397
) {
@@ -411,7 +411,7 @@ export default {
411411
// Update mod list status to mods.yml.
412412
// TODO: can performance be improved by implementing
413413
// a .removeMods(mods, profile) and calling it once outside the loop?
414-
const updatedList = await ProfileModList.removeMod(mod, profile.asImmutableProfile());
414+
const updatedList = await ProfileModList.removeMod(mod, profile);
415415
if (updatedList instanceof R2Error) {
416416
throw updatedList;
417417
} else {

test/jest/__tests__/impl/MelonLoader/state.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe("State testing", () => {
7171
const files: [string, string][] = [["cachedFileA", "fileInstallLocationA"], ["cachedFileB", "fileInstallLocationB"]];
7272

7373
sandbox.stub(ProfileProvider.instance);
74-
const profile = new Profile("stub");
74+
const profile = new ImmutableProfile("stub");
7575

7676
const fsStub = sandbox.stub(FsProvider.instance);
7777
FsProvider.provide(() => fsStub);

test/jest/__tests__/impl/install_logic/ReturnOfModding.Tests.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('ReturnOfModding Installer Tests', () => {
2929
await ProfileInstallerProvider.instance.installMod(pkg, Profile.getActiveProfile().asImmutableProfile());
3030
await expectFilesToBeCopied(sourceToExpectedDestination);
3131

32-
const result = await ProfileInstallerProvider.instance.uninstallMod(pkg, Profile.getActiveProfile());
32+
const result = await ProfileInstallerProvider.instance.uninstallMod(pkg, Profile.getActiveProfile().asImmutableProfile());
3333
expect(result instanceof R2Error).toBeFalsy();
3434
await expectFilesToBeRemoved(sourceToExpectedDestination, expectedAfterUninstall);
3535
});
@@ -70,7 +70,7 @@ describe('ReturnOfModding Installer Tests', () => {
7070
await ProfileInstallerProvider.instance.installMod(pkg, Profile.getActiveProfile().asImmutableProfile());
7171
await expectFilesToBeCopied(sourceToExpectedDestination);
7272

73-
const result = await ProfileInstallerProvider.instance.uninstallMod(pkg, Profile.getActiveProfile());
73+
const result = await ProfileInstallerProvider.instance.uninstallMod(pkg, Profile.getActiveProfile().asImmutableProfile());
7474
expect(result instanceof R2Error).toBeFalsy();
7575
await expectFilesToBeRemoved(sourceToExpectedDestination, expectedAfterUninstall);
7676
});
@@ -89,7 +89,7 @@ describe('ReturnOfModding Installer Tests', () => {
8989
await ProfileInstallerProvider.instance.installMod(pkg, Profile.getActiveProfile().asImmutableProfile());
9090
await expectFilesToBeCopied(sourceToExpectedDestination);
9191

92-
const result = await ProfileInstallerProvider.instance.uninstallMod(pkg, Profile.getActiveProfile());
92+
const result = await ProfileInstallerProvider.instance.uninstallMod(pkg, Profile.getActiveProfile().asImmutableProfile());
9393
expect(result instanceof R2Error).toBeFalsy();
9494
await expectFilesToBeRemoved(sourceToExpectedDestination, expectedAfterUninstall);
9595
});

test/jest/__tests__/impl/install_logic/Shimloader.Tests.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Shimloader Installer Tests', () => {
3838
await ProfileInstallerProvider.instance.installMod(pkg, Profile.getActiveProfile().asImmutableProfile());
3939
await expectFilesToBeCopied(sourceToExpectedDestination);
4040

41-
const result = await ProfileInstallerProvider.instance.uninstallMod(pkg, Profile.getActiveProfile());
41+
const result = await ProfileInstallerProvider.instance.uninstallMod(pkg, Profile.getActiveProfile().asImmutableProfile());
4242
expect(result instanceof R2Error).toBeFalsy();
4343
expectFilesToBeRemoved(sourceToExpectedDestination, expectedAfterUninstall)
4444
});

0 commit comments

Comments
 (0)