launch osu updater before launching to verify all files

This commit is contained in:
2024-01-24 16:31:34 +01:00
parent 8c09719b43
commit 4348c36fa0
4 changed files with 261 additions and 12 deletions

46
main.js
View File

@@ -24,6 +24,7 @@ const {
replaceUIFile,
findOsuInstallation,
updateOsuConfigHashes,
runOsuUpdater,
} = require("./electron/osuUtil");
const { formatBytes } = require("./electron/formattingUtil");
const windowName = require("get-window-by-name");
@@ -34,6 +35,7 @@ const cryptUtil = require("./electron/cryptoUtil");
const { getHwId } = require("./electron/hwidUtil");
const { appName, appVersion } = require("./electron/appInfo");
const { updateAvailable, releasesUrl } = require("./electron/updateCheck");
const fkill = require("fkill");
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
@@ -42,8 +44,9 @@ let osuCheckInterval;
let userOsuPath;
let osuLoaded = false;
let patch = false;
let lastOsuStatus = "";
let lastStatusUpdate;
let terminate = false;
let finishedUpdating = false;
let currentUser = undefined;
@@ -51,6 +54,30 @@ function isDev() {
return !app.isPackaged;
}
async function waitForTermination() {
terminate = true;
return new Promise((res) => {
const checkInterval = setInterval(async () => {
const osuWindowTitle = windowName.getWindowText("osu!.exe");
if (osuWindowTitle.length < 0) {
return;
}
const firstInstance = osuWindowTitle[0];
console.log({ terminate, firstInstance });
if (terminate && finishedUpdating) {
console.log("terminating...");
finishedUpdating = false;
terminate = false;
const processId = firstInstance.processId;
await fkill(processId, { force: true, silent: true });
clearInterval(checkInterval);
res();
console.log("terminated");
}
}, 500);
});
}
function startOsuStatus() {
osuCheckInterval = setInterval(async () => {
const osuWindowTitle = windowName.getWindowText("osu!.exe");
@@ -58,7 +85,9 @@ function startOsuStatus() {
return;
}
const firstInstance = osuWindowTitle[0];
if (firstInstance) {
console.log(osuWindowTitle);
if (!osuLoaded) {
osuLoaded = true;
setTimeout(() => {
@@ -477,9 +506,22 @@ function registerIPCPipes() {
await new Promise((res) => setTimeout(res, 1000));
}
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Launching osu updater to verify...",
});
await new Promise((res) => setTimeout(res, 1000));
runOsuUpdater(osuPath, () => {
finishedUpdating = true;
});
await waitForTermination();
await new Promise((res) => setTimeout(res, 1000));
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Preparing launch...",
});
await updateOsuConfigHashes(osuPath);
await replaceUIFile(osuPath, false);