file update check, also on launch
This commit is contained in:
parent
2c6b51cbb2
commit
d9fec1193e
17
main.js
17
main.js
|
@ -144,17 +144,26 @@ function registerIPCPipes() {
|
||||||
mainWindow.webContents.send("ezpplauncher:launchstatus", {
|
mainWindow.webContents.send("ezpplauncher:launchstatus", {
|
||||||
status: "Checking osu! directory...",
|
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", {
|
mainWindow.webContents.send("ezpplauncher:launchstatus", {
|
||||||
status: "Checking for osu! updates...",
|
status: "Checking for osu! updates...",
|
||||||
});
|
});
|
||||||
mainWindow.webContents.send("ezpplauncher:launchprogress", {
|
await new Promise((res) => setTimeout(res, 1000));
|
||||||
|
/* mainWindow.webContents.send("ezpplauncher:launchprogress", {
|
||||||
progress: 0,
|
progress: 0,
|
||||||
});
|
});
|
||||||
await new Promise((res) => setTimeout(res, 1500));
|
|
||||||
mainWindow.webContents.send("ezpplauncher:launchprogress", {
|
mainWindow.webContents.send("ezpplauncher:launchprogress", {
|
||||||
progress: 100,
|
progress: 100,
|
||||||
});
|
}); */
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,12 @@ window.addEventListener("settings-set", async (e) => {
|
||||||
await ipcRenderer.invoke("ezpplauncher:settings-set", e.detail);
|
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) => {
|
ipcRenderer.addListener("ezpplauncher:alert", (e, args) => {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent("alert", { detail: args }),
|
new CustomEvent("alert", { detail: args }),
|
||||||
|
|
|
@ -52,6 +52,12 @@
|
||||||
launchPercentage.set(progress);
|
launchPercentage.set(progress);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.addEventListener("launchabort", () => {
|
||||||
|
launchPercentage.set(-1);
|
||||||
|
launchStatus.set("");
|
||||||
|
launching.set(false);
|
||||||
|
});
|
||||||
|
|
||||||
window.addEventListener("alert", (e) => {
|
window.addEventListener("alert", (e) => {
|
||||||
console.log((e as CustomEvent).detail);
|
console.log((e as CustomEvent).detail);
|
||||||
const toastMessage = (e as CustomEvent).detail;
|
const toastMessage = (e as CustomEvent).detail;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
|
const checkUpdateURL =
|
||||||
|
"https://osu.ppy.sh/web/check-updates.php?action=check&stream=";
|
||||||
const ignoredOsuEntities = [
|
const ignoredOsuEntities = [
|
||||||
"osu!auth.dll",
|
"osu!auth.dll",
|
||||||
];
|
];
|
||||||
|
@ -37,4 +39,45 @@ async function isValidOsuFolder(path) {
|
||||||
return (Math.round((matches / osuEntities.length) * 100) >= 60);
|
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
7
tests/osuUpdate.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
const { getUpdateFiles } = require("../src/util/osuUtil");
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const osuPath = "";
|
||||||
|
const latestFiles = await getUpdateFiles("stable40");
|
||||||
|
console.log(latestFiles);
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user