From 843b52b197140ede02b810becb52a93ed35f477f Mon Sep 17 00:00:00 2001 From: nyarw Date: Mon, 9 Nov 2026 19:30:22 +0100 Subject: [PATCH 1/3] fix: create maps folder and remove deleted maps from db on load --- scripts/Rhythia.cs | 1 + scripts/map/MapCache.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/Rhythia.cs b/scripts/Rhythia.cs index 15e26357..185e8ea6 100644 --- a/scripts/Rhythia.cs +++ b/scripts/Rhythia.cs @@ -56,6 +56,7 @@ public override async void _Ready() Stats.Instance.GamesOpened++; // Map import + Directory.CreateDirectory($"{Constants.USER_FOLDER}/maps"); var nonConvertedMaps = Directory .EnumerateFiles($"{Constants.USER_FOLDER}/maps", $"*.*", SearchOption.AllDirectories) .Where(f => diff --git a/scripts/map/MapCache.cs b/scripts/map/MapCache.cs index 65375195..f00f6d58 100644 --- a/scripts/map/MapCache.cs +++ b/scripts/map/MapCache.cs @@ -28,6 +28,8 @@ public static void Load(bool fullSync) try { + Directory.CreateDirectory(MapUtil.MapsFolder); + // Map files (.phxm, .sspm, etc) go first since they will be encoded to folders after they get parsed in MapParser.cs -fog List mapsList = [ @@ -55,8 +57,9 @@ .. Directory.GetDirectories(MapUtil.MapsFolder, "*", SearchOption.AllDirectories OrderAndSetMaps(); } - catch + catch (Exception exception) { + Logger.Error(exception); OrderAndSetMaps(); } } @@ -320,6 +323,12 @@ public static void OrderAndSetMaps() { var maps = FetchAll(); + foreach (var missing in maps.Where(x => !Directory.Exists(x.FolderPath) && !File.Exists(x.FolderPath)).ToList()) + { + RemoveMap(missing); + maps.Remove(missing); + } + // only covers on screen are loaded to prevent excessive VRAM usage if (maps.Count < 1) From 9e3e5cee43de45dfe83348709fb136634b1e5703 Mon Sep 17 00:00:00 2001 From: nyarw Date: Mon, 9 Nov 2026 21:17:08 +0100 Subject: [PATCH 2/3] fix: use FolderPath for map paths and handle nested map folders --- scripts/SoundManager.cs | 4 ++-- scripts/map/Map.cs | 4 ++-- scripts/map/MapCache.cs | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/SoundManager.cs b/scripts/SoundManager.cs index 969bc506..ce39a631 100644 --- a/scripts/SoundManager.cs +++ b/scripts/SoundManager.cs @@ -261,7 +261,7 @@ public static void PlayJukebox(Map map, bool setRichPresence = true) JukeboxIndex = MapManager.Maps.FindIndex(x => x.Id == map.Id); - Song.Stream = util.Audio.LoadFromFile($"{MapUtil.MapsFolder}/{map.Name}/audio.{map.AudioExt}"); + Song.Stream = util.Audio.LoadFromFile($"{map.FolderPath}/audio.{map.AudioExt}"); Song.Play(); Instance.JukeboxPlayed?.Invoke(map); @@ -320,7 +320,7 @@ public static void StartMapSelectionPlayback(Map map, bool setRichPresence = tru } } - Song.Stream = util.Audio.LoadFromFile($"{MapUtil.MapsFolder}/{map.Name}/audio.{map.AudioExt}"); + Song.Stream = util.Audio.LoadFromFile($"{map.FolderPath}/audio.{map.AudioExt}"); Song.Play(0); Instance.JukeboxPlayed?.Invoke(map); diff --git a/scripts/map/Map.cs b/scripts/map/Map.cs index 370c1eeb..1a7be5b7 100644 --- a/scripts/map/Map.cs +++ b/scripts/map/Map.cs @@ -103,7 +103,7 @@ public Note[] TryParseNotes() { try { - notes = MapParser.DecodePHXMO($"{MapUtil.MapsFolder}/{Name}/objects.phxmo"); + notes = MapParser.DecodePHXMO($"{FolderPath}/objects.phxmo"); return notes; } catch @@ -125,7 +125,7 @@ public void UnloadCover() private Texture2D getCover() { - string path = $"{MapUtil.MapsFolder}/{Name}"; + string path = FolderPath; if (cover == DefaultCover && File.Exists($"{path}/cover.png")) { diff --git a/scripts/map/MapCache.cs b/scripts/map/MapCache.cs index f00f6d58..c45eadd5 100644 --- a/scripts/map/MapCache.cs +++ b/scripts/map/MapCache.cs @@ -30,11 +30,13 @@ public static void Load(bool fullSync) { Directory.CreateDirectory(MapUtil.MapsFolder); + EnumerationOptions options = new() { RecurseSubdirectories = true, MaxRecursionDepth = 1 }; + // Map files (.phxm, .sspm, etc) go first since they will be encoded to folders after they get parsed in MapParser.cs -fog List mapsList = [ - .. Directory.GetFiles(MapUtil.MapsFolder, $"*.{Constants.DEFAULT_MAP_EXT}", SearchOption.AllDirectories), - .. Directory.GetDirectories(MapUtil.MapsFolder, "*", SearchOption.AllDirectories), + .. Directory.GetFiles(MapUtil.MapsFolder, $"*.{Constants.DEFAULT_MAP_EXT}", options), + .. Directory.GetDirectories(MapUtil.MapsFolder, "*", options).Where(isMapFolder), ]; string[] toParseMaps = [.. mapsList]; @@ -64,6 +66,9 @@ .. Directory.GetDirectories(MapUtil.MapsFolder, "*", SearchOption.AllDirectories } } + private static bool isMapFolder(string path) => + File.Exists(Path.Combine(path, "metadata.json")) && File.Exists(Path.Combine(path, "objects.phxmo")); + private static void syncFiles(string[] toParseMaps) { var maps = FetchAll(); From d275faa0e0f03e2c3ddd2ab41950dd8892c74642 Mon Sep 17 00:00:00 2001 From: nyarw Date: Mon, 9 Nov 2026 21:17:39 +0100 Subject: [PATCH 3/3] fix: normalize map folder paths and remove duplicate map rows --- scripts/map/Map.cs | 6 +++++- scripts/map/MapCache.cs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/map/Map.cs b/scripts/map/Map.cs index 1a7be5b7..bcaf92e3 100644 --- a/scripts/map/Map.cs +++ b/scripts/map/Map.cs @@ -34,7 +34,11 @@ public partial class Map : RefCounted [Ignore] public MapSet MapSet { get; set; } - public string FolderPath { get; set; } = string.Empty; + public string FolderPath + { + get; + set => field = value?.Replace('\\', '/'); + } = string.Empty; public bool Favorite { get; set; } diff --git a/scripts/map/MapCache.cs b/scripts/map/MapCache.cs index c45eadd5..24c49b3a 100644 --- a/scripts/map/MapCache.cs +++ b/scripts/map/MapCache.cs @@ -43,6 +43,7 @@ .. Directory.GetDirectories(MapUtil.MapsFolder, "*", options).Where(isMapFolder) if (fullSync) { + removeDuplicateMaps(); syncFiles(toParseMaps); addNonCachedFiles(toParseMaps); @@ -69,6 +70,23 @@ .. Directory.GetDirectories(MapUtil.MapsFolder, "*", options).Where(isMapFolder) private static bool isMapFolder(string path) => File.Exists(Path.Combine(path, "metadata.json")) && File.Exists(Path.Combine(path, "objects.phxmo")); + private static void removeDuplicateMaps() + { + foreach (var duplicates in FetchAll().GroupBy(x => x.FolderPath).Where(x => x.Count() > 1)) + { + var kept = duplicates.OrderBy(x => x.Id).First(); + + foreach (var duplicate in duplicates.Where(x => x != kept)) + { + kept.Favorite |= duplicate.Favorite; + kept.PlayCount += duplicate.PlayCount; + RemoveMap(duplicate); + } + + UpdateMap(kept); + } + } + private static void syncFiles(string[] toParseMaps) { var maps = FetchAll();