From 283e125e38b017765978b63f2a7b1fa0f189d983 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Sun, 16 Oct 2022 16:47:18 +0200 Subject: [PATCH] detect valid osu folder by matches --- osuUtil.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 osuUtil.js diff --git a/osuUtil.js b/osuUtil.js new file mode 100644 index 0000000..1c8fc6c --- /dev/null +++ b/osuUtil.js @@ -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 } \ No newline at end of file