Compare commits

...

3 Commits

Author SHA1 Message Date
356ec5d7e0 cancel if result is undefined 2022-10-16 16:47:43 +02:00
071b13ee6e change pipe name 2022-10-16 16:47:31 +02:00
283e125e38 detect valid osu folder by matches 2022-10-16 16:47:18 +02:00
3 changed files with 52 additions and 4 deletions

8
app.js
View File

@ -1,6 +1,7 @@
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 run = () => {
const gotTheLock = app.requestSingleInstanceLock()
@ -20,11 +21,14 @@ const run = () => {
app.on('window-all-closed', () => {
app.quit()
})
ipcMain.handle('open-folder-dialog', async (event) => {
ipcMain.handle('set-osu-dir', async (event) => {
const yes = await dialog.showOpenDialog({
properties: ['openDirectory']
})
return yes.filePaths;
if (yes.filePaths.length <= 0)
return undefined;
const folderPath = yes.filePaths[0];
return osuUtil.isValidOsuFolder(folderPath);
})
})
}

42
osuUtil.js Normal file
View File

@ -0,0 +1,42 @@
const fs = require('fs');
const path = require('path');
const osuEntities = [
'avcodec-51.dll',
'avformat-52.dll',
'avutil-49.dll',
'bass.dll',
'bass_fx.dll',
'collection.db',
'd3dcompiler_47.dll',
'Data',
'Downloads',
'libEGL.dll',
'libGLESv2.dll',
'Logs',
'Microsoft.Ink.dll',
'OpenTK.dll',
'osu!.cfg',
'osu!.db',
'osu!.exe',
'osu!auth.dll',
'osu!gameplay.dll',
'osu!seasonal.dll',
'osu!ui.dll',
'presence.db',
'pthreadGC2.dll',
'scores.db',
'Skins',
'Songs'
]
async function isValidOsuFolder(path) {
const allFiles = await fs.promises.readdir(path);
let matches = 0;
for (const file of allFiles) {
if (osuEntities.includes(file)) matches = matches + 1;
}
return Math.round((matches / osuEntities.length) * 100) >= 60;
}
module.exports = { isValidOsuFolder }

View File

@ -16,7 +16,9 @@ window.addEventListener('DOMContentLoaded', () => {
const $ = require('jquery');
$("#folder-btn").on('click', async () => {
const folderLoc = await ipcRenderer.invoke('open-folder-dialog');
alert(folderLoc);
const success = await ipcRenderer.invoke('set-osu-dir');
if (success == undefined)
return;
alert(success);
});
})