From 99d0d927e090cbdf2d0218aac81bf903a1fbe555 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Sun, 16 Oct 2022 18:41:15 +0200 Subject: [PATCH] get osu config method --- osuUtil.js | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/osuUtil.js b/osuUtil.js index 1c8fc6c..0fa956f 100644 --- a/osuUtil.js +++ b/osuUtil.js @@ -39,4 +39,44 @@ async function isValidOsuFolder(path) { return Math.round((matches / osuEntities.length) * 100) >= 60; } -module.exports = { isValidOsuFolder } \ No newline at end of file +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 } \ No newline at end of file