diff --git a/electron/osuUtil.js b/electron/osuUtil.js index 962b2d2..0cbecaa 100644 --- a/electron/osuUtil.js +++ b/electron/osuUtil.js @@ -9,6 +9,7 @@ const checkUpdateURL = "https://osu.ppy.sh/web/check-updates.php?action=check&stream="; const ignoredOsuEntities = [ "osu!auth.dll", + "osu!.exe" ]; const osuEntities = [ "avcodec-51.dll", @@ -266,7 +267,7 @@ async function getPatcherUpdates(osuPath) { ).digest("hex"); if ( latestPatchFileHash.trim().toLowerCase() != - localPatchFileHash.trim().toLowerCase() + localPatchFileHash.trim().toLowerCase() ) filesToDownload.push(patcherFile); } else filesToDownload.push(patcherFile); } @@ -331,7 +332,7 @@ async function getUIFiles(osuPath) { ).digest("hex"); if ( latestPatchFileHash.trim().toLowerCase() != - localPatchFileHash.trim().toLowerCase() + localPatchFileHash.trim().toLowerCase() ) filesToDownload.push(uiFile); } else filesToDownload.push(uiFile); } @@ -413,17 +414,43 @@ async function findOsuInstallation() { value = value.substring(1, value.length - 3); return path.dirname(value.trim()); } - /* const osuStruct = await regedit.listValuesSync(osuLocationFromDefaultIcon); - for (const line of osuStruct.split("\n")) { - if (line.includes("REG_SZ")) { - let value = line.trim().split(" ")[2]; - value = value.substring(1, value.length - 3); - return path.dirname(value.trim()); - } - } */ return undefined; } + + +async function updateOsuConfigHashes(osuPath) { + const osuCfg = path.join(osuPath, "osu!.cfg"); + const fileStream = await fs.promises.readFile(osuCfg, "utf-8"); + const lines = fileStream.split(/\r?\n/); + const newLines = []; + for (const line of lines) { + if (line.includes(" = ")) { + const argsPair = line.split(" = ", 2); + const key = argsPair[0]; + const value = argsPair[1]; + + if (key.startsWith("h_")) { + const fileName = key.substring(2, key.length); + const filePath = path.join(osuPath, fileName); + if (!fs.existsSync(filePath)) continue; + const binaryFileContents = await fs.promises.readFile(filePath); + const existingFileMD5 = crypto.createHash("md5").update(binaryFileContents).digest("hex"); + if (value == existingFileMD5) newLines.push(line); + else newLines.push(`${key} = ${existingFileMD5}`); + } else if (line.startsWith("u_UpdaterAutoStart")) { + newLines.push(`${key} = 0`); + } else { + newLines.push(line); + } + } else { + newLines.push(line); + } + } + + await fs.promises.writeFile(osuCfg, newLines.join("\n"), 'utf-8'); +} + module.exports = { isValidOsuFolder, getUserConfig, @@ -438,4 +465,5 @@ module.exports = { getUIFiles, replaceUIFile, findOsuInstallation, + updateOsuConfigHashes }; diff --git a/electron/richPresence.js b/electron/richPresence.js index 48eac62..a3d8353 100644 --- a/electron/richPresence.js +++ b/electron/richPresence.js @@ -1,12 +1,9 @@ const DiscordRPC = require("discord-auto-rpc"); const { appName, appVersion } = require("./appInfo.js"); -const { get } = require("./config.js"); const clientId = "1032772293220384808"; let richPresence; - -let showPresence = true; -let cleared = false; +let intervalId let currentStatus = { details: " ", @@ -31,30 +28,21 @@ let currentStatus = { module.exports = { connect: () => { + console.log("Connecting to Discord..."); if (!richPresence) { richPresence = new DiscordRPC.AutoClient({ transport: "ipc" }); richPresence.endlessLogin({ clientId }); richPresence.once("ready", () => { - setInterval(() => { - const settingPresence = get("presence"); - showPresence = settingPresence != undefined - ? settingPresence.val == "true" - : true; - - if (showPresence) { - richPresence.setActivity(currentStatus); - cleared = false; - } else { - if (cleared) return; - cleared = true; - richPresence.clearActivity(); - } + richPresence.setActivity(currentStatus); + intervalId = setInterval(() => { + richPresence.setActivity(currentStatus); }, 2500); }); } }, disconnect: async () => { if (richPresence) { + clearInterval(intervalId); await richPresence.clearActivity(); await richPresence.destroy(); richPresence = null; @@ -69,7 +57,7 @@ module.exports = { currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " "; }, update: () => { - if (showPresence) { + if (richPresence) { richPresence.setActivity(currentStatus); } }, diff --git a/main.js b/main.js index 23fe689..4b07bec 100644 --- a/main.js +++ b/main.js @@ -21,6 +21,7 @@ const { downloadUIFiles, replaceUIFile, findOsuInstallation, + updateOsuConfigHashes, } = require("./electron/osuUtil"); const { formatBytes } = require("./electron/formattingUtil"); const windowName = require("get-window-by-name"); @@ -269,6 +270,12 @@ function registerIPCPipes() { ipcMain.handle("ezpplauncher:setting-update", async (e, args) => { for (const key of Object.keys(args)) { const value = args[key]; + + if (key == "presence") { + if (!value) richPresence.disconnect(); + else richPresence.connect(); + } + if (typeof value == "boolean") { config.set(key, value ? "true" : "false"); } else { @@ -314,7 +321,7 @@ function registerIPCPipes() { ipcMain.handle("ezpplauncher:launch", async (e) => { const configPatch = config.get("patch"); - patch = configPatch != undefined ? configPatch.val == "true" : true; + patch = configPatch != undefined ? configPatch == "true" : true; mainWindow.webContents.send("ezpplauncher:launchstatus", { status: "Checking osu! directory...", }); @@ -362,9 +369,8 @@ function registerIPCPipes() { progress: Math.ceil(data.progress), }); mainWindow.webContents.send("ezpplauncher:launchstatus", { - status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ - formatBytes(data.total) - })...`, + status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total) + })...`, }); }); await uiDownloader.startDownload(); @@ -393,9 +399,8 @@ function registerIPCPipes() { progress: Math.ceil(data.progress), }); mainWindow.webContents.send("ezpplauncher:launchstatus", { - status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ - formatBytes(data.total) - })...`, + status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total) + })...`, }); }); await updateDownloader.startDownload(); @@ -440,9 +445,8 @@ function registerIPCPipes() { progress: Math.ceil(data.progress), }); mainWindow.webContents.send("ezpplauncher:launchstatus", { - status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ - formatBytes(data.total) - })...`, + status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total) + })...`, }); }); await patcherDownloader.startDownload(); @@ -467,6 +471,8 @@ function registerIPCPipes() { mainWindow.webContents.send("ezpplauncher:launchstatus", { status: "Preparing launch...", }); + await updateOsuConfigHashes(osuPath); + await replaceUIFile(osuPath, false); const userConfig = getUserConfig(osuPath); richPresence.updateVersion(await userConfig.get("LastVersion")); @@ -499,7 +505,6 @@ function registerIPCPipes() { mainWindow.webContents.send("ezpplauncher:launchabort"); }, 5000); }; - await replaceUIFile(osuPath, false); runOsuWithDevServer(osuPath, "ez-pp.farm", onExitHook); mainWindow.hide(); startOsuStatus(); @@ -551,14 +556,22 @@ function createWindow() { } registerIPCPipes(); - richPresence.connect(); + + const presenceEnabled = config.get("presence"); + if (presenceEnabled == undefined) + richPresence.connect(); + else { + console.log(presenceEnabled); + if (presenceEnabled == "true") + richPresence.connect(); + } // Uncomment the following line of code when app is ready to be packaged. // loadURL(mainWindow); // Open the DevTools and also disable Electron Security Warning. if (isDev()) { process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = true; - mainWindow.webContents.openDevTools({ mode: "detach" }); + // mainWindow.webContents.openDevTools({ mode: "detach" }); } // Emitted when the window is closed.