2024-01-12 13:19:00 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2024-01-13 22:41:40 +00:00
|
|
|
const crypto = require("crypto");
|
|
|
|
const EventEmitter = require("events");
|
|
|
|
const { default: axios } = require("axios");
|
2024-01-18 11:43:46 +00:00
|
|
|
const { runFile } = require("./executeUtil.js");
|
2024-01-12 13:19:00 +00:00
|
|
|
|
2024-01-12 15:10:19 +00:00
|
|
|
const checkUpdateURL =
|
|
|
|
"https://osu.ppy.sh/web/check-updates.php?action=check&stream=";
|
2024-01-12 13:19:00 +00:00
|
|
|
const ignoredOsuEntities = [
|
|
|
|
"osu!auth.dll",
|
|
|
|
];
|
2024-03-16 17:48:44 +00:00
|
|
|
const gamemodes = {
|
|
|
|
0: "osu!",
|
|
|
|
1: "taiko",
|
|
|
|
2: "catch",
|
|
|
|
3: "mania",
|
|
|
|
4: "osu!(rx)",
|
|
|
|
5: "taiko(rx)",
|
|
|
|
6: "catch(rx)",
|
2024-04-15 11:07:40 +00:00
|
|
|
8: "osu!(ap)",
|
|
|
|
};
|
2024-01-12 13:19:00 +00:00
|
|
|
const osuEntities = [
|
|
|
|
"avcodec-51.dll",
|
|
|
|
"avformat-52.dll",
|
|
|
|
"avutil-49.dll",
|
|
|
|
"bass.dll",
|
|
|
|
"bass_fx.dll",
|
|
|
|
"collection.db",
|
|
|
|
"d3dcompiler_47.dll",
|
|
|
|
"libEGL.dll",
|
|
|
|
"libGLESv2.dll",
|
|
|
|
"Microsoft.Ink.dll",
|
|
|
|
"OpenTK.dll",
|
|
|
|
"osu!.cfg",
|
|
|
|
"osu!.db",
|
|
|
|
"osu!.exe",
|
|
|
|
"osu!auth.dll",
|
|
|
|
"osu!gameplay.dll",
|
|
|
|
"osu!seasonal.dll",
|
|
|
|
"osu!ui.dll",
|
|
|
|
"presence.db",
|
|
|
|
"pthreadGC2.dll",
|
|
|
|
"scores.db",
|
|
|
|
];
|
|
|
|
|
2024-04-15 11:07:40 +00:00
|
|
|
const ezppLauncherUpdateList = "https://ez-pp.farm/ezpplauncher";
|
2024-01-13 22:41:40 +00:00
|
|
|
|
2024-01-12 13:19:00 +00:00
|
|
|
async function isValidOsuFolder(path) {
|
|
|
|
const allFiles = await fs.promises.readdir(path);
|
|
|
|
let matches = 0;
|
|
|
|
for (const file of allFiles) {
|
|
|
|
if (osuEntities.includes(file)) matches = matches + 1;
|
|
|
|
}
|
|
|
|
return (Math.round((matches / osuEntities.length) * 100) >= 60);
|
|
|
|
}
|
|
|
|
|
2024-01-13 22:41:40 +00:00
|
|
|
function getGlobalConfig(osuPath) {
|
2024-01-12 15:10:19 +00:00
|
|
|
const configFileInfo = {
|
|
|
|
name: "",
|
|
|
|
path: "",
|
2024-01-13 22:41:40 +00:00
|
|
|
get: async (key) => {
|
|
|
|
if (!configFileInfo.path) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
const fileStream = await fs.promises.readFile(
|
|
|
|
configFileInfo.path,
|
|
|
|
"utf-8",
|
|
|
|
);
|
|
|
|
const lines = fileStream.split(/\r?\n/);
|
|
|
|
for (const line of lines) {
|
|
|
|
if (line.includes(" = ")) {
|
|
|
|
const argsPair = line.split(" = ", 2);
|
|
|
|
const keyname = argsPair[0];
|
|
|
|
const value = argsPair[1];
|
|
|
|
if (keyname == key) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const globalOsuConfig = path.join(osuPath, "osu!.cfg");
|
|
|
|
if (fs.existsSync(globalOsuConfig)) {
|
|
|
|
configFileInfo.name = "osu!.cfg";
|
|
|
|
configFileInfo.path = globalOsuConfig;
|
|
|
|
}
|
|
|
|
return configFileInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUserConfig(osuPath) {
|
|
|
|
const configFileInfo = {
|
|
|
|
name: "",
|
|
|
|
path: "",
|
|
|
|
set: async (key, newValue) => {
|
|
|
|
if (!configFileInfo.path) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
const fileContents = [];
|
|
|
|
const fileStream = await fs.promises.readFile(
|
|
|
|
configFileInfo.path,
|
|
|
|
"utf-8",
|
|
|
|
);
|
|
|
|
const lines = fileStream.split(/\r?\n/);
|
|
|
|
for (const line of lines) {
|
|
|
|
if (line.includes(" = ")) {
|
|
|
|
const argsPair = line.split(" = ", 2);
|
|
|
|
const keyname = argsPair[0];
|
|
|
|
if (keyname == key) {
|
|
|
|
fileContents.push(`${key} = ${newValue}`);
|
|
|
|
} else {
|
|
|
|
fileContents.push(line);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fileContents.push(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await fs.promises.writeFile(configFileInfo.path, fileContents.join("\n"));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
2024-01-12 15:10:19 +00:00
|
|
|
get: async (key) => {
|
|
|
|
if (!configFileInfo.path) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
const fileStream = await fs.promises.readFile(
|
|
|
|
configFileInfo.path,
|
|
|
|
"utf-8",
|
|
|
|
);
|
|
|
|
const lines = fileStream.split(/\r?\n/);
|
|
|
|
for (const line of lines) {
|
|
|
|
if (line.includes(" = ")) {
|
|
|
|
const argsPair = line.split(" = ", 2);
|
|
|
|
const keyname = argsPair[0];
|
|
|
|
const value = argsPair[1];
|
|
|
|
if (keyname == key) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const userOsuConfig = path.join(
|
|
|
|
osuPath,
|
|
|
|
`osu!.${process.env["USERNAME"]}.cfg`,
|
|
|
|
);
|
|
|
|
if (fs.existsSync(userOsuConfig)) {
|
|
|
|
configFileInfo.name = `osu!.${process.env["USERNAME"]}.cfg`;
|
|
|
|
configFileInfo.path = userOsuConfig;
|
|
|
|
}
|
|
|
|
return configFileInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getUpdateFiles(releaseStream) {
|
|
|
|
const releaseData = await fetch(checkUpdateURL + releaseStream);
|
|
|
|
return releaseData.ok ? await releaseData.json() : undefined;
|
|
|
|
}
|
|
|
|
|
2024-01-13 22:41:40 +00:00
|
|
|
async function getFilesThatNeedUpdate(osuPath, releaseStreamFiles) {
|
|
|
|
const updateFiles = [];
|
|
|
|
for (const updatePatch of releaseStreamFiles) {
|
|
|
|
const fileName = updatePatch.filename;
|
|
|
|
const fileHash = updatePatch.file_hash;
|
|
|
|
|
|
|
|
const fileOnDisk = path.join(osuPath, fileName);
|
|
|
|
if (fs.existsSync(fileOnDisk)) {
|
|
|
|
if (ignoredOsuEntities.includes(fileName)) continue;
|
2024-01-18 11:43:46 +00:00
|
|
|
const fileHashOnDisk = crypto.createHash("md5").update(
|
|
|
|
fs.readFileSync(fileOnDisk),
|
|
|
|
).digest("hex");
|
|
|
|
if (
|
|
|
|
fileHashOnDisk.trim().toLowerCase() != fileHash.trim().toLowerCase()
|
|
|
|
) {
|
2024-01-13 22:41:40 +00:00
|
|
|
updateFiles.push(updatePatch);
|
|
|
|
}
|
|
|
|
} else updateFiles.push(updatePatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
return updateFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloadUpdateFiles(osuPath, updateFiles) {
|
|
|
|
const eventEmitter = new EventEmitter();
|
|
|
|
|
|
|
|
const startDownload = async () => {
|
|
|
|
for (const updatePatch of updateFiles) {
|
2024-01-18 11:43:46 +00:00
|
|
|
try {
|
2024-04-15 11:07:40 +00:00
|
|
|
const fileName = updatePatch.filename;
|
|
|
|
const fileSize = updatePatch.filesize;
|
|
|
|
const fileURL = updatePatch.url_full;
|
|
|
|
|
|
|
|
const axiosDownloadWithProgress = await axios.get(fileURL, {
|
|
|
|
responseType: "stream",
|
|
|
|
onDownloadProgress: (progressEvent) => {
|
|
|
|
const { loaded, total } = progressEvent;
|
|
|
|
eventEmitter.emit("data", {
|
|
|
|
fileName,
|
|
|
|
loaded,
|
|
|
|
total,
|
|
|
|
progress: Math.floor((loaded / total) * 100),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-01-22 11:06:04 +00:00
|
|
|
if (fs.existsSync(path.join(osuPath, fileName))) {
|
|
|
|
await fs.promises.rm(path.join(osuPath, fileName), {
|
|
|
|
force: true,
|
|
|
|
});
|
|
|
|
}
|
2024-01-18 11:43:46 +00:00
|
|
|
await fs.promises.writeFile(
|
|
|
|
path.join(osuPath, fileName),
|
|
|
|
axiosDownloadWithProgress.data,
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
eventEmitter.emit("error", {
|
|
|
|
fileName,
|
2024-04-15 11:07:40 +00:00
|
|
|
error: err,
|
2024-01-18 11:43:46 +00:00
|
|
|
});
|
|
|
|
}
|
2024-01-13 22:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// wait until all files are downloaded
|
|
|
|
return true;
|
2024-01-18 11:43:46 +00:00
|
|
|
};
|
2024-01-13 22:41:40 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
eventEmitter,
|
|
|
|
startDownload,
|
2024-01-18 11:43:46 +00:00
|
|
|
};
|
2024-01-13 22:41:40 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 15:31:34 +00:00
|
|
|
function runOsuUpdater(osuPath, onExit) {
|
|
|
|
const osuExecuteable = path.join(osuPath, "osu!.exe");
|
|
|
|
runFile(osuPath, osuExecuteable, ["-repair"], onExit);
|
|
|
|
}
|
|
|
|
|
2024-01-13 22:41:40 +00:00
|
|
|
function runOsuWithDevServer(osuPath, serverDomain, onExit) {
|
|
|
|
const osuExecuteable = path.join(osuPath, "osu!.exe");
|
|
|
|
runFile(osuPath, osuExecuteable, ["-devserver", serverDomain], onExit);
|
|
|
|
}
|
|
|
|
|
2024-04-14 14:36:32 +00:00
|
|
|
async function getEZPPLauncherUpdateFiles(osuPath) {
|
2024-01-13 22:41:40 +00:00
|
|
|
const filesToDownload = [];
|
2024-04-15 11:07:40 +00:00
|
|
|
const updateFilesRequest = await fetch(ezppLauncherUpdateList, {
|
|
|
|
method: "PATCH",
|
|
|
|
});
|
2024-04-14 14:36:32 +00:00
|
|
|
const updateFiles = await updateFilesRequest.json();
|
|
|
|
for (const updateFile of updateFiles) {
|
2024-04-15 11:07:40 +00:00
|
|
|
const filePath = path.join(
|
|
|
|
osuPath,
|
|
|
|
...updateFile.folder.split("/"),
|
|
|
|
updateFile.name,
|
|
|
|
);
|
2024-04-14 14:36:32 +00:00
|
|
|
if (fs.existsSync(filePath)) {
|
|
|
|
const fileHash = updateFile.md5.toLowerCase();
|
|
|
|
const localFileHash = crypto.createHash("md5").update(
|
|
|
|
fs.readFileSync(filePath),
|
|
|
|
).digest("hex").toLowerCase();
|
|
|
|
if (fileHash !== localFileHash) {
|
|
|
|
filesToDownload.push(updateFile);
|
2024-01-18 11:43:46 +00:00
|
|
|
}
|
2024-04-14 14:36:32 +00:00
|
|
|
} else {
|
|
|
|
filesToDownload.push(updateFile);
|
2024-01-13 22:41:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return filesToDownload;
|
|
|
|
}
|
|
|
|
|
2024-04-14 14:36:32 +00:00
|
|
|
async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles) {
|
2024-01-13 22:41:40 +00:00
|
|
|
const eventEmitter = new EventEmitter();
|
|
|
|
|
|
|
|
const startDownload = async () => {
|
2024-04-14 14:36:32 +00:00
|
|
|
for (const updateFile of updateFiles) {
|
2024-01-18 11:43:46 +00:00
|
|
|
try {
|
2024-04-15 11:07:40 +00:00
|
|
|
const filePath = path.join(
|
|
|
|
osuPath,
|
|
|
|
...updateFile.folder.split("/"),
|
|
|
|
updateFile.name,
|
|
|
|
);
|
|
|
|
const folder = path.dirname(filePath);
|
|
|
|
if (!fs.existsSync(folder)) {
|
|
|
|
await fs.promises.mkdir(folder, { recursive: true });
|
|
|
|
}
|
|
|
|
const axiosDownloadWithProgress = await axios.get(updateFile.url, {
|
|
|
|
responseType: "stream",
|
|
|
|
onDownloadProgress: (progressEvent) => {
|
|
|
|
const fileSize = updateFile.size;
|
|
|
|
const { loaded } = progressEvent;
|
|
|
|
eventEmitter.emit("data", {
|
|
|
|
fileName: path.basename(filePath),
|
|
|
|
loaded,
|
|
|
|
total: fileSize,
|
|
|
|
progress: Math.floor((loaded / fileSize) * 100),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-04-14 14:36:32 +00:00
|
|
|
if (fs.existsSync(filePath)) {
|
|
|
|
await fs.promises.rm(filePath, {
|
2024-01-22 11:06:04 +00:00
|
|
|
force: true,
|
|
|
|
});
|
|
|
|
}
|
2024-01-18 11:43:46 +00:00
|
|
|
await fs.promises.writeFile(
|
2024-04-14 14:36:32 +00:00
|
|
|
filePath,
|
2024-01-18 11:43:46 +00:00
|
|
|
axiosDownloadWithProgress.data,
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
eventEmitter.emit("error", {
|
2024-04-14 14:36:32 +00:00
|
|
|
fileName: path.basename(filePath),
|
2024-04-15 11:07:40 +00:00
|
|
|
error: err,
|
2024-01-18 11:43:46 +00:00
|
|
|
});
|
|
|
|
}
|
2024-01-13 22:41:40 +00:00
|
|
|
}
|
2024-04-15 11:07:40 +00:00
|
|
|
};
|
2024-01-13 22:41:40 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
eventEmitter,
|
|
|
|
startDownload,
|
2024-01-18 11:43:46 +00:00
|
|
|
};
|
2024-01-13 22:41:40 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 14:36:32 +00:00
|
|
|
async function replaceUIFiles(osuPath, revert) {
|
2024-01-13 22:41:40 +00:00
|
|
|
if (!revert) {
|
|
|
|
const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll");
|
|
|
|
const oldOsuUIFile = path.join(osuPath, "osu!ui.dll");
|
2024-04-15 11:07:40 +00:00
|
|
|
const ezppGameplayFile = path.join(
|
|
|
|
osuPath,
|
|
|
|
"EZPPLauncher",
|
|
|
|
"ezpp!gameplay.dll",
|
|
|
|
);
|
2024-04-14 14:36:32 +00:00
|
|
|
const oldOsuGameplayFile = path.join(osuPath, "osu!gameplay.dll");
|
|
|
|
|
2024-01-18 11:43:46 +00:00
|
|
|
await fs.promises.rename(
|
|
|
|
oldOsuUIFile,
|
|
|
|
path.join(osuPath, "osu!ui.dll.bak"),
|
|
|
|
);
|
2024-01-13 22:41:40 +00:00
|
|
|
await fs.promises.rename(ezppUIFile, oldOsuUIFile);
|
2024-04-14 14:36:32 +00:00
|
|
|
|
|
|
|
await fs.promises.rename(
|
|
|
|
oldOsuGameplayFile,
|
|
|
|
path.join(osuPath, "osu!gameplay.dll.bak"),
|
|
|
|
);
|
|
|
|
await fs.promises.rename(ezppGameplayFile, oldOsuGameplayFile);
|
2024-01-13 22:41:40 +00:00
|
|
|
} else {
|
|
|
|
const oldOsuUIFile = path.join(osuPath, "osu!ui.dll");
|
|
|
|
const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll");
|
2024-04-14 14:36:32 +00:00
|
|
|
const oldOsuGameplayFile = path.join(osuPath, "osu!gameplay.dll");
|
2024-04-15 11:07:40 +00:00
|
|
|
const ezppGameplayFile = path.join(
|
|
|
|
osuPath,
|
|
|
|
"EZPPLauncher",
|
|
|
|
"ezpp!gameplay.dll",
|
|
|
|
);
|
2024-04-14 14:36:32 +00:00
|
|
|
|
2024-01-13 22:41:40 +00:00
|
|
|
await fs.promises.rename(oldOsuUIFile, ezppUIFile);
|
2024-01-18 11:43:46 +00:00
|
|
|
await fs.promises.rename(
|
|
|
|
path.join(osuPath, "osu!ui.dll.bak"),
|
|
|
|
oldOsuUIFile,
|
|
|
|
);
|
2024-04-14 14:36:32 +00:00
|
|
|
|
|
|
|
await fs.promises.rename(oldOsuGameplayFile, ezppGameplayFile);
|
|
|
|
await fs.promises.rename(
|
|
|
|
path.join(osuPath, "osu!gameplay.dll.bak"),
|
|
|
|
oldOsuGameplayFile,
|
|
|
|
);
|
2024-01-13 22:41:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-18 15:32:57 +00:00
|
|
|
async function findOsuInstallation() {
|
|
|
|
const regedit = require("regedit-rs");
|
|
|
|
|
|
|
|
const osuLocationFromDefaultIcon =
|
|
|
|
"HKLM\\SOFTWARE\\Classes\\osu\\DefaultIcon";
|
|
|
|
const osuKey = regedit.listSync(osuLocationFromDefaultIcon);
|
|
|
|
if (osuKey[osuLocationFromDefaultIcon].exists) {
|
|
|
|
const key = osuKey[osuLocationFromDefaultIcon].values[""];
|
|
|
|
let value = key.value;
|
|
|
|
value = value.substring(1, value.length - 3);
|
|
|
|
return path.dirname(value.trim());
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2024-01-20 00:27:22 +00:00
|
|
|
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);
|
2024-01-22 11:00:50 +00:00
|
|
|
const existingFileMD5 = crypto.createHash("md5").update(
|
|
|
|
binaryFileContents,
|
|
|
|
).digest("hex");
|
2024-01-20 00:27:22 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-22 11:00:50 +00:00
|
|
|
await fs.promises.writeFile(osuCfg, newLines.join("\n"), "utf-8");
|
2024-01-20 00:27:22 +00:00
|
|
|
}
|
|
|
|
|
2024-01-18 11:43:46 +00:00
|
|
|
module.exports = {
|
|
|
|
isValidOsuFolder,
|
|
|
|
getUserConfig,
|
|
|
|
getGlobalConfig,
|
|
|
|
getUpdateFiles,
|
|
|
|
getFilesThatNeedUpdate,
|
|
|
|
downloadUpdateFiles,
|
|
|
|
runOsuWithDevServer,
|
2024-04-14 14:36:32 +00:00
|
|
|
replaceUIFiles,
|
2024-01-18 15:32:57 +00:00
|
|
|
findOsuInstallation,
|
2024-01-22 11:00:50 +00:00
|
|
|
updateOsuConfigHashes,
|
2024-01-24 15:31:34 +00:00
|
|
|
runOsuUpdater,
|
2024-04-14 14:36:32 +00:00
|
|
|
getEZPPLauncherUpdateFiles,
|
|
|
|
downloadEZPPLauncherUpdateFiles,
|
2024-04-15 11:07:40 +00:00
|
|
|
gamemodes,
|
2024-01-18 11:43:46 +00:00
|
|
|
};
|