From 51ce354a3b5d5c062686fa9ae28fe6fc0ae8fa1b Mon Sep 17 00:00:00 2001 From: aychar <58487401+hrfarmer@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:54:18 -0500 Subject: [PATCH] downgrade realm, set realm to readonly, and add try catch for import --- package-lock.json | 10 +- package.json | 2 +- src/main/lib/osu-file-parser/OsuParser.ts | 134 ++++++++++++---------- src/main/router/dir-router.ts | 6 +- 4 files changed, 86 insertions(+), 66 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2ec20128..65f545e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "graceful-fs": "^4.2.11", "lucide-solid": "^0.452.0", "node-addon-api": "^8.2.1", - "realm": "^12.13.1", + "realm": "12.6.2", "remixicon": "^4.3.0", "sharp": "^0.33.5", "solid-focus-trap": "^0.1.7", @@ -8706,9 +8706,9 @@ } }, "node_modules/realm": { - "version": "12.13.1", - "resolved": "https://registry.npmjs.org/realm/-/realm-12.13.1.tgz", - "integrity": "sha512-fAs70ZCBf1P7htVhOTrDMFHD6SzoGXVsALy6DpOPR6t0LXoK635cKxBMECX3bYdCgI7+riSfdoWXLA/7g5yTSQ==", + "version": "12.6.2", + "resolved": "https://registry.npmjs.org/realm/-/realm-12.6.2.tgz", + "integrity": "sha512-6ICUaKHNeiEAwVIKC3AkCDTCVEtpkFAVeWvmUVdmVIUjcY/+2cMLe/tgFpLcY7pEB/n1EUg3pVyUBcVuMvwdqg==", "deprecated": "This version uses Atlas Device Sync, please install `realm@community` and read https://github.com/realm/realm-js/blob/main/DEPRECATION.md for more information.", "hasInstallScript": true, "license": "apache-2.0", @@ -8718,7 +8718,7 @@ "debug": "^4.3.4", "node-machine-id": "^1.1.12", "path-browserify": "^1.0.1", - "prebuild-install": "^7.1.2" + "prebuild-install": "^7.1.1" }, "engines": { "node": ">=18" diff --git a/package.json b/package.json index 0e5add17..5de111ac 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "graceful-fs": "^4.2.11", "lucide-solid": "^0.452.0", "node-addon-api": "^8.2.1", - "realm": "^12.13.1", + "realm": "~12.6.2", "remixicon": "^4.3.0", "sharp": "^0.33.5", "solid-focus-trap": "^0.1.7", diff --git a/src/main/lib/osu-file-parser/OsuParser.ts b/src/main/lib/osu-file-parser/OsuParser.ts index a1e9f4bc..97ece49f 100644 --- a/src/main/lib/osu-file-parser/OsuParser.ts +++ b/src/main/lib/osu-file-parser/OsuParser.ts @@ -134,7 +134,11 @@ export class OsuParser { ): DirParseResult { const currentDir = databasePath.replaceAll("\\", "/"); - const realm = await Realm.open({ path: currentDir + "/client.realm" }); + const realm = await Realm.open({ + path: currentDir + "/client.realm", + readOnly: true, + schemaVersion: 23, + }); const beatmapSets = realm.objects("BeatmapSet"); const songTable = new Map(); @@ -143,67 +147,81 @@ export class OsuParser { let i = 0; for (const beatmapSet of beatmapSets) { - const beatmaps = removeUnoriginalBeatmaps(beatmapSet.Beatmaps); - - for (const beatmap of beatmaps) { - const song: Song = { - audio: "", - osuFile: "", - path: "", - ctime: "", - dateAdded: beatmapSet.DateAdded, - title: beatmap.Metadata.Title, - artist: beatmap.Metadata.Artist, - creator: beatmap.Metadata.Author.Username, - bpm: [], - duration: beatmap.Length, - diffs: [beatmap.DifficultyName], - }; - - song.osuFile = - currentDir + - "/files/" + - beatmap.Hash[0] + - "/" + - beatmap.Hash.substring(0, 2) + - "/" + - beatmap.Hash; - - const songHash = beatmapSet.Files.find( - (file) => file.Filename === beatmap.Metadata.AudioFile, - )?.File.Hash as string; // the mp3 should exist, will check if its possible for it to not in lazer - - song.audio = - currentDir + "/files/" + songHash[0] + "/" + songHash.substring(0, 2) + "/" + songHash; - - /* Note: in lots of places throughout the application, it relies on the song.path parameter, which in the + try { + const beatmaps = removeUnoriginalBeatmaps(beatmapSet.Beatmaps); + + for (const beatmap of beatmaps) { + try { + const song: Song = { + audio: "", + osuFile: "", + path: "", + ctime: "", + dateAdded: beatmapSet.DateAdded, + title: beatmap.Metadata.Title, + artist: beatmap.Metadata.Artist, + creator: beatmap.Metadata.Author.Username, + bpm: [], + duration: beatmap.Length, + diffs: [beatmap.DifficultyName], + }; + + song.osuFile = + currentDir + + "/files/" + + beatmap.Hash[0] + + "/" + + beatmap.Hash.substring(0, 2) + + "/" + + beatmap.Hash; + + const songHash = beatmapSet.Files.find( + (file) => file.Filename === beatmap.Metadata.AudioFile, + )?.File.Hash as string; // the mp3 should exist, will check if its possible for it to not in lazer + + song.audio = + currentDir + + "/files/" + + songHash[0] + + "/" + + songHash.substring(0, 2) + + "/" + + songHash; + + /* Note: in lots of places throughout the application, it relies on the song.path parameter, which in the stable parser is the path of the folder that holds all the files. This folder doesn't exist in lazer's file structure, so for now I'm just passing the audio location as the path parameter. In initial testing this doesn't seem to break anything but just leaving this note in case it does */ - song.path = song.audio; - - if (beatmap.Metadata.BackgroundFile) { - const bgHash = beatmapSet.Files.find( - (file) => file.Filename === beatmap.Metadata.BackgroundFile, - )?.File.Hash as string; - - song.bg = - currentDir + "/files/" + bgHash[0] + "/" + bgHash.substring(0, 2) + "/" + bgHash; - } - - song.beatmapSetID = beatmapSet.OnlineID; - - songTable.set(song.audio, song); - audioTable.set(song.audio, { - songID: song.audio, - path: song.audio, - ctime: String(beatmapSet.DateAdded), - }); - - if (update) { - update(i + 1, beatmapSets.length, song.title); - i++; + song.path = song.audio; + + if (beatmap.Metadata.BackgroundFile) { + const bgHash = beatmapSet.Files.find( + (file) => file.Filename === beatmap.Metadata.BackgroundFile, + )?.File.Hash as string; + + song.bg = + currentDir + "/files/" + bgHash[0] + "/" + bgHash.substring(0, 2) + "/" + bgHash; + } + + song.beatmapSetID = beatmapSet.OnlineID; + + songTable.set(song.audio, song); + audioTable.set(song.audio, { + songID: song.audio, + path: song.audio, + ctime: String(beatmapSet.DateAdded), + }); + + if (update) { + update(i + 1, beatmapSets.length, song.title); + i++; + } + } catch (err) { + console.error("Error while parsing beatmap: ", err); + } } + } catch (err) { + console.error("Error while parsing beatmapset: ", err); } } diff --git a/src/main/router/dir-router.ts b/src/main/router/dir-router.ts index 339810bd..3fbdf7bf 100644 --- a/src/main/router/dir-router.ts +++ b/src/main/router/dir-router.ts @@ -62,8 +62,10 @@ Router.respond("dir::autoGetOsuDirs", () => { }); } - if (process.env.HOME != undefined && fs.existsSync(path.join(process.env.HOME, "osu"))) { - dirs.push({ version: "lazer", path: path.join(process.env.HOME, "osu") }); + const homePath = process.env.XDG_DATA_HOME ?? `${process.env.HOME}/.local/share`; + + if (homePath != undefined && fs.existsSync(path.join(homePath, "osu"))) { + dirs.push({ version: "lazer", path: path.join(homePath, "osu") }); } if (dirs.length > 0) {