small bugfixes #18

Merged
HorizonCode merged 3 commits from dev into master 2024-04-23 07:57:29 +00:00
2 changed files with 29 additions and 10 deletions

View File

@ -264,24 +264,33 @@ async function getEZPPLauncherUpdateFiles(osuPath) {
filesToDownload.push(updateFile); filesToDownload.push(updateFile);
} }
} }
return filesToDownload; return [filesToDownload, updateFiles];
} }
async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles) { async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles, allFiles) {
const eventEmitter = new EventEmitter(); const eventEmitter = new EventEmitter();
const startDownload = async () => { const startDownload = async () => {
//NOTE: delete files that are not in the updateFiles array //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) { for (const pruneFolder of foldersToPrune) {
//NOTE: check if the folder is not the osu root folder. //NOTE: check if the folder is not the osu root folder.
if (path.basename(pruneFolder) == "osu!") if (path.basename(pruneFolder) == "osu!")
continue; continue;
for (const files of await fs.promises.readdir(pruneFolder)) { if (fs.existsSync(pruneFolder)) {
const filePath = path.join(pruneFolder, files); for (const files of await fs.promises.readdir(pruneFolder)) {
if (!updateFiles.some(file => path.join(osuPath, ...file.folder.split("/"), file.name) === filePath)) { const filePath = path.join(pruneFolder, files);
const validFolder = allFiles.find(file => path.dirname(filePath).endsWith(file.folder));
await fs.promises.rm(filePath, { recursive: true, force: true }); if (!validFolder) {
if (allFiles.find(file => file.name == path.basename(filePath)) === undefined) {
eventEmitter.emit("data", {
fileName: path.basename(filePath),
});
try {
await fs.promises.rm(filePath, { recursive: true, force: true });
} catch { }
}
}
} }
} }
} }

14
main.js
View File

@ -557,12 +557,13 @@ function registerIPCPipes() {
status: "Looking for patcher updates...", status: "Looking for patcher updates...",
}); });
await new Promise((res) => setTimeout(res, 1000)); await new Promise((res) => setTimeout(res, 1000));
const patchFiles = await getEZPPLauncherUpdateFiles(osuPath); const [patchFiles, allUpdateFiles] = await getEZPPLauncherUpdateFiles(osuPath);
if (patchFiles.length > 0) { if (patchFiles.length > 0) {
logger.log("EZPPLauncher updates found."); logger.log("EZPPLauncher updates found.");
const patcherDownloader = await downloadEZPPLauncherUpdateFiles( const patcherDownloader = await downloadEZPPLauncherUpdateFiles(
osuPath, osuPath,
patchFiles, patchFiles,
allUpdateFiles
); );
let errored = false; let errored = false;
patcherDownloader.eventEmitter.on("error", (data) => { patcherDownloader.eventEmitter.on("error", (data) => {
@ -587,6 +588,15 @@ function registerIPCPipes() {
}/${formatBytes(data.total)})...`, }/${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(); await patcherDownloader.startDownload();
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: -1, progress: -1,
@ -664,7 +674,7 @@ function registerIPCPipes() {
if (fs.existsSync(updateFile)) { if (fs.existsSync(updateFile)) {
await fs.promises.rm(updateFile, { await fs.promises.rm(updateFile, {
force: true, force: true,
recursive: (await fs.promises.lstat(updateFile)).isDirectory, recursive: (await fs.promises.lstat(updateFile)).isDirectory(),
}); });
} }
} }