Skip to content

Commit

Permalink
properly check for file hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
hrfarmer committed Oct 24, 2024
1 parent 51ce354 commit 5c561fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
38 changes: 20 additions & 18 deletions src/main/lib/osu-file-parser/OsuParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,29 +176,31 @@ export class OsuParser {
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;
(file) => file.Filename.toLowerCase() === beatmap.Metadata.AudioFile.toLowerCase(),
)?.File.Hash;

if (songHash) {
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 */
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;
const bgHash = beatmapSet.Files.find(
(file) => file.Filename === beatmap.Metadata.BackgroundFile,
)?.File.Hash;

if (bgHash) {
song.bg =
currentDir + "/files/" + bgHash[0] + "/" + bgHash.substring(0, 2) + "/" + bgHash;
}
Expand Down
10 changes: 3 additions & 7 deletions src/main/router/dir-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,15 @@ Router.respond("dir::autoGetOsuDirs", () => {
}
} else if (process.platform === "linux") {
const dirs: OsuDirectory[] = [];
const homePath = process.env.XDG_DATA_HOME ?? `${process.env.HOME}/.local/share`;

if (
process.env.XDG_DATA_HOME != undefined &&
fs.existsSync(path.join(process.env.XDG_DATA_HOME, "osu-wine", "osu!"))
) {
if (homePath != undefined && fs.existsSync(path.join(homePath, "osu-wine", "osu!"))) {
dirs.push({
version: "stable",
path: path.join(process.env.XDG_DATA_HOME, "osu-wine", "osu!"),
path: path.join(homePath, "osu-wine", "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") });
}
Expand Down

0 comments on commit 5c561fc

Please sign in to comment.