From 9ac75a309b59cbad6ac1bdcecc51e458e1ac1289 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Mon, 17 Oct 2022 18:10:17 +0200 Subject: [PATCH] update electron, add dpapi function wip --- osuUtil.js | 28 +++++++++++++++++++++++++++- package.json | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/osuUtil.js b/osuUtil.js index 6f99811..edf702f 100644 --- a/osuUtil.js +++ b/osuUtil.js @@ -3,11 +3,13 @@ const fu = require('./fileUtil'); const path = require('path'); const crypto = require('crypto'); const axios = require('axios').default; +const dpapi = require('wincrypt'); const executeUtil = require('./executeUtil'); const { EventEmitter } = require('events'); const { DownloaderHelper } = require('node-downloader-helper'); const checkUpdateURL = "https://osu.ppy.sh/web/check-updates.php?action=check&stream="; +const osuEncryptBuffer = Buffer.from('cu24180ncjeiu0ci1nwui', "utf-8") const osuEntities = [ 'avcodec-51.dll', 'avformat-52.dll', @@ -147,4 +149,28 @@ async function startWithDevServer(osuPath, serverDomain, onExit) { return true; } -module.exports = { isValidOsuFolder, getLatestConfig, getUpdateFiles, filesThatNeedUpdate, downloadUpdateFiles, startOsuWithDevServer: startWithDevServer } \ No newline at end of file +function encryptString(value) { + return dpapi.protect(Buffer.from(value, 'utf-8'), osuEncryptBuffer, 'CurrentUser'); +} + +async function setConfigValue(configPath, key, value) { + const configLines = new Array(); + const fileStream = await fs.promises.readFile(configPath, "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 (key == keyname) { + configLines.push(`${keyname} = ${value}`); + } else { + configLines.push(line); + } + } else { + configLines.push(line); + } + } +} + +module.exports = { isValidOsuFolder, getLatestConfig, getUpdateFiles, filesThatNeedUpdate, downloadUpdateFiles, startOsuWithDevServer: startWithDevServer, setConfigValue } \ No newline at end of file diff --git a/package.json b/package.json index 422f59f..9fb08cb 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "dist": "electron-builder" }, "devDependencies": { - "electron": "^17.4.3", + "electron": "^21.1.1", "electron-builder": "^23.0.3", "electron-packager": "^15.5.1" },