From 5ba2cad5adc918ed40b8ca76e6e5c9945b6b9f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4ki?= Date: Wed, 7 Feb 2024 13:49:17 +0200 Subject: [PATCH] Remove Mod class The class was no longer used directly, only by ThunderstoreVersion which extends it. Relevant attributes and getters/setters were moved to ThunderstoreVersion definition. Mod.fromManifest was dropped since it's not used and did return a Mod object anyway. --- src/model/Mod.ts | 90 -------------------------------- src/model/ThunderstoreVersion.ts | 78 +++++++++++++++++++++++++-- src/r2mm/mods/ModFromManifest.ts | 59 --------------------- 3 files changed, 75 insertions(+), 152 deletions(-) delete mode 100644 src/model/Mod.ts delete mode 100644 src/r2mm/mods/ModFromManifest.ts diff --git a/src/model/Mod.ts b/src/model/Mod.ts deleted file mode 100644 index 3c8a4d5e3..000000000 --- a/src/model/Mod.ts +++ /dev/null @@ -1,90 +0,0 @@ -import VersionNumber from './VersionNumber'; -import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter'; -import ModFromManifest from '../r2mm/mods/ModFromManifest'; -import R2Error from './errors/R2Error'; - -export default class Mod implements ReactiveObjectConverterInterface { - private name: string = ''; - private versionNumber: VersionNumber = new VersionNumber('0.0.0'); - private dependencies: string[] = []; - private fullName: string = ''; - private description: string = '' - private icon: string = '' - private enabled: boolean = true; - - public async fromManifest(): Promise { - return await ModFromManifest.get(this.getFullName(), this.getVersionNumber()); - } - - public fromReactive(reactive: any): Mod { - this.setName(reactive.name); - this.setVersionNumber(new VersionNumber('0.0.0').fromReactive(reactive.versionNumber)); - this.setDependencies(reactive.dependencies); - this.setFullName(reactive.fullName); - this.setDescription(reactive.description); - this.setIcon(reactive.icon); - this.enabled = reactive.enabled; - return this; - } - - public getName(): string { - return this.name; - } - - public setName(name: string) { - this.name = name; - } - - public getVersionNumber(): VersionNumber { - return this.versionNumber; - } - - public setVersionNumber(versionNumber: VersionNumber) { - this.versionNumber = versionNumber; - } - - public getDependencies(): string[] { - return this.dependencies; - } - - public setDependencies(dependencies: string[]) { - this.dependencies = dependencies; - } - - public getFullName(): string { - return this.fullName; - } - - public setFullName(name: string) { - this.fullName = name; - } - - public getDescription(): string { - return this.description; - } - - public setDescription(description: string) { - this.description = description; - } - - public getIcon(): string { - return this.icon; - } - - public setIcon(icon: string) { - this.icon = icon; - } - - public isEnabled(): boolean { - return this.enabled; - } - - public enable() { - this.enabled = true; - } - - public disable() { - this.enabled = false; - } - -} diff --git a/src/model/ThunderstoreVersion.ts b/src/model/ThunderstoreVersion.ts index 586fcb740..c5d526a34 100644 --- a/src/model/ThunderstoreVersion.ts +++ b/src/model/ThunderstoreVersion.ts @@ -1,10 +1,16 @@ -import Mod from './Mod'; import VersionNumber from './VersionNumber'; import ReactiveObjectConverterInterface from './safety/ReactiveObjectConverter'; import CdnProvider from '../providers/generic/connection/CdnProvider'; -export default class ThunderstoreVersion extends Mod implements ReactiveObjectConverterInterface { +export default class ThunderstoreVersion implements ReactiveObjectConverterInterface { + private name: string = ''; + private versionNumber: VersionNumber = new VersionNumber('0.0.0'); + private dependencies: string[] = []; + private fullName: string = ''; + private description: string = '' + private icon: string = '' + private enabled: boolean = true; private downloads: number = 0; private downloadUrl: string = ''; @@ -21,12 +27,78 @@ export default class ThunderstoreVersion extends Mod implements ReactiveObjectCo } public fromReactive(reactive: any): ThunderstoreVersion { - super.fromReactive(reactive); + this.setName(reactive.name); + this.setVersionNumber(new VersionNumber('0.0.0').fromReactive(reactive.versionNumber)); + this.setDependencies(reactive.dependencies); + this.setFullName(reactive.fullName); + this.setDescription(reactive.description); + this.setIcon(reactive.icon); + this.enabled = reactive.enabled; this.setDownloadCount(reactive.downloadCount); this.setDownloadUrl(reactive.downloadUrl); return this; } + public getName(): string { + return this.name; + } + + public setName(name: string) { + this.name = name; + } + + public getVersionNumber(): VersionNumber { + return this.versionNumber; + } + + public setVersionNumber(versionNumber: VersionNumber) { + this.versionNumber = versionNumber; + } + + public getDependencies(): string[] { + return this.dependencies; + } + + public setDependencies(dependencies: string[]) { + this.dependencies = dependencies; + } + + public getFullName(): string { + return this.fullName; + } + + public setFullName(name: string) { + this.fullName = name; + } + + public getDescription(): string { + return this.description; + } + + public setDescription(description: string) { + this.description = description; + } + + public getIcon(): string { + return this.icon; + } + + public setIcon(icon: string) { + this.icon = icon; + } + + public isEnabled(): boolean { + return this.enabled; + } + + public enable() { + this.enabled = true; + } + + public disable() { + this.enabled = false; + } + public getDownloadCount(): number { return this.downloads; } diff --git a/src/r2mm/mods/ModFromManifest.ts b/src/r2mm/mods/ModFromManifest.ts deleted file mode 100644 index e7290a58e..000000000 --- a/src/r2mm/mods/ModFromManifest.ts +++ /dev/null @@ -1,59 +0,0 @@ -import VersionNumber from '../../model/VersionNumber'; - -import * as yaml from 'yaml'; -import * as path from 'path'; -import Mod from '../../model/Mod'; -import YamlParseError from '../../model/errors/Yaml/YamlParseError'; -import FileNotFoundError from '../../model/errors/FileNotFoundError'; -import R2Error from '../../model/errors/R2Error'; -import PathResolver from '../manager/PathResolver'; -import FsProvider from '../../providers/generic/file/FsProvider'; - -const cacheDirectory: string = path.join(PathResolver.MOD_ROOT, 'cache'); - -export default class ModFromManifest { - - public static async get(modName: string, versionNumber: VersionNumber): Promise { - const fs = FsProvider.instance; - try { - const buf: Buffer = await fs.readFile( - path.join(cacheDirectory, modName, versionNumber.toString(), 'manifest.json') - ); - try { - const modManifest: any = yaml.parse(buf.toString()); - const mod: Mod = new Mod(); - mod.setName(modManifest.name); - mod.setVersionNumber(new VersionNumber(modManifest.version_number)); - mod.setDescription(modManifest.description); - mod.setDependencies(modManifest.dependencies); - mod.setFullName(modName); - try { - mod.setIcon(path.join(cacheDirectory, modName, versionNumber.toString(), 'icon.png')); - } catch(e) { - const err: Error = e as Error; - return new FileNotFoundError( - `Unable to locate icon.png for mod: ${modName}`, - err.message, - null - ); - } - return mod; - } catch(e) { - const err: Error = e as Error; - return new YamlParseError( - `Failed to parse manifest of mod: ${modName}`, - err.message, - null - ); - } - } catch(e) { - const err: Error = e as Error; - return new FileNotFoundError( - `Error reading manifest file of mod: ${modName}`, - err.message, - null - ); - } - } - -}