update fixes

This commit is contained in:
HorizonCode 2024-01-20 01:27:22 +01:00
parent f631c78805
commit 00d71704ab
3 changed files with 71 additions and 42 deletions

View File

@ -9,6 +9,7 @@ const checkUpdateURL =
"https://osu.ppy.sh/web/check-updates.php?action=check&stream="; "https://osu.ppy.sh/web/check-updates.php?action=check&stream=";
const ignoredOsuEntities = [ const ignoredOsuEntities = [
"osu!auth.dll", "osu!auth.dll",
"osu!.exe"
]; ];
const osuEntities = [ const osuEntities = [
"avcodec-51.dll", "avcodec-51.dll",
@ -266,7 +267,7 @@ async function getPatcherUpdates(osuPath) {
).digest("hex"); ).digest("hex");
if ( if (
latestPatchFileHash.trim().toLowerCase() != latestPatchFileHash.trim().toLowerCase() !=
localPatchFileHash.trim().toLowerCase() localPatchFileHash.trim().toLowerCase()
) filesToDownload.push(patcherFile); ) filesToDownload.push(patcherFile);
} else filesToDownload.push(patcherFile); } else filesToDownload.push(patcherFile);
} }
@ -331,7 +332,7 @@ async function getUIFiles(osuPath) {
).digest("hex"); ).digest("hex");
if ( if (
latestPatchFileHash.trim().toLowerCase() != latestPatchFileHash.trim().toLowerCase() !=
localPatchFileHash.trim().toLowerCase() localPatchFileHash.trim().toLowerCase()
) filesToDownload.push(uiFile); ) filesToDownload.push(uiFile);
} else filesToDownload.push(uiFile); } else filesToDownload.push(uiFile);
} }
@ -413,17 +414,43 @@ async function findOsuInstallation() {
value = value.substring(1, value.length - 3); value = value.substring(1, value.length - 3);
return path.dirname(value.trim()); 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; 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 = { module.exports = {
isValidOsuFolder, isValidOsuFolder,
getUserConfig, getUserConfig,
@ -438,4 +465,5 @@ module.exports = {
getUIFiles, getUIFiles,
replaceUIFile, replaceUIFile,
findOsuInstallation, findOsuInstallation,
updateOsuConfigHashes
}; };

View File

@ -1,12 +1,9 @@
const DiscordRPC = require("discord-auto-rpc"); const DiscordRPC = require("discord-auto-rpc");
const { appName, appVersion } = require("./appInfo.js"); const { appName, appVersion } = require("./appInfo.js");
const { get } = require("./config.js");
const clientId = "1032772293220384808"; const clientId = "1032772293220384808";
let richPresence; let richPresence;
let intervalId
let showPresence = true;
let cleared = false;
let currentStatus = { let currentStatus = {
details: " ", details: " ",
@ -31,30 +28,21 @@ let currentStatus = {
module.exports = { module.exports = {
connect: () => { connect: () => {
console.log("Connecting to Discord...");
if (!richPresence) { if (!richPresence) {
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" }); richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
richPresence.endlessLogin({ clientId }); richPresence.endlessLogin({ clientId });
richPresence.once("ready", () => { richPresence.once("ready", () => {
setInterval(() => { richPresence.setActivity(currentStatus);
const settingPresence = get("presence"); intervalId = setInterval(() => {
showPresence = settingPresence != undefined richPresence.setActivity(currentStatus);
? settingPresence.val == "true"
: true;
if (showPresence) {
richPresence.setActivity(currentStatus);
cleared = false;
} else {
if (cleared) return;
cleared = true;
richPresence.clearActivity();
}
}, 2500); }, 2500);
}); });
} }
}, },
disconnect: async () => { disconnect: async () => {
if (richPresence) { if (richPresence) {
clearInterval(intervalId);
await richPresence.clearActivity(); await richPresence.clearActivity();
await richPresence.destroy(); await richPresence.destroy();
richPresence = null; richPresence = null;
@ -69,7 +57,7 @@ module.exports = {
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " "; currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
}, },
update: () => { update: () => {
if (showPresence) { if (richPresence) {
richPresence.setActivity(currentStatus); richPresence.setActivity(currentStatus);
} }
}, },

39
main.js
View File

@ -21,6 +21,7 @@ const {
downloadUIFiles, downloadUIFiles,
replaceUIFile, replaceUIFile,
findOsuInstallation, findOsuInstallation,
updateOsuConfigHashes,
} = require("./electron/osuUtil"); } = require("./electron/osuUtil");
const { formatBytes } = require("./electron/formattingUtil"); const { formatBytes } = require("./electron/formattingUtil");
const windowName = require("get-window-by-name"); const windowName = require("get-window-by-name");
@ -269,6 +270,12 @@ function registerIPCPipes() {
ipcMain.handle("ezpplauncher:setting-update", async (e, args) => { ipcMain.handle("ezpplauncher:setting-update", async (e, args) => {
for (const key of Object.keys(args)) { for (const key of Object.keys(args)) {
const value = args[key]; const value = args[key];
if (key == "presence") {
if (!value) richPresence.disconnect();
else richPresence.connect();
}
if (typeof value == "boolean") { if (typeof value == "boolean") {
config.set(key, value ? "true" : "false"); config.set(key, value ? "true" : "false");
} else { } else {
@ -314,7 +321,7 @@ function registerIPCPipes() {
ipcMain.handle("ezpplauncher:launch", async (e) => { ipcMain.handle("ezpplauncher:launch", async (e) => {
const configPatch = config.get("patch"); const configPatch = config.get("patch");
patch = configPatch != undefined ? configPatch.val == "true" : true; patch = configPatch != undefined ? configPatch == "true" : true;
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Checking osu! directory...", status: "Checking osu! directory...",
}); });
@ -362,9 +369,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.total) })...`,
})...`,
}); });
}); });
await uiDownloader.startDownload(); await uiDownloader.startDownload();
@ -393,9 +399,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.total) })...`,
})...`,
}); });
}); });
await updateDownloader.startDownload(); await updateDownloader.startDownload();
@ -440,9 +445,8 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.total) })...`,
})...`,
}); });
}); });
await patcherDownloader.startDownload(); await patcherDownloader.startDownload();
@ -467,6 +471,8 @@ function registerIPCPipes() {
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Preparing launch...", status: "Preparing launch...",
}); });
await updateOsuConfigHashes(osuPath);
await replaceUIFile(osuPath, false);
const userConfig = getUserConfig(osuPath); const userConfig = getUserConfig(osuPath);
richPresence.updateVersion(await userConfig.get("LastVersion")); richPresence.updateVersion(await userConfig.get("LastVersion"));
@ -499,7 +505,6 @@ function registerIPCPipes() {
mainWindow.webContents.send("ezpplauncher:launchabort"); mainWindow.webContents.send("ezpplauncher:launchabort");
}, 5000); }, 5000);
}; };
await replaceUIFile(osuPath, false);
runOsuWithDevServer(osuPath, "ez-pp.farm", onExitHook); runOsuWithDevServer(osuPath, "ez-pp.farm", onExitHook);
mainWindow.hide(); mainWindow.hide();
startOsuStatus(); startOsuStatus();
@ -551,14 +556,22 @@ function createWindow() {
} }
registerIPCPipes(); 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. // Uncomment the following line of code when app is ready to be packaged.
// loadURL(mainWindow); // loadURL(mainWindow);
// Open the DevTools and also disable Electron Security Warning. // Open the DevTools and also disable Electron Security Warning.
if (isDev()) { if (isDev()) {
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = true; process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = true;
mainWindow.webContents.openDevTools({ mode: "detach" }); // mainWindow.webContents.openDevTools({ mode: "detach" });
} }
// Emitted when the window is closed. // Emitted when the window is closed.