some experimental stuff 👀

This commit is contained in:
HorizonCode 2023-06-02 14:13:09 +02:00
parent 769a88521e
commit 42777c9e0c
5 changed files with 444 additions and 329 deletions

17
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"args" : ["."],
"outputCapture": "std"
}
]
}

17
app.js
View File

@ -195,11 +195,19 @@ const run = () => {
} else linuxWMCtrlFound = true;
} else {
const osuFolder = await config.get("osuPath");
console.log(osuFolder, !osuFolder || osuFolder == "");
if (!osuFolder || osuFolder == "") {
const foundFolder = await osuUtil.findOsuInstallation();
if (foundFolder && osuUtil.isValidOsuFolder(foundFolder)) {
mainWindow.webContents.send('alert_message', foundFolder);
}
console.log("osu! Installation located at: ", foundFolder);
}
}
});
ipcMain.on("alert_response", async (event, path) => {
console.log("yes");
await config.set("osuPath", path);
})
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) mainWindow = createWindow();
@ -208,6 +216,8 @@ const run = () => {
app.quit()
})
ipcMain.handle('launch', async () => {
const osuFolder = await config.get("osuPath");
await osuUtil.updateOsuCfg(path.join(osuFolder, "osu!.cfg"));
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
const username = await config.get('username');
const password = await config.get('password');
@ -221,13 +231,17 @@ const run = () => {
await osuUtil.setConfigValue(osuConfig.path, "Username", "");
await osuUtil.setConfigValue(osuConfig.path, "Password", "");
}
await osuUtil.replaceUI(osuFolder, true);
rpc.updateState("Launching osu!...");
isIngame = true;
if (mainWindow.isVisible()) mainWindow.hide();
const result = await osuUtil.startOsuWithDevServer(tempOsuPath, "ez-pp.farm", async () => {
isIngame = false;
if (!mainWindow.isVisible()) mainWindow.show();
setTimeout(async () => {
isIngame = false;
await osuUtil.replaceUI(osuFolder, false);
await doUpdateCheck(mainWindow);
}, 2000);
});
return result;
})
@ -344,6 +358,7 @@ async function tryLogin(window) {
async function doUpdateCheck(window) {
const osuPath = await config.get("osuPath");
console.log("osuPath:", osuPath);
if (!osuPath || osuPath.trim == "") {
window.webContents.send('status_update', {
type: "missing-folder"

View File

@ -13,6 +13,19 @@ body {
background-color: hsl(var(--main-bg), 24%, 19%);
}
p.text-white {
margin: .5rem 0;
color: white;
}
.quotetext {
color: white;
background-color: #727272;
border-radius: .35rem;
font-size: .95rem;
padding: .25rem .5rem;
}
.sections {
display: flex;
flex-flow: column;
@ -176,7 +189,7 @@ body {
.btn-accent:hover {
background: hsl(var(--main-accent), 93%, 42%);
color: #fff ;
color: #fff;
}
.btn-grey,

View File

@ -8,8 +8,10 @@ const { EventEmitter } = require('events');
const { DownloaderHelper } = require('node-downloader-helper');
const checkUpdateURL = "https://osu.ppy.sh/web/check-updates.php?action=check&stream=";
const customUIDLLPath = "";
const customUIDLLName = "ezpp!ui.dll";
const ignoredOsuEntities = [
'osu!auth.dll'
'osu!auth.dll',
]
const osuEntities = [
'avcodec-51.dll',
@ -174,6 +176,34 @@ async function setConfigValue(configPath, key, value) {
}
await fs.promises.writeFile(configPath, configLines.join("\n"), 'utf-8');
}
async function updateOsuCfg(cfgPath) {
const osuFolder = path.dirname(cfgPath);
const fileStream = await fs.promises.readFile(cfgPath, "utf-8");
const lines = fileStream.split(/\r?\n/);
const newLines = [];
for (const line of lines) {
if (line.includes(' = ')) {
const argsPair = line.split(' = ', 2);
const keyname = argsPair[0]
const value = argsPair[1];
if (keyname.startsWith("h_")) {
const filename = keyname.substring(2, keyname.length);
const filepath = path.join(osuFolder, 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(`${keyname} = ${existingFileMD5}`);
} else {
newLines.push(line);
}
}
}
await fs.promises.writeFile(cfgPath, newLines.join("\n"), 'utf-8');
}
async function findOsuInstallation() {
const regedit = require('qiao-regedit');
@ -183,14 +213,32 @@ async function findOsuInstallation() {
if (line.includes("REG_SZ")) {
let value = (line.trim().split(" ")[2]);
value = value.substring(1, value.length - 3);
return value.trim();
return path.dirname(value.trim());
}
}
return undefined;
}
async function replaceUI(folder, isStart) {
const ezppUIFile = path.join(folder, customUIDLLName);
const osuUIFile = path.join(folder, "osu!ui.dll");
const osuUIFileBackup = path.join(folder, "osu!ui.dll.bak");
if (isStart) {
if (fs.existsSync(osuUIFileBackup)) await fs.promises.unlink(osuUIFileBackup);
await fs.promises.rename(osuUIFile, osuUIFileBackup);
await new Promise((res) => setTimeout(res, 1000));
await fs.promises.rename(ezppUIFile, osuUIFile);
} else {
if (!fs.existsSync(osuUIFileBackup)) return;
await fs.promises.rename(osuUIFile, ezppUIFile);
await new Promise((res) => setTimeout(res, 1000));
await fs.promises.rename(osuUIFileBackup, osuUIFile);
}
}
module.exports = {
isValidOsuFolder, getLatestConfig, getUpdateFiles, filesThatNeedUpdate,
downloadUpdateFiles, startOsuWithDevServer: startWithDevServer, setConfigValue,
findOsuInstallation
findOsuInstallation, replaceUI, updateOsuCfg
}

View File

@ -188,6 +188,28 @@ window.addEventListener('DOMContentLoaded', () => {
}
})
ipcRenderer.on('alert_message', async (event, path) => {
const res = await Swal.fire({
title: 'Hey!',
html: `<p class="text-white">Detected a osu! installation at</p><span class="quotetext">${path}</span><p class="text-white">Is this correct?</p>`,
icon: 'info',
showCancelButton: true,
confirmButtonText: 'Yes',
cancelButtonText: 'No',
});
if (res.isConfirmed) {
$('#currentOsuPath').text(path);
ipcRenderer.send('alert_response', path);
Swal.fire({
title: 'Success!',
text: 'osu! folder set.',
icon: 'success',
confirmButtonText: 'Cool'
})
ipcRenderer.send("do-update-check");
}
})
ipcRenderer.on('status_update', (event, status) => {
switch (status.type) {
case "up-to-date":