Skip to content

Commit cec82da

Browse files
committed
Icon handling
1 parent 40f055c commit cec82da

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ latest.log
4545
/www/mods/shibahoodiekel
4646
/www/mods/nekomori
4747
/www/mods/dragndrop (11).zip
48-
/.oneloader-image-cache
48+
/.oneloader-image-cache
49+
/www/l

www/modloader/early_loader.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@
492492
files: this.files,
493493
plugins: this.plugins,
494494
pluginsDelta: this.pluginsDelta,
495-
imageDelta: this.imageDelta
495+
imageDelta: this.imageDelta,
496+
_raw: this
496497
};
497498
}
498499
}
@@ -534,7 +535,8 @@
534535
files: this.files,
535536
plugins: this.plugins,
536537
pluginsDelta: this.pluginsDelta,
537-
imageDelta: this.imageDelta
538+
imageDelta: this.imageDelta,
539+
_raw: this
538540
};
539541
}
540542
}

www/mods/oneloader/mod.json

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
{
2929
"file":"oneloader-update-installer.js",
3030
"runat":"pre_stage_2"
31+
},
32+
{
33+
"file":"oneloader-icon-handler.js",
34+
"runat":"pre_stage_2"
3135
}
3236
]
3337
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const base = path.dirname(process.mainModule.filename);
4+
const hash = a => require('crypto').createHash('sha256').update(a).digest('hex');
5+
6+
if (!fs.existsSync(path.join(base, "icon", "icon-oneloader-backup.png"))) {
7+
fs.writeFileSync(
8+
path.join(base, "icon", "icon-oneloader-backup.png"),
9+
fs.readFileSync(path.join(base, "icon", "icon.png"))
10+
);
11+
}
12+
13+
let ki = [];
14+
for (let [key, value] of params.knownMods.entries()) {
15+
if (value.json.game_icon) {
16+
ki.push(await value._raw.readFile(value.json.game_icon));
17+
}
18+
}
19+
20+
if (ki.length > 1) {
21+
ki = [];
22+
alert("More than 1 mod wants to change game icon, will use default");
23+
}
24+
25+
26+
let currIconHash = hash(fs.readFileSync(path.join(base, "icon", "icon.png")));
27+
28+
if (ki.length < 1) {
29+
let backupHash = hash(fs.readFileSync(path.join(base, "icon", "icon-oneloader-backup.png")));
30+
if (currIconHash != backupHash) {
31+
fs.writeFileSync(
32+
path.join(base, "icon", "icon.png"),
33+
fs.readFileSync(path.join(base, "icon", "icon-oneloader-backup.png"))
34+
);
35+
chrome.runtime.reload();
36+
}
37+
} else {
38+
let candidateHash = hash(ki[0]);
39+
if (currIconHash != candidateHash) {
40+
fs.writeFileSync(
41+
path.join(base, "icon", "icon.png"),
42+
ki[0]
43+
);
44+
chrome.runtime.reload();
45+
}
46+
}

0 commit comments

Comments
 (0)