add modules to electron export, fix issues when downloading updates

This commit is contained in:
HorizonCode 2024-01-18 12:43:46 +01:00
parent 6369c0e8af
commit 6aa0a6c969
17 changed files with 338 additions and 162 deletions

11
electron/cryptoUtil.js Normal file
View File

@ -0,0 +1,11 @@
const cryptojs = require("crypto-js");
const encrypt = (string, salt) => {
return cryptojs.AES.encrypt(string, salt).toString();
};
const decrypt = (string, salt) => {
return cryptojs.AES.decrypt(string, salt).toString(cryptojs.enc.Utf8);
};
module.exports = { encrypt, decrypt };

32
electron/hwidUtil.js Normal file
View File

@ -0,0 +1,32 @@
const child_process = require("child_process");
const options = { encoding: "ascii", windowsHide: true, timeout: 200 };
const platforms = {
win32: [
"REG QUERY HKLM\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid",
/MachineGuid\s+REG_SZ\s+(.*?)\s/,
],
darwin: [
"ioreg -rd1 -c IOPlatformExpertDevice",
/"IOPlatformUUID" = "(.*?)"/,
],
linux: [
"cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || true",
/^([\da-f]+)/,
],
};
const crypto = require("crypto");
/**
* Returns machine hardware id.
* Returns `undefined` if cannot determine.
* @return {string?}
*/
function getHwId() {
const getter = platforms[process.platform];
if (!getter) return;
const result = getter[1].exec(child_process.execSync(getter[0], options));
if (!result) return;
return crypto.createHash("md5").update(result[1]).digest("hex") ||
undefined;
}
exports.getHwId = getHwId;

View File

