From 9f9804f161fab8731d981a5d78924b8dff103c0f Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Tue, 23 Apr 2024 09:38:11 +0200 Subject: [PATCH 1/3] small bugfixes --- electron/osuUtil.js | 16 +++++++++++----- main.js | 11 ++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/electron/osuUtil.js b/electron/osuUtil.js index 67e7a6c..b49aca5 100644 --- a/electron/osuUtil.js +++ b/electron/osuUtil.js @@ -277,11 +277,17 @@ async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles) { //NOTE: check if the folder is not the osu root folder. if (path.basename(pruneFolder) == "osu!") continue; - for (const files of await fs.promises.readdir(pruneFolder)) { - const filePath = path.join(pruneFolder, files); - if (!updateFiles.some(file => path.join(osuPath, ...file.folder.split("/"), file.name) === filePath)) { - - await fs.promises.rm(filePath, { recursive: true, force: true }); + if (fs.existsSync(pruneFolder)) { + for (const files of await fs.promises.readdir(pruneFolder)) { + const filePath = path.join(pruneFolder, files); + if (!updateFiles.some(file => path.join(osuPath, ...file.folder.split("/"), file.name) === filePath)) { + eventEmitter.emit("data", { + fileName: path.basename(filePath), + }); + try { + await fs.promises.rm(filePath, { recursive: true, force: true }); + } catch { } + } } } } diff --git a/main.js b/main.js index 7fd6650..49f30b6 100644 --- a/main.js +++ b/main.js @@ -587,6 +587,15 @@ function registerIPCPipes() { }/${formatBytes(data.total)})...`, }); }); + patcherDownloader.eventEmitter.on("delete", (data) => { + logger.log(`Deleting ${data.fileName}!`); + mainWindow.webContents.send("ezpplauncher:launchprogress", { + progress: -1, + }); + mainWindow.webContents.send("ezpplauncher:launchstatus", { + status: `Deleting ${data.fileName}...`, + }); + }); await patcherDownloader.startDownload(); mainWindow.webContents.send("ezpplauncher:launchprogress", { progress: -1, @@ -664,7 +673,7 @@ function registerIPCPipes() { if (fs.existsSync(updateFile)) { await fs.promises.rm(updateFile, { force: true, - recursive: (await fs.promises.lstat(updateFile)).isDirectory, + recursive: (await fs.promises.lstat(updateFile)).isDirectory(), }); } } -- 2.34.1 From 6881a0d1d50cada5bf381e0ca3c6c6c1c309c8f5 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Tue, 23 Apr 2024 09:56:22 +0200 Subject: [PATCH 2/3] pruning fixes --- electron/osuUtil.js | 26 ++++++++++++++++---------- main.js | 3 ++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/electron/osuUtil.js b/electron/osuUtil.js index b49aca5..4f37e6e 100644 --- a/electron/osuUtil.js +++ b/electron/osuUtil.js @@ -264,29 +264,35 @@ async function getEZPPLauncherUpdateFiles(osuPath) { filesToDownload.push(updateFile); } } - return filesToDownload; + return [filesToDownload, updateFiles]; } -async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles) { +async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles, allFiles) { const eventEmitter = new EventEmitter(); const startDownload = async () => { //NOTE: delete files that are not in the updateFiles array - const foldersToPrune = updateFiles.map(file => path.dirname(path.join(osuPath, ...file.folder.split("/"), file.name))).filter((folder, index, self) => self.indexOf(folder) === index); + const foldersToPrune = allFiles.map(file => path.dirname(path.join(osuPath, ...file.folder.split("/"), file.name))).filter((folder, index, self) => self.indexOf(folder) === index); for (const pruneFolder of foldersToPrune) { + console.log("Pruning folder:", pruneFolder); //NOTE: check if the folder is not the osu root folder. if (path.basename(pruneFolder) == "osu!") continue; if (fs.existsSync(pruneFolder)) { for (const files of await fs.promises.readdir(pruneFolder)) { const filePath = path.join(pruneFolder, files); - if (!updateFiles.some(file => path.join(osuPath, ...file.folder.split("/"), file.name) === filePath)) { - eventEmitter.emit("data", { - fileName: path.basename(filePath), - }); - try { - await fs.promises.rm(filePath, { recursive: true, force: true }); - } catch { } + const validFolder = allFiles.find(file => path.dirname(filePath).endsWith(file.folder)); + if (!validFolder) { + if (allFiles.find(file => file.name == path.basename(filePath)) === undefined) { + console.log("Deleting file:", filePath); + console.log(allFiles.find(file => file.name == path.basename(filePath))); + eventEmitter.emit("data", { + fileName: path.basename(filePath), + }); + try { + await fs.promises.rm(filePath, { recursive: true, force: true }); + } catch { } + } } } } diff --git a/main.js b/main.js index 49f30b6..4cd0cce 100644 --- a/main.js +++ b/main.js @@ -557,12 +557,13 @@ function registerIPCPipes() { status: "Looking for patcher updates...", }); await new Promise((res) => setTimeout(res, 1000)); - const patchFiles = await getEZPPLauncherUpdateFiles(osuPath); + const [patchFiles, allUpdateFiles] = await getEZPPLauncherUpdateFiles(osuPath); if (patchFiles.length > 0) { logger.log("EZPPLauncher updates found."); const patcherDownloader = await downloadEZPPLauncherUpdateFiles( osuPath, patchFiles, + allUpdateFiles ); let errored = false; patcherDownloader.eventEmitter.on("error", (data) => { -- 2.34.1 From cd8f42327c2e861a73bf4b3226d2503e3a885ec3 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Tue, 23 Apr 2024 09:56:45 +0200 Subject: [PATCH 3/3] remove logging --- electron/osuUtil.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/electron/osuUtil.js b/electron/osuUtil.js index 4f37e6e..e116608 100644 --- a/electron/osuUtil.js +++ b/electron/osuUtil.js @@ -274,7 +274,6 @@ async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles, allFiles) { //NOTE: delete files that are not in the updateFiles array const foldersToPrune = allFiles.map(file => path.dirname(path.join(osuPath, ...file.folder.split("/"), file.name))).filter((folder, index, self) => self.indexOf(folder) === index); for (const pruneFolder of foldersToPrune) { - console.log("Pruning folder:", pruneFolder); //NOTE: check if the folder is not the osu root folder. if (path.basename(pruneFolder) == "osu!") continue; @@ -284,8 +283,6 @@ async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles, allFiles) { const validFolder = allFiles.find(file => path.dirname(filePath).endsWith(file.folder)); if (!validFolder) { if (allFiles.find(file => file.name == path.basename(filePath)) === undefined) { - console.log("Deleting file:", filePath); - console.log(allFiles.find(file => file.name == path.basename(filePath))); eventEmitter.emit("data", { fileName: path.basename(filePath), }); -- 2.34.1