diff --git a/appInfo.js b/electron/appInfo.js similarity index 100% rename from appInfo.js rename to electron/appInfo.js diff --git a/src/config/config.js b/electron/config.js similarity index 100% rename from src/config/config.js rename to electron/config.js diff --git a/electron/cryptoUtil.js b/electron/cryptoUtil.js new file mode 100644 index 0000000..354e176 --- /dev/null +++ b/electron/cryptoUtil.js @@ -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 }; diff --git a/src/util/executeUtil.js b/electron/executeUtil.js similarity index 100% rename from src/util/executeUtil.js rename to electron/executeUtil.js diff --git a/src/util/formattingUtil.js b/electron/formattingUtil.js similarity index 100% rename from src/util/formattingUtil.js rename to electron/formattingUtil.js diff --git a/electron/hwidUtil.js b/electron/hwidUtil.js new file mode 100644 index 0000000..285ff88 --- /dev/null +++ b/electron/hwidUtil.js @@ -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; diff --git a/src/util/osuUtil.js b/electron/osuUtil.js similarity index 72% rename from src/util/osuUtil.js rename to electron/osuUtil.js index 2d1d94c..962b2d2 100644 --- a/src/util/osuUtil.js +++ b/electron/osuUtil.js @@ -3,7 +3,7 @@ const path = require("path"); const crypto = require("crypto"); const EventEmitter = require("events"); const { default: axios } = require("axios"); -const { runFile } = require("./executeUtil"); +const { runFile } = require("./executeUtil.js"); const checkUpdateURL = "https://osu.ppy.sh/web/check-updates.php?action=check&stream="; @@ -38,22 +38,22 @@ const patcherFiles = [ { name: "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", 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 = [ { name: "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) { const allFiles = await fs.promises.readdir(path); @@ -175,13 +175,17 @@ async function getFilesThatNeedUpdate(osuPath, releaseStreamFiles) { const fileOnDisk = path.join(osuPath, fileName); if (fs.existsSync(fileOnDisk)) { if (ignoredOsuEntities.includes(fileName)) continue; - const fileHashOnDisk = crypto.createHash("md5").update(fs.readFileSync(fileOnDisk)).digest("hex"); - if (fileHashOnDisk.trim().toLowerCase() != fileHash.trim().toLowerCase()) { + const fileHashOnDisk = crypto.createHash("md5").update( + fs.readFileSync(fileOnDisk), + ).digest("hex"); + if ( + fileHashOnDisk.trim().toLowerCase() != fileHash.trim().toLowerCase() + ) { console.log({ fileOnDisk, fileHashOnDisk, - fileHash - }) + fileHash, + }); updateFiles.push(updatePatch); } } else updateFiles.push(updatePatch); @@ -207,7 +211,7 @@ function downloadUpdateFiles(osuPath, updateFiles) { fileName, loaded, total, - progress: Math.floor((loaded / total) * 100) + progress: Math.floor((loaded / total) * 100), }); }, }); @@ -216,20 +220,30 @@ function downloadUpdateFiles(osuPath, updateFiles) { fileName, loaded: 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 return true; - } + }; return { eventEmitter, startDownload, - } + }; } function runOsuWithDevServer(osuPath, serverDomain, onExit) { @@ -238,7 +252,6 @@ function runOsuWithDevServer(osuPath, serverDomain, onExit) { } async function getPatcherUpdates(osuPath) { - const filesToDownload = []; const patcherDir = path.join(osuPath, "EZPPLauncher"); @@ -246,9 +259,15 @@ async function getPatcherUpdates(osuPath) { for (const patcherFile of patcherFiles) { if (fs.existsSync(path.join(patcherDir, patcherFile.name))) { - const latestPatchFileHash = await (await fetch(patcherFile.url_hash)).text(); - 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); + const latestPatchFileHash = await (await fetch(patcherFile.url_hash)) + .text(); + 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); } @@ -259,7 +278,6 @@ function downloadPatcherUpdates(osuPath, patcherUpdates) { const eventEmitter = new EventEmitter(); const startDownload = async () => { - const patcherDir = path.join(osuPath, "EZPPLauncher"); if (!fs.existsSync(patcherDir)) fs.mkdirSync(patcherDir); @@ -274,23 +292,32 @@ function downloadPatcherUpdates(osuPath, patcherUpdates) { fileName, loaded, 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 { eventEmitter, startDownload, - } + }; } async function getUIFiles(osuPath) { - const filesToDownload = []; const ezppLauncherDir = path.join(osuPath, "EZPPLauncher"); @@ -299,8 +326,13 @@ async function getUIFiles(osuPath) { for (const uiFile of uiFiles) { if (fs.existsSync(path.join(ezppLauncherDir, uiFile.name))) { const latestPatchFileHash = await (await fetch(uiFile.url_hash)).text(); - const localPatchFileHash = crypto.createHash("md5").update(fs.readFileSync(path.join(ezppLauncherDir, uiFile.name))).digest("hex"); - if (latestPatchFileHash.trim().toLowerCase() != localPatchFileHash.trim().toLowerCase()) filesToDownload.push(uiFile); + const localPatchFileHash = crypto.createHash("md5").update( + fs.readFileSync(path.join(ezppLauncherDir, uiFile.name)), + ).digest("hex"); + if ( + latestPatchFileHash.trim().toLowerCase() != + localPatchFileHash.trim().toLowerCase() + ) filesToDownload.push(uiFile); } else filesToDownload.push(uiFile); } @@ -311,7 +343,6 @@ function downloadUIFiles(osuPath, uiFiles) { const eventEmitter = new EventEmitter(); const startDownload = async () => { - const ezpplauncherDir = path.join(osuPath, "EZPPLauncher"); if (!fs.existsSync(ezpplauncherDir)) fs.mkdirSync(ezpplauncherDir); @@ -326,33 +357,85 @@ function downloadUIFiles(osuPath, uiFiles) { fileName, loaded, 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 { eventEmitter, startDownload, - } + }; } async function replaceUIFile(osuPath, revert) { if (!revert) { const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!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); } else { const oldOsuUIFile = path.join(osuPath, "osu!ui.dll"); const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll"); 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 }; +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()); + } + /* 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; +} + +module.exports = { + isValidOsuFolder, + getUserConfig, + getGlobalConfig, + getUpdateFiles, + getFilesThatNeedUpdate, + downloadUpdateFiles, + runOsuWithDevServer, + getPatcherUpdates, + downloadPatcherUpdates, + downloadUIFiles, + getUIFiles, + replaceUIFile, + findOsuInstallation, +}; diff --git a/electron/richPresence.js b/electron/richPresence.js new file mode 100644 index 0000000..976c5f8 --- /dev/null +++ b/electron/richPresence.js @@ -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}` : " "; + }, +}; diff --git a/main.js b/main.js index e5be96d..9bceb8b 100644 --- a/main.js +++ b/main.js @@ -3,16 +3,32 @@ const { app, BrowserWindow, Menu, ipcMain, dialog } = require("electron"); const path = require("path"); const serve = require("electron-serve"); const loadURL = serve({ directory: "public" }); -const config = require("./src/config/config"); +const config = require("./electron/config"); const { setupTitlebar, attachTitlebarToWindow } = require( "custom-electron-titlebar/main", ); -const { isValidOsuFolder, getUpdateFiles, getGlobalConfig, getFilesThatNeedUpdate, downloadUpdateFiles, getUserConfig, runOsuWithDevServer, getPatcherUpdates, downloadPatcherUpdates, getUIFiles, downloadUIFiles, replaceUIFile } = require("./src/util/osuUtil"); -const { formatBytes } = require("./src/util/formattingUtil"); +const { + isValidOsuFolder, + getUpdateFiles, + getGlobalConfig, + getFilesThatNeedUpdate, + downloadUpdateFiles, + getUserConfig, + runOsuWithDevServer, + getPatcherUpdates, + downloadPatcherUpdates, + getUIFiles, + downloadUIFiles, + replaceUIFile, + findOsuInstallation, +} = require("./electron/osuUtil"); +const { formatBytes } = require("./electron/formattingUtil"); const windowName = require("get-window-by-name"); const { existsSync } = require("fs"); -const { runFileDetached } = require("./src/util/executeUtil"); -const richPresence = require("./src/discord/richPresence"); +const { runFileDetached } = require("./electron/executeUtil"); +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 // be closed automatically when the JavaScript object is garbage collected. @@ -40,7 +56,11 @@ function startOsuStatus() { if (!osuLoaded) { osuLoaded = true; setTimeout(() => { - const patcherExecuteable = path.join(userOsuPath, "EZPPLauncher", "patcher.exe"); + const patcherExecuteable = path.join( + userOsuPath, + "EZPPLauncher", + "patcher.exe", + ); if (existsSync(patcherExecuteable)) { runFileDetached(userOsuPath, patcherExecuteable); } @@ -102,15 +122,6 @@ function startOsuStatus() { details, state: infoText }) - /* const components = windowTitle.split(" - "); - const splitTitle = [components.shift(), components.join(" - ")] - const currentMap = splitTitle[1]; - if (!currentMap.endsWith(".osu")) { - richPresence.updateStatus({ - state: "Playing...", - details: currentMap - }) - } */ } }, 2500); } @@ -121,6 +132,7 @@ function stopOsuStatus() { function registerIPCPipes() { ipcMain.handle("ezpplauncher:login", async (e, args) => { + const hwid = getHwId(); const timeout = new AbortController(); const timeoutId = setTimeout(() => timeout.abort(), 8000); try { @@ -143,7 +155,7 @@ function registerIPCPipes() { if ("user" in result) { if (args.saveCredentials) { config.set("username", args.username); - config.set("password", args.password); + config.set("password", cryptUtil.encrypt(args.password, hwid)); } currentUser = args; config.remove("guest"); @@ -162,11 +174,23 @@ function registerIPCPipes() { } }); - ipcMain.handle("ezpplauncher:autologin", async (e) => { + ipcMain.handle("ezpplauncher:autologin-active", async (e) => { const username = config.get("username"); const password = config.get("password"); const guest = config.get("guest"); + if (guest != undefined) return true; + return username != undefined && password != undefined; + }); + + ipcMain.handle("ezpplauncher:autologin", async (e) => { + const hwid = getHwId(); + const username = config.get("username"); + const guest = config.get("guest"); if (guest) return { code: 200, message: "Login as guest", guest: true }; + if (username == undefined) { + return { code: 200, message: "No autologin" }; + } + const password = cryptUtil.decrypt(config.get("password"), hwid); if (username == undefined || password == undefined) { return { code: 200, message: "No autologin" }; } @@ -196,6 +220,8 @@ function registerIPCPipes() { }; } return result; + } else { + config.remove("password"); } return { code: 500, @@ -220,7 +246,7 @@ function registerIPCPipes() { config.remove("username"); config.remove("password"); config.remove("guest"); - currentUser = undefined + currentUser = undefined; return true; }); @@ -228,6 +254,18 @@ function registerIPCPipes() { return config.all(); }); + ipcMain.handle("ezpplauncher:detect-folder", async (e) => { + const detected = await findOsuInstallation(); + if (detected && await isValidOsuFolder(detected)) { + mainWindow.webContents.send("ezpplauncher:alert", { + type: "success", + message: "osu! path successfully saved!", + }); + config.set("osuPath", detected); + } + return config.all(); + }); + ipcMain.handle("ezpplauncher:set-folder", async (e) => { const folderResult = await dialog.showOpenDialog({ title: "Select osu! installation directory", @@ -285,33 +323,65 @@ function registerIPCPipes() { const updateFiles = await getFilesThatNeedUpdate(osuPath, latestFiles); if (uiFiles.length > 0) { 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) => { mainWindow.webContents.send("ezpplauncher:launchprogress", { 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) + })...`, }); }); await uiDownloader.startDownload(); mainWindow.webContents.send("ezpplauncher:launchprogress", { progress: -1, }); + if (errored) { + mainWindow.webContents.send("ezpplauncher:launchabort"); + return; + } } if (updateFiles.length > 0) { 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) => { mainWindow.webContents.send("ezpplauncher:launchprogress", { 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) + })...`, }); }); await updateDownloader.startDownload(); mainWindow.webContents.send("ezpplauncher:launchprogress", { progress: -1, }); + if (errored) { + mainWindow.webContents.send("ezpplauncher:launchabort"); + return; + } mainWindow.webContents.send("ezpplauncher:launchstatus", { status: "osu! is now up to date!", }); @@ -331,18 +401,34 @@ function registerIPCPipes() { const patchFiles = await getPatcherUpdates(osuPath); if (patchFiles.length > 0) { 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) => { mainWindow.webContents.send("ezpplauncher:launchprogress", { 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) + })...`, }); }); await patcherDownloader.startDownload(); mainWindow.webContents.send("ezpplauncher:launchprogress", { progress: -1, - }) + }); + if (errored) { + mainWindow.webContents.send("ezpplauncher:launchabort"); + return; + } mainWindow.webContents.send("ezpplauncher:launchstatus", { status: "Patcher is now up to date!", }); @@ -375,8 +461,8 @@ function registerIPCPipes() { stopOsuStatus(); richPresence.updateVersion(); richPresence.updateStatus({ - details: "Idle in Launcher...", - state: undefined + state: "Idle in Launcher...", + details: undefined }) mainWindow.webContents.send("ezpplauncher:launchstatus", { status: "Waiting for cleanup...", @@ -386,11 +472,19 @@ function registerIPCPipes() { await replaceUIFile(osuPath, true); mainWindow.webContents.send("ezpplauncher:launchabort"); }, 5000); - } + }; await replaceUIFile(osuPath, false); runOsuWithDevServer(osuPath, "ez-pp.farm", onExitHook); mainWindow.hide(); startOsuStatus(); + + + /* mainWindow.webContents.send("ezpplauncher:launchprogress", { + progress: 0, + }); + mainWindow.webContents.send("ezpplauncher:launchprogress", { + progress: 100, + }); */ return true; }); } @@ -400,8 +494,8 @@ function createWindow() { // Create the browser window. mainWindow = new BrowserWindow({ - width: 600, - height: 380, + width: 550, + height: 350, resizable: false, frame: false, titleBarStyle: "hidden", diff --git a/package-lock.json b/package-lock.json index e44ad7e..595d3d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,17 +7,21 @@ "": { "name": "ezpplauncher-next", "version": "2.0.0", + "hasInstallScript": true, "license": "MIT", "dependencies": { "@types/better-sqlite3": "^7.6.8", "axios": "^1.6.5", "better-sqlite3": "^9.2.2", "crypto": "^1.0.1", + "crypto-js": "^4.2.0", "custom-electron-titlebar": "^4.2.7", "discord-auto-rpc": "^1.0.17", "electron-serve": "^1.1.0", "get-window-by-name": "^2.0.0", - "svelte-french-toast": "^1.2.0" + "regedit-rs": "^1.0.2", + "svelte-french-toast": "^1.2.0", + "systeminformation": "^5.21.22" }, "devDependencies": { "@electron/rebuild": "^3.5.0", @@ -3071,6 +3075,11 @@ "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." }, + "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": { "version": "6.4.1", "resolved": "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-6.4.1.tgz", @@ -7044,6 +7053,64 @@ "node": ">=8.10.0" } }, + "node_modules/regedit-rs": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/regedit-rs/-/regedit-rs-1.0.2.tgz", + "integrity": "sha512-4vEgiZNO1FCG8z/Zx3v/6PU1+eZ+ELe6R0ca+VB96Vw+Mi3M0IVHAjtMFbl97lUSX11dJqpyousX/wY8QcI1lA==", + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "regedit-rs-win32-arm64-msvc": "1.0.2", + "regedit-rs-win32-ia32-msvc": "1.0.2", + "regedit-rs-win32-x64-msvc": "1.0.2" + } + }, + "node_modules/regedit-rs-win32-arm64-msvc": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/regedit-rs-win32-arm64-msvc/-/regedit-rs-win32-arm64-msvc-1.0.2.tgz", + "integrity": "sha512-hM1sxazOJWKmiC9DM8QXW9Iqm50Mh/Y9G4/rRYQpWXjMzq7lTqjwVZRkAoBrHliFS6d1Lt4qkm5+Ybt6GkbDpw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/regedit-rs-win32-ia32-msvc": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/regedit-rs-win32-ia32-msvc/-/regedit-rs-win32-ia32-msvc-1.0.2.tgz", + "integrity": "sha512-FLINrCJ30wm6NYw7skQUDET8NP1N46kH77dqesCiU+/FjWzzPE5luZYY+j4uf+hKjPY6/MCj2CB9l9VdPhaBVQ==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/regedit-rs-win32-x64-msvc": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/regedit-rs-win32-x64-msvc/-/regedit-rs-win32-x64-msvc-1.0.2.tgz", + "integrity": "sha512-ccCSyd5vWBKVWftBKLKzegqwwPMWcQtIW0ub66dCFFuv2s+x2EcZZWGdD9dVXX2Z6V9DU2JRPKgWUNjVPaj6Xg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/regenerator-runtime": { "version": "0.14.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", @@ -8521,6 +8588,31 @@ "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==", "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": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.2.0.tgz", diff --git a/package.json b/package.json index f2c13a1..49e9a40 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,12 @@ "files": [ "public/**/*", "main.js", - "preload.js" + "preload.js", + "electron/*", + "electron/**/*" ], "win": { + "requestedExecutionLevel": "requireAdministrator", "target": [ "portable" ] @@ -29,8 +32,9 @@ "start": "sirv public --no-clear", "electron": "wait-on http://localhost:8080 && electron .", "electron-dev": "concurrently \"yarn run dev\" \"yarn run electron\"", - "preelectron-pack": "yarn run build", + "preelectron-pack": "electron-rebuild && yarn run build", "electron-pack": "electron-builder", + "postinstall": "electron-builder install-app-deps", "check": "svelte-check --tsconfig ./tsconfig.json" }, "dependencies": { @@ -38,11 +42,14 @@ "axios": "^1.6.5", "better-sqlite3": "^9.2.2", "crypto": "^1.0.1", + "crypto-js": "^4.2.0", "custom-electron-titlebar": "^4.2.7", "discord-auto-rpc": "^1.0.17", "electron-serve": "^1.1.0", "get-window-by-name": "^2.0.0", - "svelte-french-toast": "^1.2.0" + "regedit-rs": "^1.0.2", + "svelte-french-toast": "^1.2.0", + "systeminformation": "^5.21.22" }, "devDependencies": { "@electron/rebuild": "^3.5.0", diff --git a/preload.js b/preload.js index 7e15fd6..add59e5 100644 --- a/preload.js +++ b/preload.js @@ -22,6 +22,15 @@ window.addEventListener("login-attempt", async (e) => { ); }); +window.addEventListener("autologin-active", async (e) => { + const autologin = await ipcRenderer.invoke( + "ezpplauncher:autologin-active", + ); + window.dispatchEvent( + new CustomEvent("autologin-result", { detail: autologin }), + ); +}); + window.addEventListener("autologin-attempt", async () => { const loginResult = await ipcRenderer.invoke("ezpplauncher:autologin"); window.dispatchEvent( @@ -48,6 +57,13 @@ window.addEventListener("settings-get", async () => { ); }); +window.addEventListener("folder-auto", async (e) => { + const result = await ipcRenderer.invoke("ezpplauncher:detect-folder"); + window.dispatchEvent( + new CustomEvent("settings-result", { detail: result }), + ); +}); + window.addEventListener("folder-set", async (e) => { const result = await ipcRenderer.invoke("ezpplauncher:set-folder"); window.dispatchEvent( diff --git a/public/index.html b/public/index.html index c6ad532..902395f 100644 --- a/public/index.html +++ b/public/index.html @@ -18,5 +18,5 @@ - + diff --git a/rollup.config.js b/rollup.config.js index b722fa7..e1987ea 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -9,7 +9,6 @@ import image from "@rollup/plugin-image"; import sveltePreprocess from "svelte-preprocess"; import typescript from "@rollup/plugin-typescript"; import progress from "rollup-plugin-progress"; -import findUnused from "rollup-plugin-unused"; const production = !process.env.ROLLUP_WATCH; @@ -48,8 +47,7 @@ export default { file: "public/build/bundle.js", }, plugins: [ - findUnused(), - progress({ clearLine: true }), + !production && progress({ clearLine: true }), svelte({ preprocess: sveltePreprocess({ sourceMap: !production }), compilerOptions: { @@ -61,7 +59,7 @@ export default { // we'll extract any component CSS out into // a separate file - better for performance css({ output: "bundle.css" }), - postcss(), + postcss({ sourceMap: "inline" }), // If you have external dependencies installed from // npm, you'll most likely need these plugins. In diff --git a/src/App.svelte b/src/App.svelte index 7c60e2b..bcc4faf 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -5,8 +5,10 @@ DropdownItem, DropdownHeader, DropdownDivider, + Button, } from "flowbite-svelte"; import { + ArrowLeftSolid, ArrowRightFromBracketSolid, ArrowRightToBracketSolid, UserSettingsSolid, @@ -38,6 +40,12 @@ window.dispatchEvent(new CustomEvent("logout")); currentUser.set(undefined); currentPage.set(Page.Login); + toast.success("Successfully logged out!", { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 2000, + }); }; window.addEventListener("launchStatusUpdate", (e) => { @@ -67,7 +75,7 @@ position: "bottom-center", className: "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", - duration: 1500, + duration: 2000, }); break; } @@ -76,7 +84,7 @@ position: "bottom-center", className: "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", - duration: 1500, + duration: 4000, }); break; } @@ -96,14 +104,27 @@
-
+
+ {#if $currentPage == Page.Settings} + + {/if} EZPPFarm Logo EZPPLauncher
{#if $currentPage == Page.Launch} -
+
{/if} - - diff --git a/src/app.pcss b/src/app.pcss index 5e16355..6ede246 100644 --- a/src/app.pcss +++ b/src/app.pcss @@ -20,6 +20,10 @@ html .cet-titlebar .cet-control-icon svg { display: none; } +.cet-container { + overflow: hidden !important; +} + .indeterminate { background-image: repeating-linear-gradient( 90deg, diff --git a/src/pages/Login.svelte b/src/pages/Login.svelte index 47bcf62..8545a8d 100644 --- a/src/pages/Login.svelte +++ b/src/pages/Login.svelte @@ -15,81 +15,118 @@ const processLogin = async () => { loading = true; - window.addEventListener( - "login-result", - (e) => { - const customEvent = e as CustomEvent; - const resultData = customEvent.detail; - const wasSuccessful = "user" in resultData; + const loginPromise = new Promise((res, rej) => { + window.addEventListener( + "login-result", + (e) => { + const customEvent = e as CustomEvent; + const resultData = customEvent.detail; + const wasSuccessful = "user" in resultData; - if (!wasSuccessful) { - const errorResult = resultData as Error; - toast.error(errorResult.message, { - position: "bottom-center", - className: - "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", - duration: 1500, - }); - loading = false; - return; - } - const userResult = resultData.user as User; - currentUser.set(userResult); - currentPage.set(Page.Launch); - toast.success(`Welcome back, ${userResult.name}!`, { - position: "bottom-center", - className: - "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", - duration: 3000, - }); - }, - { once: true } - ); - window.dispatchEvent( - new CustomEvent("login-attempt", { - detail: { username, password, saveCredentials }, - }) - ); - }; - - const tryAutoLogin = async () => { - loading = true; - await new Promise((res) => setTimeout(res, 1500)); - window.addEventListener( - "login-result", - (e) => { - const customEvent = e as CustomEvent; - const resultData = customEvent.detail; - const isGuest = "guest" in resultData; - const wasSuccessful = "user" in resultData; - if (isGuest) { + if (!wasSuccessful) { + /* const errorResult = resultData as Error; + toast.error(errorResult.message, { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 1500, + }); */ + rej(); + loading = false; + return; + } + const userResult = resultData.user as User; + currentUser.set(userResult); currentPage.set(Page.Launch); - toast.success(`Logged in as Guest`, { + res(); + toast.success(`Welcome back, ${userResult.name}!`, { position: "bottom-center", className: "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", duration: 3000, }); - return; - } - if (!wasSuccessful) { - loading = false; - return; - } - const userResult = resultData.user as User; - currentUser.set(userResult); - currentPage.set(Page.Launch); - toast.success(`Welcome back, ${userResult.name}!`, { - position: "bottom-center", - className: - "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", - duration: 3000, - }); - loading = false; + }, + { once: true } + ); + window.dispatchEvent( + new CustomEvent("login-attempt", { + detail: { username, password, saveCredentials }, + }) + ); + }); + toast.promise( + loginPromise, + { + loading: "Logging in...", + success: "Successfully logged in!", + error: "Failed to login.", }, - { once: true } + { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 3000, + } + ); + }; + + const tryAutoLogin = async () => { + loading = true; + const loginPromise = new Promise((res, rej) => { + window.addEventListener( + "login-result", + (e) => { + const customEvent = e as CustomEvent; + const resultData = customEvent.detail; + const isGuest = "guest" in resultData; + const wasSuccessful = "user" in resultData; + console.log(resultData); + if (isGuest) { + currentPage.set(Page.Launch); + res(); + toast.success(`Logged in as Guest`, { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 3000, + }); + return; + } + if (!wasSuccessful) { + loading = false; + rej(); + return; + } + const userResult = resultData.user as User; + currentUser.set(userResult); + currentPage.set(Page.Launch); + res(); + toast.success(`Welcome back, ${userResult.name}!`, { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 3000, + }); + loading = false; + }, + { once: true } + ); + window.dispatchEvent(new CustomEvent("autologin-attempt")); + }); + toast.promise( + loginPromise, + { + loading: "Logging in...", + success: "Successfully logged in!", + error: "Failed to login.", + }, + { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 3000, + } ); - window.dispatchEvent(new CustomEvent("autologin-attempt")); }; const proceedAsGuest = () => { @@ -103,10 +140,24 @@ }); }; - if (!$startup) { - startup.set(true); - tryAutoLogin(); - } + const shouldAutologin = async () => { + const shouldAutologin = await new Promise((res) => { + window.addEventListener("autologin-result", (e) => { + const customEvent = e as CustomEvent; + const resultData = customEvent.detail; + res(resultData); + }); + window.dispatchEvent(new CustomEvent("autologin-active")); + }); + return shouldAutologin; + }; + + (async () => { + if (!$startup) { + startup.set(true); + if (await shouldAutologin()) tryAutoLogin(); + } + })();
- import { Button, ButtonGroup, Input } from "flowbite-svelte"; - import { FolderSolid } from "flowbite-svelte-icons"; + import { + Button, + ButtonGroup, + Input, + Label, + Toggle, + Tooltip, + } from "flowbite-svelte"; + import { FileSearchSolid, FolderSolid } from "flowbite-svelte-icons"; import { currentPage } from "../storage/localStore"; import { Page } from "../consts/pages"; let folderPath: string = ""; + let patching: boolean = true; + let presence: boolean = true; + window.addEventListener("settings-result", (e) => { const settings: Record[] = (e as CustomEvent).detail; const osuPath = settings.find((setting) => setting.key == "osuPath"); @@ -16,17 +26,38 @@ const setFolderPath = () => { window.dispatchEvent(new CustomEvent("folder-set")); }; + + const detectFolderPath = () => { + window.dispatchEvent(new CustomEvent("folder-auto")); + }; + + const togglePatching = () => { + patching = !patching; + }; + + const togglePresence = () => { + presence = !presence; + };
+
+ Discord Presence + Patching +
+ - -
+ /> + -
+ + +
diff --git a/tailwind.config.cjs b/tailwind.config.cjs index 5e2693f..29d823d 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -8,6 +8,10 @@ const config = { theme: { extend: { keyframes: { + slideIn: { + "0%": { opacity: "0", transform: "translateX(-5px)" }, + "100%": { opacity: "1" }, + }, fadeIn: { "0%": { opacity: "0", transform: "translateY(5px)" }, "100%": { opacity: "1" }, @@ -18,11 +22,12 @@ const config = { }, }, animation: { + sideIn: "slideIn 1s ease forwards", fadeIn: "fadeIn 1s ease forwards", fadeOut: "fadeOut 1s ease forwards", }, transitionProperty: { - 'width': 'width', + "width": "width", }, colors: { // flowbite-svelte diff --git a/tests/fileHash.js b/tests/fileHash.js deleted file mode 100644 index f2ba454..0000000 --- a/tests/fileHash.js +++ /dev/null @@ -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, - }) -})(); \ No newline at end of file diff --git a/tests/osuConfig.js b/tests/osuConfig.js deleted file mode 100644 index 7365164..0000000 --- a/tests/osuConfig.js +++ /dev/null @@ -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); -})(); \ No newline at end of file diff --git a/tests/osuUpdate.js b/tests/osuUpdate.js deleted file mode 100644 index 017b2a5..0000000 --- a/tests/osuUpdate.js +++ /dev/null @@ -1,7 +0,0 @@ -const { getUpdateFiles } = require("../src/util/osuUtil"); - -(async () => { - const osuPath = ""; - const latestFiles = await getUpdateFiles("stable40"); - console.log(latestFiles); -})(); diff --git a/tsconfig.json b/tsconfig.json index 5263aed..8c8fe1f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,16 @@ { "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/*"], "compilerOptions": { "typeRoots": [