@ -3,7 +3,7 @@ const path = require("path");
const crypto = require("crypto"); const crypto = require("crypto");
const EventEmitter = require("events"); const EventEmitter = require("events");
const { default: axios } = require("axios"); const { default: axios } = require("axios");
const { runFile } = require("./executeUtil"); const { runFile } = require("./executeUtil.js");
const checkUpdateURL = const checkUpdateURL =
"https://osu.ppy.sh/web/check-updates.php?action=check&stream="; "https://osu.ppy.sh/web/check-updates.php?action=check&stream=";
@ -38,22 +38,22 @@ const patcherFiles = [
{ {
name: "patcher.exe", name: "patcher.exe",
url_download: "https://ez-pp.farm/assets/patcher.exe", url_download: "https://ez-pp.farm/assets/patcher.exe",
url_hash: "https://ez-pp.farm/assets/patcher.md5" url_hash: "https://ez-pp.farm/assets/patcher.md5",
}, },
{ {
name: "patch.hook.dll", name: "patch.hook.dll",
url_download: "https://ez-pp.farm/assets/patch.hook.dll", url_download: "https://ez-pp.farm/assets/patch.hook.dll",
url_hash: "https://ez-pp.farm/assets/patch.hook.md5" url_hash: "https://ez-pp.farm/assets/patch.hook.md5",
} },
] ];
const uiFiles = [ const uiFiles = [
{ {
name: "ezpp!ui.dll", name: "ezpp!ui.dll",
url_download: "https://ez-pp.farm/assets/ezpp!ui.dll", url_download: "https://ez-pp.farm/assets/ezpp!ui.dll",
url_hash: "https://ez-pp.farm/assets/ezpp!ui.md5" url_hash: "https://ez-pp.farm/assets/ezpp!ui.md5",
} },
] ];
async function isValidOsuFolder(path) { async function isValidOsuFolder(path) {
const allFiles = await fs.promises.readdir(path); const allFiles = await fs.promises.readdir(path);
@ -175,13 +175,17 @@ async function getFilesThatNeedUpdate(osuPath, releaseStreamFiles) {
const fileOnDisk = path.join(osuPath, fileName); const fileOnDisk = path.join(osuPath, fileName);
if (fs.existsSync(fileOnDisk)) { if (fs.existsSync(fileOnDisk)) {
if (ignoredOsuEntities.includes(fileName)) continue; if (ignoredOsuEntities.includes(fileName)) continue;
const fileHashOnDisk = crypto.createHash("md5").update(fs.readFileSync(fileOnDisk)).digest("hex"); const fileHashOnDisk = crypto.createHash("md5").update(
if (fileHashOnDisk.trim().toLowerCase() != fileHash.trim().toLowerCase()) { fs.readFileSync(fileOnDisk),
).digest("hex");
if (
fileHashOnDisk.trim().toLowerCase() != fileHash.trim().toLowerCase()
) {
console.log({ console.log({
fileOnDisk, fileOnDisk,
fileHashOnDisk, fileHashOnDisk,
fileHash fileHash,
}) });
updateFiles.push(updatePatch); updateFiles.push(updatePatch);
} }
} else updateFiles.push(updatePatch); } else updateFiles.push(updatePatch);
@ -207,7 +211,7 @@ function downloadUpdateFiles(osuPath, updateFiles) {
fileName, fileName,
loaded, loaded,
total, total,
progress: Math.floor((loaded / total) * 100) progress: Math.floor((loaded / total) * 100),
}); });
}, },
}); });
@ -216,20 +220,30 @@ function downloadUpdateFiles(osuPath, updateFiles) {
fileName, fileName,
loaded: fileSize, loaded: fileSize,
total: fileSize, total: fileSize,
progress: 100 progress: 100,
}); });
}) });
await fs.promises.writeFile(path.join(osuPath, fileName), axiosDownloadWithProgress.data); try {
await fs.promises.writeFile(
path.join(osuPath, fileName),
axiosDownloadWithProgress.data,
);
} catch (err) {
console.log(err);
eventEmitter.emit("error", {
fileName,
});
}
} }
// wait until all files are downloaded // wait until all files are downloaded
return true; return true;
} };
return { return {
eventEmitter, eventEmitter,
startDownload, startDownload,
} };
} }
function runOsuWithDevServer(osuPath, serverDomain, onExit) { function runOsuWithDevServer(osuPath, serverDomain, onExit) {
@ -238,7 +252,6 @@ function runOsuWithDevServer(osuPath, serverDomain, onExit) {
} }
async function getPatcherUpdates(osuPath) { async function getPatcherUpdates(osuPath) {
const filesToDownload = []; const filesToDownload = [];
const patcherDir = path.join(osuPath, "EZPPLauncher"); const patcherDir = path.join(osuPath, "EZPPLauncher");
@ -246,9 +259,15 @@ async function getPatcherUpdates(osuPath) {
for (const patcherFile of patcherFiles) { for (const patcherFile of patcherFiles) {
if (fs.existsSync(path.join(patcherDir, patcherFile.name))) { if (fs.existsSync(path.join(patcherDir, patcherFile.name))) {
const latestPatchFileHash = await (await fetch(patcherFile.url_hash)).text(); const latestPatchFileHash = await (await fetch(patcherFile.url_hash))
const localPatchFileHash = crypto.createHash("md5").update(fs.readFileSync(path.join(patcherDir, patcherFile.name))).digest("hex"); .text();
if (latestPatchFileHash.trim().toLowerCase() != localPatchFileHash.trim().toLowerCase()) filesToDownload.push(patcherFile); const localPatchFileHash = crypto.createHash("md5").update(
fs.readFileSync(path.join(patcherDir, patcherFile.name)),
).digest("hex");
if (
latestPatchFileHash.trim().toLowerCase() !=
localPatchFileHash.trim().toLowerCase()
) filesToDownload.push(patcherFile);
} else filesToDownload.push(patcherFile); } else filesToDownload.push(patcherFile);
} }
@ -259,7 +278,6 @@ function downloadPatcherUpdates(osuPath, patcherUpdates) {
const eventEmitter = new EventEmitter(); const eventEmitter = new EventEmitter();
const startDownload = async () => { const startDownload = async () => {
const patcherDir = path.join(osuPath, "EZPPLauncher"); const patcherDir = path.join(osuPath, "EZPPLauncher");
if (!fs.existsSync(patcherDir)) fs.mkdirSync(patcherDir); if (!fs.existsSync(patcherDir)) fs.mkdirSync(patcherDir);
@ -274,23 +292,32 @@ function downloadPatcherUpdates(osuPath, patcherUpdates) {
fileName, fileName,
loaded, loaded,
total, total,
progress: Math.floor((loaded / total) * 100) progress: Math.floor((loaded / total) * 100),
}); });
}, },
}); });
await fs.promises.writeFile(path.join(osuPath, "EZPPLauncher", fileName), axiosDownloadWithProgress.data); try {
await fs.promises.writeFile(
path.join(osuPath, "EZPPLauncher", fileName),
axiosDownloadWithProgress.data,
);
} catch (err) {
console.log(err);
eventEmitter.emit("error", {
fileName,
});
} }
} }
};
return { return {
eventEmitter, eventEmitter,
startDownload, startDownload,
} };
} }
async function getUIFiles(osuPath) { async function getUIFiles(osuPath) {
const filesToDownload = []; const filesToDownload = [];
const ezppLauncherDir = path.join(osuPath, "EZPPLauncher"); const ezppLauncherDir = path.join(osuPath, "EZPPLauncher");
@ -299,8 +326,13 @@ async function getUIFiles(osuPath) {
for (const uiFile of uiFiles) { for (const uiFile of uiFiles) {
if (fs.existsSync(path.join(ezppLauncherDir, uiFile.name))) { if (fs.existsSync(path.join(ezppLauncherDir, uiFile.name))) {
const latestPatchFileHash = await (await fetch(uiFile.url_hash)).text(); const latestPatchFileHash = await (await fetch(uiFile.url_hash)).text();
const localPatchFileHash = crypto.createHash("md5").update(fs.readFileSync(path.join(ezppLauncherDir, uiFile.name))).digest("hex"); const localPatchFileHash = crypto.createHash("md5").update(
if (latestPatchFileHash.trim().toLowerCase() != localPatchFileHash.trim().toLowerCase()) filesToDownload.push(uiFile); fs.readFileSync(path.join(ezppLauncherDir, uiFile.name)),
).digest("hex");
if (
latestPatchFileHash.trim().toLowerCase() !=
localPatchFileHash.trim().toLowerCase()
) filesToDownload.push(uiFile);
} else filesToDownload.push(uiFile); } else filesToDownload.push(uiFile);
} }
@ -311,7 +343,6 @@ function downloadUIFiles(osuPath, uiFiles) {
const eventEmitter = new EventEmitter(); const eventEmitter = new EventEmitter();
const startDownload = async () => { const startDownload = async () => {
const ezpplauncherDir = path.join(osuPath, "EZPPLauncher"); const ezpplauncherDir = path.join(osuPath, "EZPPLauncher");
if (!fs.existsSync(ezpplauncherDir)) fs.mkdirSync(ezpplauncherDir); if (!fs.existsSync(ezpplauncherDir)) fs.mkdirSync(ezpplauncherDir);
@ -326,33 +357,61 @@ function downloadUIFiles(osuPath, uiFiles) {
fileName, fileName,
loaded, loaded,
total, total,
progress: Math.floor((loaded / total) * 100) progress: Math.floor((loaded / total) * 100),
}); });
}, },
}); });
try {
await fs.promises.writeFile(path.join(osuPath, "EZPPLauncher", fileName), axiosDownloadWithProgress.data); await fs.promises.writeFile(
path.join(osuPath, "EZPPLauncher", fileName),
axiosDownloadWithProgress.data,
);
} catch (err) {
console.log(err);
eventEmitter.emit("error", {
fileName,
});
} }
} }
};
return { return {
eventEmitter, eventEmitter,
startDownload, startDownload,
} };
} }
async function replaceUIFile(osuPath, revert) { async function replaceUIFile(osuPath, revert) {
if (!revert) { if (!revert) {
const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll"); const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll");
const oldOsuUIFile = path.join(osuPath, "osu!ui.dll"); const oldOsuUIFile = path.join(osuPath, "osu!ui.dll");
await fs.promises.rename(oldOsuUIFile, path.join(osuPath, "osu!ui.dll.bak")); await fs.promises.rename(
oldOsuUIFile,
path.join(osuPath, "osu!ui.dll.bak"),
);
await fs.promises.rename(ezppUIFile, oldOsuUIFile); await fs.promises.rename(ezppUIFile, oldOsuUIFile);
} else { } else {
const oldOsuUIFile = path.join(osuPath, "osu!ui.dll"); const oldOsuUIFile = path.join(osuPath, "osu!ui.dll");
const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll"); const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll");
await fs.promises.rename(oldOsuUIFile, ezppUIFile); await fs.promises.rename(oldOsuUIFile, ezppUIFile);
await fs.promises.rename(path.join(osuPath, "osu!ui.dll.bak"), oldOsuUIFile); await fs.promises.rename(
path.join(osuPath, "osu!ui.dll.bak"),
oldOsuUIFile,
);
} }
} }
module.exports = { isValidOsuFolder, getUserConfig, getGlobalConfig, getUpdateFiles, getFilesThatNeedUpdate, downloadUpdateFiles, runOsuWithDevServer, getPatcherUpdates, downloadPatcherUpdates, downloadUIFiles, getUIFiles, replaceUIFile }; module.exports = {
isValidOsuFolder,
getUserConfig,
getGlobalConfig,
getUpdateFiles,
getFilesThatNeedUpdate,
downloadUpdateFiles,
runOsuWithDevServer,
getPatcherUpdates,
downloadPatcherUpdates,
downloadUIFiles,
getUIFiles,
replaceUIFile,
};

