update fixes

This commit is contained in:
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",
@@ -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
};

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