file update check, also on launch

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

17
main.js
View File

@ -144,17 +144,26 @@ function registerIPCPipes() {
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Checking osu! directory...",
});
await new Promise((res) => setTimeout(res, 1500));
await new Promise((res) => setTimeout(res, 1000));
const osuPath = config.get("osuPath");
if (!(await isValidOsuFolder(osuPath))) {
mainWindow.webContents.send("ezpplauncher:launchabort");
mainWindow.webContents.send("ezpplauncher:alert", {
type: "error",
message: "invalid osu! path!",
});
return;
}
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Checking for osu! updates...",
});
mainWindow.webContents.send("ezpplauncher:launchprogress", {
await new Promise((res) => setTimeout(res, 1000));
/* mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: 0,
});
await new Promise((res) => setTimeout(res, 1500));
mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: 100,
});
}); */
return true;
});
}

View File

@ -59,6 +59,12 @@ window.addEventListener("settings-set", async (e) => {
await ipcRenderer.invoke("ezpplauncher:settings-set", e.detail);
});
ipcRenderer.addListener("ezpplauncher:launchabort", (e, args) => {
window.dispatchEvent(
new CustomEvent("launch-abort"),
);
});
ipcRenderer.addListener("ezpplauncher:alert", (e, args) => {
window.dispatchEvent(
new CustomEvent("alert", { detail: args }),

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 };

7
tests/osuUpdate.js Normal file
View File

@ -0,0 +1,7 @@
const { getUpdateFiles } = require("../src/util/osuUtil");
(async () => {
const osuPath = "";
const latestFiles = await getUpdateFiles("stable40");
console.log(latestFiles);
})();