55
electron/richPresence.js Normal file
View File

@ -0,0 +1,55 @@
const DiscordRPC = require("discord-auto-rpc");
const { appName, appVersion } = require("./appInfo.js");
const clientId = "1032772293220384808";
let richPresence;
let currentStatus = {
details: " ",
state: "Idle in Launcher...",
startTimestamp: new Date(),
largeImageKey: "ezppfarm",
largeImageText: `${appName} ${appVersion}`,
smallImageKey: " ",
smallImageText: " ",
buttons: [
{
label: "Download the Launcher",
url: "https://git.ez-pp.farm/EZPPFarm/EZPPLauncher/releases/latest",
},
{
label: "Join EZPPFarm",
url: "https://ez-pp.farm/discord",
},
],
instance: false,
};
module.exports = {
connect: () => {
if (!richPresence) {
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
richPresence.endlessLogin({ clientId });
richPresence.once("ready", () => {
setInterval(() => {
richPresence.setActivity(currentStatus);
}, 2500);
});
}
},
disconnect: async () => {
if (richPresence) {
await richPresence.clearActivity();
await richPresence.destroy();
richPresence = null;
}
},
updateStatus: ({ state, details }) => {
currentStatus.state = state ?? " ";
currentStatus.details = details ?? " ";
},
updateVersion: (osuVersion) => {
currentStatus.smallImageKey = osuVersion ? "osu" : " ";
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
},
};

