Skip to content

Commit 280852c

Browse files
committed
Drop PackageInstallerV2 class
Based on code review feedback, implement the uninstallation methods as optional methods, rather than have a separate version of the abstract class with more abstract methods. Replace the approach with abstract classes and methods with a plain TypeScript interface because having optional methods in abstract classes seems poorly supported in TypeScript.
1 parent de5c003 commit 280852c

10 files changed

+23
-28
lines changed

src/installers/BepInExInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PackageLoader } from "../model/installing/PackageLoader";
66

77
const basePackageFiles = ["manifest.json", "readme.md", "icon.png"];
88

9-
export class BepInExInstaller extends PackageInstaller {
9+
export class BepInExInstaller implements PackageInstaller {
1010
/**
1111
* Handles installation of BepInEx
1212
*/

src/installers/GodotMLInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { InstallArgs, PackageInstaller } from "./PackageInstaller";
22
import path from "path";
33
import FsProvider from "../providers/generic/file/FsProvider";
44

5-
export class GodotMLInstaller extends PackageInstaller {
5+
export class GodotMLInstaller implements PackageInstaller {
66
/**
77
* Handles installation of GodotML
88
*/

src/installers/InstallRuleInstaller.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,10 @@ async function installState(args: InstallRuleArgs) {
215215
await addToStateFile(mod, fileRelocations, profile);
216216
}
217217

218-
export class InstallRuleInstaller extends PackageInstaller {
218+
export class InstallRuleInstaller implements PackageInstaller {
219219
public readonly rule: CoreRuleType;
220220

221221
constructor(rules: CoreRuleType) {
222-
super();
223222
this.rule = rules;
224223
}
225224

src/installers/LovelyInstaller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import FileTree from "../model/file/FileTree";
66
import R2Error from "../model/errors/R2Error";
77
import path from "path";
88

9-
export class LovelyInstaller extends PackageInstaller {
9+
export class LovelyInstaller implements PackageInstaller {
1010
async install(args: InstallArgs) {
1111
const {
1212
mod,
@@ -45,7 +45,7 @@ export class LovelyInstaller extends PackageInstaller {
4545
}
4646
}
4747

48-
export class LovelyPluginInstaller extends PackageInstaller {
48+
export class LovelyPluginInstaller implements PackageInstaller {
4949
async install(args: InstallArgs) {
5050
const {
5151
mod,

src/installers/MelonLoaderInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "path";
44

55
const basePackageFiles = ["manifest.json", "readme.md", "icon.png"];
66

7-
export class MelonLoaderInstaller extends PackageInstaller {
7+
export class MelonLoaderInstaller implements PackageInstaller {
88
/**
99
* Handles installation of MelonLoader
1010
*/

src/installers/NorthstarInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PackageLoader } from '../model/installing/PackageLoader';
66

77
const basePackageFiles = ["manifest.json", "readme.md", "icon.png"];
88

9-
export class NorthstarInstaller extends PackageInstaller {
9+
export class NorthstarInstaller implements PackageInstaller {
1010
/**
1111
* Handles installation of Northstar
1212
*/

src/installers/PackageInstaller.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import Profile from "../model/Profile";
22
import ManifestV2 from "../model/ManifestV2";
33

4-
54
export type InstallArgs = {
65
mod: ManifestV2;
76
profile: Profile;
87
packagePath: string;
98
};
109

11-
12-
export abstract class PackageInstaller {
13-
abstract install(args: InstallArgs): Promise<void>;
14-
// abstract disable(args: InstallArgs): Promise<void>; // TODO: Implement
15-
}
16-
17-
18-
export abstract class PackageInstallerV2 extends PackageInstaller {
19-
abstract uninstall(args: InstallArgs): Promise<void>;
10+
export interface PackageInstaller {
11+
install(args: InstallArgs): Promise<void>;
12+
uninstall?(args: InstallArgs): Promise<void>;
2013
}

src/installers/ReturnOfModdingInstaller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from "path";
22

33
import { InstallRuleInstaller } from "./InstallRuleInstaller";
4-
import { InstallArgs, PackageInstallerV2 } from "./PackageInstaller";
4+
import { InstallArgs, PackageInstaller } from "./PackageInstaller";
55
import FileWriteError from "../model/errors/FileWriteError";
66
import { PackageLoader } from "../model/installing/PackageLoader";
77
import FsProvider from "../providers/generic/file/FsProvider";
@@ -13,7 +13,7 @@ const basePackageFiles = ["manifest.json", "readme.md", "icon.png"];
1313
/**
1414
* Handles (un)installation of ReturnOfModding mod loader
1515
*/
16-
export class ReturnOfModdingInstaller extends PackageInstallerV2 {
16+
export class ReturnOfModdingInstaller implements PackageInstaller {
1717
async install(args: InstallArgs) {
1818
const {mod, packagePath, profile} = args;
1919

@@ -64,7 +64,7 @@ export class ReturnOfModdingInstaller extends PackageInstallerV2 {
6464
/**
6565
* Handles (un)installation of mods that use ReturnOfModding mod loader
6666
*/
67-
export class ReturnOfModdingPluginInstaller extends PackageInstallerV2 {
67+
export class ReturnOfModdingPluginInstaller implements PackageInstaller {
6868
_ROOT = "ReturnOfModding";
6969
_PLUGINS = "plugins";
7070
_DATA = "plugins_data";

src/installers/ShimloaderInstaller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import FileUtils from "../utils/FileUtils";
66
import R2Error from "../model/errors/R2Error";
77
import { InstallRuleInstaller } from "./InstallRuleInstaller";
88

9-
export class ShimloaderInstaller extends PackageInstaller {
9+
export class ShimloaderInstaller implements PackageInstaller {
1010
/**
1111
* Handle installation of unreal-shimloader
1212
*/
@@ -55,7 +55,7 @@ export class ShimloaderInstaller extends PackageInstaller {
5555
}
5656
}
5757

58-
export class ShimloaderPluginInstaller extends PackageInstaller {
58+
export class ShimloaderPluginInstaller implements PackageInstaller {
5959
readonly installer = new InstallRuleInstaller({
6060
gameName: "none" as any, // This isn't acutally used for actual installation but needs some value
6161
rules: [

src/r2mm/installing/profile_installers/GenericProfileInstaller.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import FileWriteError from '../../../model/errors/FileWriteError';
1818
import FileUtils from '../../../utils/FileUtils';
1919
import { GetInstallerIdForLoader, GetInstallerIdForPlugin } from '../../../model/installing/PackageLoader';
2020
import { PackageInstallerId, PackageInstallers } from "../../../installers/registry";
21-
import { InstallArgs, PackageInstallerV2 } from "../../../installers/PackageInstaller";
21+
import { InstallArgs } from "../../../installers/PackageInstaller";
2222
import { InstallRuleInstaller } from "../../../installers/InstallRuleInstaller";
2323
import { ShimloaderPluginInstaller } from "../../../installers/ShimloaderInstaller";
2424
import { ReturnOfModdingPluginInstaller } from "../../../installers/ReturnOfModdingInstaller";
@@ -289,7 +289,8 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
289289
}
290290

291291
async uninstallMod(mod: ManifestV2, profile: Profile): Promise<R2Error | null> {
292-
// Implementations of PackageInstallerV2 define their own uninstallation logic.
292+
// Support for installer specific uninstall methods are rolled out
293+
// gradually and therefore might not be defined yet.
293294
try {
294295
if (
295296
await this.uninstallModLoaderWithInstaller(mod, profile) ||
@@ -319,7 +320,8 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
319320
}
320321

321322
/**
322-
* Uninstall mod if it's a registered mod loader with PackageInstallerV2 implementation
323+
* Uninstall mod if it's a registered mod loader and the installer class
324+
* implements a custom uninstallation method.
323325
* @return true if mod loader was uninstalled
324326
*/
325327
async uninstallModLoaderWithInstaller(mod: ManifestV2, profile: Profile): Promise<boolean> {
@@ -329,7 +331,8 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
329331
}
330332

331333
/**
332-
* Uninstall mod if its registered installer implements PackageInstallerV2
334+
* Uninstall mod if its registered installer implements a custom
335+
* uninstallation method.
333336
* @return true if mod was uninstalled
334337
*/
335338
async uninstallModWithInstaller(mod: ManifestV2, profile: Profile): Promise<boolean> {
@@ -344,7 +347,7 @@ export default class GenericProfileInstaller extends ProfileInstallerProvider {
344347
): Promise<boolean> {
345348
const installer = installerId ? PackageInstallers[installerId] : undefined;
346349

347-
if (installer && installer instanceof PackageInstallerV2) {
350+
if (installer && installer.uninstall) {
348351
const args = this.getInstallArgs(mod, profile);
349352
await installer.uninstall(args);
350353
return true;

0 commit comments

Comments
 (0)