Skip to content

Commit 5631988

Browse files
committed
Extract setting icon path for ManifestV2 into a reusable method
1 parent 3000394 commit 5631988

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/r2mm/mods/ProfileModList.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ export default class ProfileModList {
4444
const value = (yaml.parse((await fs.readFile(profile.joinToProfilePath('mods.yml'))).toString()) || []);
4545
for(let modIndex in value){
4646
const mod = new ManifestV2().fromReactive(value[modIndex]);
47-
let iconPath = path.resolve(profile.getProfilePath(), "BepInEx", "plugins", mod.getName(), "icon.png");
48-
49-
// BepInEx is not a plugin, and so the only place where we can get its icon is from the cache.
50-
// Also non-BepInEx games, e.g. ReturnOfModding games, read the icons from cache. This could
51-
// be fixed using a different path though.
52-
if (!(await fs.exists(iconPath))) {
53-
iconPath = path.join(PathResolver.MOD_ROOT, "cache", mod.getName(), mod.getVersionNumber().toString(), "icon.png");
54-
}
55-
56-
mod.setIcon(iconPath);
47+
await this.setIconPath(mod, profile);
5748
value[modIndex] = mod;
5849
}
5950
return value;
@@ -280,4 +271,16 @@ export default class ProfileModList {
280271
return modList.filter(value => !value.isEnabled()).length;
281272
}
282273

274+
public static async setIconPath(mod: ManifestV2, profile: ImmutableProfile): Promise<void> {
275+
let iconPath = path.resolve(profile.getProfilePath(), "BepInEx", "plugins", mod.getName(), "icon.png");
276+
277+
// BepInEx is not a plugin, and so the only place where we can get its icon is from the cache.
278+
// Also non-BepInEx games, e.g. ReturnOfModding games, read the icons from cache. This could
279+
// be fixed using a different path though.
280+
if (!(await FsProvider.instance.exists(iconPath))) {
281+
iconPath = path.join(PathResolver.MOD_ROOT, "cache", mod.getName(), mod.getVersionNumber().toString(), "icon.png");
282+
}
283+
284+
mod.setIcon(iconPath);
285+
}
283286
}

0 commit comments

Comments
 (0)