Skip to content

Commit

Permalink
Merge pull request #1504 from ebkr/profilemodlist-icon
Browse files Browse the repository at this point in the history
Change the icon paths used when reading a mod list from mods.yml
  • Loading branch information
anttimaki authored Oct 30, 2024
2 parents 63cfe75 + 5631988 commit 3f09e69
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/r2mm/mods/ProfileModList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import FileUtils from '../../utils/FileUtils';
import ManagerInformation from '../../_managerinf/ManagerInformation';
import LinkProvider from '../../providers/components/LinkProvider';
import AsyncLock from 'async-lock';
import GameManager from '../../model/game/GameManager';
import { MOD_LOADER_VARIANTS } from '../installing/profile_installers/ModLoaderVariantRecord';
import FileTree from '../../model/file/FileTree';
import ZipBuilder from '../../providers/generic/zip/ZipBuilder';
import InteractionProvider from '../../providers/ror2/system/InteractionProvider';
Expand Down Expand Up @@ -46,23 +44,7 @@ export default class ProfileModList {
const value = (yaml.parse((await fs.readFile(profile.joinToProfilePath('mods.yml'))).toString()) || []);
for(let modIndex in value){
const mod = new ManifestV2().fromReactive(value[modIndex]);
const fallbackPath = path.join(PathResolver.MOD_ROOT, "cache", mod.getName(), mod.getVersionNumber().toString(), "icon.png");
let iconPath;
if (
MOD_LOADER_VARIANTS[GameManager.activeGame.internalFolderName]
.find(x => x.packageName === mod.getName()) !== undefined
) {
// BepInEx is not a plugin, and so the only place where we can get its icon is from the cache
iconPath = path.resolve(profile.getProfilePath(), "BepInEx", "core", "icon.png");
} else {
iconPath = path.resolve(profile.getProfilePath(), "BepInEx", "plugins", mod.getName(), "icon.png");
}

if (await fs.exists(iconPath)) {
mod.setIcon(iconPath);
} else {
mod.setIcon(fallbackPath);
}
await this.setIconPath(mod, profile);
value[modIndex] = mod;
}
return value;
Expand Down Expand Up @@ -289,4 +271,16 @@ export default class ProfileModList {
return modList.filter(value => !value.isEnabled()).length;
}

public static async setIconPath(mod: ManifestV2, profile: ImmutableProfile): Promise<void> {
let iconPath = path.resolve(profile.getProfilePath(), "BepInEx", "plugins", mod.getName(), "icon.png");

// BepInEx is not a plugin, and so the only place where we can get its icon is from the cache.
// Also non-BepInEx games, e.g. ReturnOfModding games, read the icons from cache. This could
// be fixed using a different path though.
if (!(await FsProvider.instance.exists(iconPath))) {
iconPath = path.join(PathResolver.MOD_ROOT, "cache", mod.getName(), mod.getVersionNumber().toString(), "icon.png");
}

mod.setIcon(iconPath);
}
}

0 comments on commit 3f09e69

Please sign in to comment.