Compare commits
4 Commits
356ec5d7e0
...
830b1099ac
Author | SHA1 | Date | |
---|---|---|---|
830b1099ac | |||
14201fb9cd | |||
bd7f3ddefd | |||
99d0d927e0 |
26
app.js
26
app.js
@ -2,6 +2,10 @@ const { app, BrowserWindow, ipcMain, dialog } = require('electron');
|
||||
const { setupTitlebar, attachTitlebarToWindow } = require('custom-electron-titlebar/main');
|
||||
const windowManager = require('./ui/windowManager');
|
||||
const osuUtil = require('./osuUtil');
|
||||
const config = require('./config');
|
||||
const fs = require('fs');
|
||||
|
||||
let tempOsuPath;
|
||||
|
||||
const run = () => {
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
@ -9,12 +13,24 @@ const run = () => {
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
setupTitlebar();
|
||||
|
||||
let mainWindow;
|
||||
app.whenReady().then(() => {
|
||||
|
||||
mainWindow = createWindow()
|
||||
mainWindow = createWindow();
|
||||
mainWindow.on('show', async () => {
|
||||
const osuPath = await config.get("osuPath", "");
|
||||
if(fs.existsSync(osuPath)){
|
||||
tempOsuPath = osuPath;
|
||||
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
|
||||
console.log(osuConfig);
|
||||
const lastVersion = await osuConfig.get("LastVersion");
|
||||
console.log(lastVersion);
|
||||
//Do update check
|
||||
}
|
||||
})
|
||||
app.on('activate', function () {
|
||||
if (BrowserWindow.getAllWindows().length === 0) mainWindow = createWindow();
|
||||
})
|
||||
@ -28,14 +44,18 @@ const run = () => {
|
||||
if (yes.filePaths.length <= 0)
|
||||
return undefined;
|
||||
const folderPath = yes.filePaths[0];
|
||||
return osuUtil.isValidOsuFolder(folderPath);
|
||||
const validOsuDir = osuUtil.isValidOsuFolder(folderPath);
|
||||
|
||||
if (validOsuDir) await config.set("osuPath", folderPath);
|
||||
|
||||
return validOsuDir;
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
const win = windowManager.createWindow(480, 420);
|
||||
const win = windowManager.createWindow(480, 350);
|
||||
|
||||
win.loadFile('./html/index.html');
|
||||
|
||||
|
51
config.js
Normal file
51
config.js
Normal file
@ -0,0 +1,51 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const configFolder = path.join(process.env['LOCALAPPDATA'], 'EZPPLauncher');
|
||||
if (!fs.existsSync(configFolder)) fs.mkdirSync(configFolder);
|
||||
|
||||
const configLocation = path.join(configFolder, `ezpplauncher.${path.basename(process.env['HOME'])}.cfg`);
|
||||
if (!fs.existsSync(configLocation)) fs.writeFileSync(configLocation, "");
|
||||
|
||||
|
||||
|
||||
async function get(key, defaultValue) {
|
||||
const fileStream = await fs.promises.readFile(configLocation, "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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
async function set(key, value) {
|
||||
console.log("setting " + key + " to " + value);
|
||||
const configValues = new Map();
|
||||
const fileStream = await fs.promises.readFile(configLocation, "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];
|
||||
configValues.set(keyname, value);
|
||||
}
|
||||
}
|
||||
|
||||
configValues.set(key, value);
|
||||
|
||||
const arr = [];
|
||||
for (var [storkey, storvalue] of configValues.entries())
|
||||
arr.push(`${storkey}=${storvalue}`);
|
||||
|
||||
await fs.promises.writeFile(configLocation, arr.join('\n'));
|
||||
}
|
||||
|
||||
module.exports = { get, set }
|
@ -17,7 +17,7 @@
|
||||
|
||||
<body class="fixed-sn mdb-skin-custom" data-spy="scroll" data-target="#scrollspy" data-offset="15"
|
||||
oncontextmenu="return false;">
|
||||
<main style="margin-top: 2rem;">
|
||||
<main style="">
|
||||
<div class="noselect">
|
||||
<div class="position-relative overflow-hidden p-3 p-md-5 m-md-3 text-center text-lg-end d-flex align-items-center justify-content-center"
|
||||
style="border-radius: 0.5em;">
|
||||
@ -28,18 +28,19 @@
|
||||
<div class="card" style="border-radius: 1rem;">
|
||||
<div class="row g-0">
|
||||
<div class="card-body p-4 p-lg-5 text-black">
|
||||
<div class="d-flex align-items-center mb-3 pb-1 text-white">
|
||||
<div class="d-flex align-items-center mb-2 pb-1 text-white">
|
||||
<span class="h1 fw-bold mb-0">EZPPLauncher</span>
|
||||
</div>
|
||||
<h5 class="fw-normal mb-3 pb-3 text-white text-start"
|
||||
<h5 class="fw-lighter fs-5 mb-3 pb-3 text-white text-start"
|
||||
style="letter-spacing: 1px;">
|
||||
Launch osu! with connection to the EZPPFarm server
|
||||
</h5>
|
||||
<div class="pt-1 mb-4">
|
||||
<button id="launch-btn" class="btn btn-primary btn-lg btn-block"
|
||||
type="button" style="background-color:#d6016f" disabled>Launch</button>
|
||||
type="button" style="background-color:#d6016f"
|
||||
disabled>Launch</button>
|
||||
</div>
|
||||
<button class="btn btn-dark btn-sm float-start" id="folder-btn">
|
||||
<button class="btn btn-dark btn-sm float-end" id="folder-btn">
|
||||
set osu! directory
|
||||
</button>
|
||||
</div>
|
||||
|
42
osuUtil.js
42
osuUtil.js
@ -39,4 +39,44 @@ async function isValidOsuFolder(path) {
|
||||
return Math.round((matches / osuEntities.length) * 100) >= 60;
|
||||
}
|
||||
|
||||
module.exports = { isValidOsuFolder }
|
||||
async function getLatestConfig(osuPath) {
|
||||
const allFiles = await fs.promises.readdir(osuPath);
|
||||
const configFileInfo = {
|
||||
name: "",
|
||||
path: "",
|
||||
lastModified: 0,
|
||||
get: async (key) => {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const file of allFiles) {
|
||||
if (file.startsWith('osu!.') && file.endsWith('.cfg') && file !== "osu!.cfg") {
|
||||
const fullFilePath = path.join(osuPath, file);
|
||||
const fileStats = await fs.promises.stat(fullFilePath);
|
||||
const lastModified = fileStats.mtimeMs;
|
||||
if (lastModified > configFileInfo.lastModified) {
|
||||
configFileInfo.name = file;
|
||||
configFileInfo.path = fullFilePath;
|
||||
configFileInfo.lastModified = lastModified;
|
||||
}
|
||||
}
|
||||
}
|
||||
return configFileInfo;
|
||||
}
|
||||
|
||||
async function checkForUpdate(path) {
|
||||
|
||||
}
|
||||
|
||||
module.exports = { isValidOsuFolder, getLatestConfig }
|
@ -19,6 +19,10 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
const success = await ipcRenderer.invoke('set-osu-dir');
|
||||
if (success == undefined)
|
||||
return;
|
||||
alert(success);
|
||||
if (success) {
|
||||
|
||||
} else {
|
||||
//TODO: Alert User, invalid osu folder selected
|
||||
}
|
||||
});
|
||||
})
|
@ -33,9 +33,9 @@ module.exports = {
|
||||
|
||||
window.webContents.setUserAgent("EZPPLauncher");
|
||||
attachTitlebarToWindow(window);
|
||||
window.webContents.openDevTools({
|
||||
/* window.webContents.openDevTools({
|
||||
mode: "detach"
|
||||
});
|
||||
}); */
|
||||
|
||||
return window;
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user