112
main.js
View File

@ -3,16 +3,31 @@ const { app, BrowserWindow, Menu, ipcMain, dialog } = require("electron");
const path = require("path"); const path = require("path");
const serve = require("electron-serve"); const serve = require("electron-serve");
const loadURL = serve({ directory: "public" }); const loadURL = serve({ directory: "public" });
const config = require("./src/config/config"); const config = require("./electron/config");
const { setupTitlebar, attachTitlebarToWindow } = require( const { setupTitlebar, attachTitlebarToWindow } = require(
"custom-electron-titlebar/main", "custom-electron-titlebar/main",
); );
const { isValidOsuFolder, getUpdateFiles, getGlobalConfig, getFilesThatNeedUpdate, downloadUpdateFiles, getUserConfig, runOsuWithDevServer, getPatcherUpdates, downloadPatcherUpdates, getUIFiles, downloadUIFiles, replaceUIFile } = require("./src/util/osuUtil"); const {
const { formatBytes } = require("./src/util/formattingUtil"); isValidOsuFolder,
getUpdateFiles,
getGlobalConfig,
getFilesThatNeedUpdate,
downloadUpdateFiles,
getUserConfig,
runOsuWithDevServer,
getPatcherUpdates,
downloadPatcherUpdates,
getUIFiles,
downloadUIFiles,
replaceUIFile,
} = require("./electron/osuUtil");
const { formatBytes } = require("./electron/formattingUtil");
const windowName = require("get-window-by-name"); const windowName = require("get-window-by-name");
const { existsSync } = require("fs"); const { existsSync } = require("fs");
const { runFileDetached } = require("./src/util/executeUtil"); const { runFileDetached } = require("./electron/executeUtil");
const richPresence = require("./src/discord/richPresence"); const richPresence = require("./electron/richPresence");
const cryptUtil = require("./electron/cryptoUtil");
const { getHwId } = require("./electron/hwidUtil");
// Keep a global reference of the window object, if you don't, the window will // Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected. // be closed automatically when the JavaScript object is garbage collected.
@ -40,7 +55,11 @@ function startOsuStatus() {
if (!osuLoaded) { if (!osuLoaded) {
osuLoaded = true; osuLoaded = true;
setTimeout(() => { setTimeout(() => {
const patcherExecuteable = path.join(userOsuPath, "EZPPLauncher", "patcher.exe"); const patcherExecuteable = path.join(
userOsuPath,
"EZPPLauncher",
"patcher.exe",
);
if (existsSync(patcherExecuteable)) { if (existsSync(patcherExecuteable)) {
runFileDetached(userOsuPath, patcherExecuteable); runFileDetached(userOsuPath, patcherExecuteable);
} }
@ -53,17 +72,17 @@ function startOsuStatus() {
if (!windowTitle.includes("-")) { if (!windowTitle.includes("-")) {
richPresence.updateStatus({ richPresence.updateStatus({
details: undefined, details: undefined,
state: "Idle..." state: "Idle...",
}) });
} else { } else {
const components = windowTitle.split(" - "); const components = windowTitle.split(" - ");
const splitTitle = [components.shift(), components.join(" - ")] const splitTitle = [components.shift(), components.join(" - ")];
const currentMap = splitTitle[1]; const currentMap = splitTitle[1];
if (!currentMap.endsWith(".osu")) { if (!currentMap.endsWith(".osu")) {
richPresence.updateStatus({ richPresence.updateStatus({
state: "Playing...", state: "Playing...",
details: currentMap details: currentMap,
}) });
} }
} }
} }
@ -76,6 +95,7 @@ function stopOsuStatus() {
function registerIPCPipes() { function registerIPCPipes() {
ipcMain.handle("ezpplauncher:login", async (e, args) => { ipcMain.handle("ezpplauncher:login", async (e, args) => {
const hwid = getHwId();
const timeout = new AbortController(); const timeout = new AbortController();
const timeoutId = setTimeout(() => timeout.abort(), 8000); const timeoutId = setTimeout(() => timeout.abort(), 8000);
try { try {
@ -98,7 +118,7 @@ function registerIPCPipes() {
if ("user" in result) { if ("user" in result) {
if (args.saveCredentials) { if (args.saveCredentials) {
config.set("username", args.username); config.set("username", args.username);
config.set("password", args.password); config.set("password", cryptUtil.encrypt(args.password, hwid));
} }
currentUser = args; currentUser = args;
config.remove("guest"); config.remove("guest");
@ -118,8 +138,9 @@ function registerIPCPipes() {
}); });
ipcMain.handle("ezpplauncher:autologin", async (e) => { ipcMain.handle("ezpplauncher:autologin", async (e) => {
const hwid = getHwId();
const username = config.get("username"); const username = config.get("username");
const password = config.get("password"); const password = cryptUtil.decrypt(config.get("password"), hwid);
const guest = config.get("guest"); const guest = config.get("guest");
if (guest) return { code: 200, message: "Login as guest", guest: true }; if (guest) return { code: 200, message: "Login as guest", guest: true };
if (username == undefined || password == undefined) { if (username == undefined || password == undefined) {
@ -175,7 +196,7 @@ function registerIPCPipes() {
config.remove("username"); config.remove("username");
config.remove("password"); config.remove("password");
config.remove("guest"); config.remove("guest");
currentUser = undefined currentUser = undefined;
return true; return true;
}); });
@ -240,33 +261,65 @@ function registerIPCPipes() {
const updateFiles = await getFilesThatNeedUpdate(osuPath, latestFiles); const updateFiles = await getFilesThatNeedUpdate(osuPath, latestFiles);
if (uiFiles.length > 0) { if (uiFiles.length > 0) {
const uiDownloader = downloadUIFiles(osuPath, uiFiles); const uiDownloader = downloadUIFiles(osuPath, uiFiles);
let errored = false;
uiDownloader.eventEmitter.on("error", (data) => {
const filename = data.fileName;
errored = true;
mainWindow.webContents.send("ezpplauncher:alert", {
type: "error",
message:
`Failed to download/replace ${filename}!\nMaybe try to rerun the Launcher as Admin.`,
});
});
uiDownloader.eventEmitter.on("data", (data) => { uiDownloader.eventEmitter.on("data", (data) => {
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
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)}/${formatBytes(data.total)})...`, status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
formatBytes(data.total)
})...`,
}); });
}); });
await uiDownloader.startDownload(); await uiDownloader.startDownload();
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: -1, progress: -1,
}); });
if (errored) {
mainWindow.webContents.send("ezpplauncher:launchabort");
return;
}
} }
if (updateFiles.length > 0) { if (updateFiles.length > 0) {
const updateDownloader = downloadUpdateFiles(osuPath, updateFiles); const updateDownloader = downloadUpdateFiles(osuPath, updateFiles);
let errored = false;
updateDownloader.eventEmitter.on("error", (data) => {
const filename = data.fileName;
errored = true;
mainWindow.webContents.send("ezpplauncher:alert", {
type: "error",
message:
`Failed to download/replace ${filename}!\nMaybe try to rerun the Launcher as Admin.`,
});
});
updateDownloader.eventEmitter.on("data", (data) => { updateDownloader.eventEmitter.on("data", (data) => {
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
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)}/${formatBytes(data.total)})...`, status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
formatBytes(data.total)
})...`,
}); });
}); });
await updateDownloader.startDownload(); await updateDownloader.startDownload();
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: -1, progress: -1,
}); });
if (errored) {
mainWindow.webContents.send("ezpplauncher:launchabort");
return;
}
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "osu! is now up to date!", status: "osu! is now up to date!",
}); });
@ -286,18 +339,34 @@ function registerIPCPipes() {
const patchFiles = await getPatcherUpdates(osuPath); const patchFiles = await getPatcherUpdates(osuPath);
if (patchFiles.length > 0) { if (patchFiles.length > 0) {
const patcherDownloader = downloadPatcherUpdates(osuPath, patchFiles); const patcherDownloader = downloadPatcherUpdates(osuPath, patchFiles);
let errored = false;
patcherDownloader.eventEmitter.on("error", (data) => {
const filename = data.fileName;
errored = true;
mainWindow.webContents.send("ezpplauncher:alert", {
type: "error",
message:
`Failed to download/replace ${filename}!\nMaybe try to rerun the Launcher as Admin.`,
});
});
patcherDownloader.eventEmitter.on("data", (data) => { patcherDownloader.eventEmitter.on("data", (data) => {
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
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)}/${formatBytes(data.total)})...`, status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
formatBytes(data.total)
})...`,
}); });
}); });
await patcherDownloader.startDownload(); await patcherDownloader.startDownload();
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: -1, progress: -1,
}) });
if (errored) {
mainWindow.webContents.send("ezpplauncher:launchabort");
return;
}
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Patcher is now up to date!", status: "Patcher is now up to date!",
}); });
@ -330,8 +399,8 @@ function registerIPCPipes() {
richPresence.updateVersion(); richPresence.updateVersion();
richPresence.updateStatus({ richPresence.updateStatus({
state: "Idle in Launcher...", state: "Idle in Launcher...",
details: undefined details: undefined,
}) });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Waiting for cleanup...", status: "Waiting for cleanup...",
}); });
@ -340,13 +409,12 @@ function registerIPCPipes() {
await replaceUIFile(osuPath, true); await replaceUIFile(osuPath, true);
mainWindow.webContents.send("ezpplauncher:launchabort"); mainWindow.webContents.send("ezpplauncher:launchabort");
}, 5000); }, 5000);
} };
await replaceUIFile(osuPath, false); await replaceUIFile(osuPath, false);
runOsuWithDevServer(osuPath, "ez-pp.farm", onExitHook); runOsuWithDevServer(osuPath, "ez-pp.farm", onExitHook);
mainWindow.hide(); mainWindow.hide();
startOsuStatus(); startOsuStatus();
/* mainWindow.webContents.send("ezpplauncher:launchprogress", { /* mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: 0, progress: 0,
}); });

34
package-lock.json generated
View File

@ -13,11 +13,13 @@
"axios": "^1.6.5", "axios": "^1.6.5",
"better-sqlite3": "^9.2.2", "better-sqlite3": "^9.2.2",
"crypto": "^1.0.1", "crypto": "^1.0.1",
"crypto-js": "^4.2.0",
"custom-electron-titlebar": "^4.2.7", "custom-electron-titlebar": "^4.2.7",
"discord-auto-rpc": "^1.0.17", "discord-auto-rpc": "^1.0.17",
"electron-serve": "^1.1.0", "electron-serve": "^1.1.0",
"get-window-by-name": "^2.0.0", "get-window-by-name": "^2.0.0",
"svelte-french-toast": "^1.2.0" "svelte-french-toast": "^1.2.0",
"systeminformation": "^5.21.22"
}, },
"devDependencies": { "devDependencies": {
"@electron/rebuild": "^3.5.0", "@electron/rebuild": "^3.5.0",
@ -3071,6 +3073,11 @@
"integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==", "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
"deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in." "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in."
}, },
"node_modules/crypto-js": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q=="
},
"node_modules/css-declaration-sorter": { "node_modules/css-declaration-sorter": {
"version": "6.4.1", "version": "6.4.1",
"resolved": "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-6.4.1.tgz", "resolved": "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-6.4.1.tgz",
@ -8521,6 +8528,31 @@
"integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==", "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==",
"dev": true "dev": true
}, },
"node_modules/systeminformation": {
"version": "5.21.22",
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.21.22.tgz",
"integrity": "sha512-gNHloAJSyS+sKWkwvmvozZ1eHrdVTEsynWMTY6lvLGBB70gflkBQFw8drXXr1oEXY84+Vr9tOOrN8xHZLJSycA==",
"os": [
"darwin",
"linux",
"win32",
"freebsd",
"openbsd",
"netbsd",
"sunos",
"android"
],
"bin": {
"systeminformation": "lib/cli.js"
},
"engines": {
"node": ">=8.0.0"
},
"funding": {
"type": "Buy me a coffee",
"url": "https://www.buymeacoffee.com/systeminfo"
}
},
"node_modules/tailwind-merge": { "node_modules/tailwind-merge": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.2.0.tgz", "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.2.0.tgz",

View File

@ -12,9 +12,12 @@
"files": [ "files": [
"public/**/*", "public/**/*",
"main.js", "main.js",
"preload.js" "preload.js",
"electron/*",
"electron/**/*"
], ],
"win": { "win": {
"requestedExecutionLevel": "requireAdministrator",
"target": [ "target": [
"portable" "portable"
] ]
@ -29,7 +32,6 @@
"start": "sirv public --no-clear", "start": "sirv public --no-clear",
"electron": "wait-on http://localhost:8080 && electron .", "electron": "wait-on http://localhost:8080 && electron .",
"electron-dev": "concurrently \"yarn run dev\" \"yarn run electron\"", "electron-dev": "concurrently \"yarn run dev\" \"yarn run electron\"",
"preelectron-pack": "yarn run build",
"electron-pack": "electron-builder", "electron-pack": "electron-builder",
"check": "svelte-check --tsconfig ./tsconfig.json" "check": "svelte-check --tsconfig ./tsconfig.json"
}, },
@ -38,11 +40,13 @@
"axios": "^1.6.5", "axios": "^1.6.5",
"better-sqlite3": "^9.2.2", "better-sqlite3": "^9.2.2",
"crypto": "^1.0.1", "crypto": "^1.0.1",
"crypto-js": "^4.2.0",
"custom-electron-titlebar": "^4.2.7", "custom-electron-titlebar": "^4.2.7",
"discord-auto-rpc": "^1.0.17", "discord-auto-rpc": "^1.0.17",
"electron-serve": "^1.1.0", "electron-serve": "^1.1.0",
"get-window-by-name": "^2.0.0", "get-window-by-name": "^2.0.0",
"svelte-french-toast": "^1.2.0" "svelte-french-toast": "^1.2.0",
"systeminformation": "^5.21.22"
}, },
"devDependencies": { "devDependencies": {
"@electron/rebuild": "^3.5.0", "@electron/rebuild": "^3.5.0",

View File

@ -67,7 +67,7 @@
position: "bottom-center", position: "bottom-center",
className: className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 1500, duration: 2000,
}); });
break; break;
} }
@ -76,7 +76,7 @@
position: "bottom-center", position: "bottom-center",
className: className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 1500, duration: 4000,
}); });
break; break;
} }
@ -167,11 +167,3 @@
{:else} {:else}
<Launch /> <Launch />
{/if} {/if}
<style>
.container {
text-align: center;
padding: 1em;
margin: auto;
}
</style>

