Skip to content

Commit

Permalink
Ensure manifest.json is present in all locally imported mods
Browse files Browse the repository at this point in the history
Create a manifest.json file into cache folder if one wasn't provided by
the uploaded zip, or if a .dll file was uploaded. For consistency we
want all installed mods to have this file regardless of the
installation method.

Locally installed mods will still have the separate mm_v2_manifest.json
file so they can be told apart from the files downloaded from
Thunderstore.
  • Loading branch information
anttimaki committed Feb 18, 2025
1 parent 1172d43 commit 9f86cfe
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/r2mm/installing/LocalModInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,32 @@ export default class LocalModInstaller extends LocalModInstallerProvider {
await FsProvider.instance.writeFile(manifestPath, JSON.stringify(manifest));
}

/**
* Write Thunderstore compatible manifest.json to cache if one wasn't provided
* with the upload. This is done to have to have consistency between all
* installed mods, regardless of how they were installed. Having the manifest
* present allows other mods to sniff out what other mods are installed.
*/
private async writeManifestToCache(cacheDirectory: string, manifest: ManifestV2) {
const manifestPath: string = path.join(cacheDirectory, 'manifest.json');

if (!(await FsProvider.instance.exists(manifestPath))) {
const content = {
'name': manifest.getDisplayName(), // getName() returns "author-modname" here
'description': manifest.getDescription(),
'version_number': manifest.getVersionNumber().toString(),
'dependencies': manifest.getDependencies(),
'website_url': ''
};

await FsProvider.instance.writeFile(manifestPath, JSON.stringify(content, null, 4));
}
}

public async extractToCacheWithManifestData(profile: ImmutableProfile, zipFile: string, manifest: ManifestV2) {
const cacheDirectory: string = await this.initialiseCacheDirectory(manifest);
await ZipExtract.extractOnly(zipFile, cacheDirectory);
await this.writeManifestToCache(cacheDirectory, manifest);
await this.writeCustomManifestToCache(cacheDirectory, manifest);
await ProfileInstallerProvider.instance.uninstallMod(manifest, profile);
throwForR2Error(await ProfileInstallerProvider.instance.installMod(manifest, profile));
Expand All @@ -56,6 +79,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider {
const cacheDirectory: string = await this.initialiseCacheDirectory(manifest);
const fileSafe = file.split("\\").join("/");
await FsProvider.instance.copyFile(fileSafe, path.join(cacheDirectory, path.basename(fileSafe)));
await this.writeManifestToCache(cacheDirectory, manifest);
await this.writeCustomManifestToCache(cacheDirectory, manifest);
} catch (e) {
throw R2Error.fromThrownValue(e, "Error moving file to cache");
Expand Down

0 comments on commit 9f86cfe

Please sign in to comment.