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=";
const ignoredOsuEntities = [
"osu!auth.dll",
"osu!.exe"
];
const osuEntities = [
"avcodec-51.dll",
@ -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
};

View File

@ -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();
}
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);
}
},

31
main.js
View File

@ -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,8 +369,7 @@ 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)
})...`,
});
});
@ -393,8 +399,7 @@ 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)
})...`,
});
});
@ -440,8 +445,7 @@ 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)
})...`,
});
});
@ -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();
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.