View File

@ -1,56 +0,0 @@
const DiscordRPC = require("discord-auto-rpc");
const { appName, appVersion } = require("../../appInfo");
const clientId = "1032772293220384808";
let richPresence;
let currentStatus = {
details: " ",
state: "Idle in Launcher...",
startTimestamp: new Date(),
largeImageKey: "ezppfarm",
largeImageText: `${appName} ${appVersion}`,
smallImageKey: " ",
smallImageText: " ",
buttons: [
{
label: "Download the Launcher",
url: "https://git.ez-pp.farm/EZPPFarm/EZPPLauncher/releases/latest"
},
{
label: "Join EZPPFarm",
url: "https://ez-pp.farm/discord"
}
],
instance: false
}
module.exports = {
connect: () => {
if (!richPresence) {
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
richPresence.endlessLogin({ clientId });
richPresence.once("ready", () => {
setInterval(() => {
richPresence.setActivity(currentStatus);
}, 2500)
});
}
},
disconnect: async () => {
if (richPresence) {
await richPresence.clearActivity();
await richPresence.destroy();
richPresence = null;
}
},
updateStatus: ({ state, details }) => {
currentStatus.state = state ?? " ";
currentStatus.details = details ?? " ";
},
updateVersion: (osuVersion) => {
currentStatus.smallImageKey = osuVersion ? "osu" : " ";
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
}
}

