Skip to content

Commit

Permalink
Merge pull request ebkr#1636 from ebkr/local-import-manifest
Browse files Browse the repository at this point in the history
Ensure manifest.json is present in all locally imported mods
  • Loading branch information
anttimaki authored Feb 19, 2025
2 parents 90b804a + bb1b9fb commit b81777e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/r2mm/installing/LocalModInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider {
* be used in troubleshooting, telling us that the version of the mod isn't
* necessarily the same that's available via Thunderstore API.
*/
private async writeManifestToCache(cacheDirectory: string, manifest: ManifestV2) {
private async writeCustomManifestToCache(cacheDirectory: string, manifest: ManifestV2) {
const manifestPath: string = path.join(cacheDirectory, 'mm_v2_manifest.json');

if (await FsProvider.instance.exists(manifestPath)) {
Expand All @@ -42,10 +42,33 @@ 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 consistency between all installed
* mods, regardless of how they were installed. Having the manifest present
* allows e.g. 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));
throwForR2Error(await ProfileModList.addMod(manifest, profile));
Expand All @@ -57,6 +80,7 @@ export default class LocalModInstaller extends LocalModInstallerProvider {
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 b81777e

Please sign in to comment.