Skip to content

Commit fb73945

Browse files
authored
Merge pull request #1591 from ebkr/icon-fallback
Use fallback image if mod icon isn't found on disk
2 parents b64a321 + 8e87402 commit fb73945

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Diff for: src/r2mm/mods/ProfileModList.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import ZipBuilder from '../../providers/generic/zip/ZipBuilder';
2222
import InteractionProvider from '../../providers/ror2/system/InteractionProvider';
2323
import { ProfileApiClient } from '../profiles/ProfilesClient';
2424

25+
const FALLBACK_ICON = require("../../../public/unknown.png");
26+
2527
export default class ProfileModList {
2628

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

282284
public static async setIconPath(mod: ManifestV2, profile: ImmutableProfile): Promise<void> {
283-
let iconPath = path.resolve(profile.getProfilePath(), "BepInEx", "plugins", mod.getName(), "icon.png");
285+
const paths = [
286+
path.resolve(profile.getProfilePath(), "BepInEx", "plugins", mod.getName(), "icon.png"),
287+
path.join(PathResolver.MOD_ROOT, "cache", mod.getName(), mod.getVersionNumber().toString(), "icon.png"),
288+
]
284289

285-
// BepInEx is not a plugin, and so the only place where we can get its icon is from the cache.
286-
// Also non-BepInEx games, e.g. ReturnOfModding games, read the icons from cache. This could
287-
// be fixed using a different path though.
288-
if (!(await FsProvider.instance.exists(iconPath))) {
289-
iconPath = path.join(PathResolver.MOD_ROOT, "cache", mod.getName(), mod.getVersionNumber().toString(), "icon.png");
290+
for (const iconPath of paths) {
291+
if (await FsProvider.instance.exists(iconPath)) {
292+
mod.setIcon(iconPath);
293+
return;
294+
}
290295
}
291296

292-
mod.setIcon(iconPath);
297+
mod.setIcon(FALLBACK_ICON);
293298
}
294299
}

0 commit comments

Comments
 (0)