View File

@ -1,14 +0,0 @@
const fs = require("fs");
const crypto = require("crypto");
(async () => {
const correctHash = 'b66478cc0f9ec50810489a039ced642b';
const filePath = 'C:\\Users\\horiz\\AppData\\Local\\osu!\\avcodec-51.dll';
const fileHash = crypto.createHash('md5').update(await fs.promises.readFile(filePath)).digest('hex');
console.log({
correctHash,
fileHash,
matching: correctHash === fileHash,
})
})();

View File

@ -1,9 +0,0 @@
const { getGlobalConfig } = require("../src/util/osuUtil");
const config = require("../src/config/config");
(async () => {
const osuPath = config.get("osuPath");
const globalConfig = getGlobalConfig(osuPath);
const globalConfigContent = await globalConfig.get("_ReleaseStream");
console.log(globalConfigContent);
})();

View File

@ -1,7 +0,0 @@
const { getUpdateFiles } = require("../src/util/osuUtil");
(async () => {
const osuPath = "";
const latestFiles = await getUpdateFiles("stable40");
console.log(latestFiles);
})();

View File

@ -1,7 +1,16 @@
{ {
"extends": "./node_modules/@tsconfig/svelte/tsconfig.json", "extends": "./node_modules/@tsconfig/svelte/tsconfig.json",
"include": ["src/**/*"], "include": [
"src/**/*",
"electron/richPresence.js",
"electron/config.js",
"electron/cryptoUtil.js",
"electron/executeUtil.js",
"electron/formattingUtil.js",
"electron/hwidUtil.js",
"electron/osuUtil.js"
],
"exclude": ["node_modules/*", "__sapper__/*", "public/*"], "exclude": ["node_modules/*", "__sapper__/*", "public/*"],
"compilerOptions": { "compilerOptions": {
"typeRoots": [ "typeRoots": [