Skip to content

Commit

Permalink
Merge pull request #1591 from ebkr/icon-fallback
Browse files Browse the repository at this point in the history
Use fallback image if mod icon isn't found on disk
  • Loading branch information
anttimaki authored Jan 15, 2025
2 parents b64a321 + 8e87402 commit fb73945
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/r2mm/mods/ProfileModList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import ZipBuilder from '../../providers/generic/zip/ZipBuilder';
import InteractionProvider from '../../providers/ror2/system/InteractionProvider';
import { ProfileApiClient } from '../profiles/ProfilesClient';

const FALLBACK_ICON = require("../../../public/unknown.png");

export default class ProfileModList {

public static SUPPORTED_CONFIG_FILE_EXTENSIONS = [".cfg", ".txt", ".json", ".yml", ".yaml", ".ini"];
Expand Down Expand Up @@ -280,15 +282,18 @@ export default class ProfileModList {
}

public static async setIconPath(mod: ManifestV2, profile: ImmutableProfile): Promise<void> {
let iconPath = path.resolve(profile.getProfilePath(), "BepInEx", "plugins", mod.getName(), "icon.png");
const paths = [
path.resolve(profile.getProfilePath(), "BepInEx", "plugins", mod.getName(), "icon.png"),
path.join(PathResolver.MOD_ROOT, "cache", mod.getName(), mod.getVersionNumber().toString(), "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");
for (const iconPath of paths) {
if (await FsProvider.instance.exists(iconPath)) {
mod.setIcon(iconPath);
return;
}
}

mod.setIcon(iconPath);
mod.setIcon(FALLBACK_ICON);
}
}

0 comments on commit fb73945

Please sign in to comment.