file update check, also on launch

This commit is contained in:
2024-01-12 16:10:19 +01:00
parent 2c6b51cbb2
commit d9fec1193e
5 changed files with 76 additions and 5 deletions

View File

@@ -52,6 +52,12 @@
launchPercentage.set(progress);
});
window.addEventListener("launchabort", () => {
launchPercentage.set(-1);
launchStatus.set("");
launching.set(false);
});
window.addEventListener("alert", (e) => {
console.log((e as CustomEvent).detail);
const toastMessage = (e as CustomEvent).detail;

View File

@@ -1,6 +1,8 @@
const fs = require("fs");
const path = require("path");
const checkUpdateURL =
"https://osu.ppy.sh/web/check-updates.php?action=check&stream=";
const ignoredOsuEntities = [
"osu!auth.dll",
];
@@ -37,4 +39,45 @@ async function isValidOsuFolder(path) {
return (Math.round((matches / osuEntities.length) * 100) >= 60);
}
module.exports = { isValidOsuFolder };
async function getUserConfig(osuPath) {
const configFileInfo = {
name: "",
path: "",
get: async (key) => {
if (!configFileInfo.path) {
return "";
}
const fileStream = await fs.promises.readFile(
configFileInfo.path,
"utf-8",
);
const lines = fileStream.split(/\r?\n/);
for (const line of lines) {
if (line.includes(" = ")) {
const argsPair = line.split(" = ", 2);
const keyname = argsPair[0];
const value = argsPair[1];
if (keyname == key) {
return value;
}
}
}
},
};
const userOsuConfig = path.join(
osuPath,
`osu!.${process.env["USERNAME"]}.cfg`,
);
if (fs.existsSync(userOsuConfig)) {
configFileInfo.name = `osu!.${process.env["USERNAME"]}.cfg`;
configFileInfo.path = userOsuConfig;
}
return configFileInfo;
}
async function getUpdateFiles(releaseStream) {
const releaseData = await fetch(checkUpdateURL + releaseStream);
return releaseData.ok ? await releaseData.json() : undefined;
}
module.exports = { isValidOsuFolder, getUserConfig, getUpdateFiles };