From a6e2a5511719c9449f48405d460b13466482df62 Mon Sep 17 00:00:00 2001 From: MrKev312 <34964788+MrKev312@users.noreply.github.com> Date: Sat, 21 Dec 2024 18:07:49 +0100 Subject: [PATCH] Refactor song caching mechanism Replaced `JDCacheJSON` with `List` `existingSongs` for tracking cached songs. Removed `cacheJSON` variable and its deserialization. Populated `existingSongs` by deserializing JSON and extracting `ParentMapId` values from `MapsDict`. If `cachingStatus.json` is missing, populated `existingSongs` from directory names in `outputFolder`. Updated song caching check to use `existingSongs` with `StringComparer.OrdinalIgnoreCase`. --- JustDanceEditor.UI/Converting/ConverterDialogue.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/JustDanceEditor.UI/Converting/ConverterDialogue.cs b/JustDanceEditor.UI/Converting/ConverterDialogue.cs index 88e49da..d810750 100644 --- a/JustDanceEditor.UI/Converting/ConverterDialogue.cs +++ b/JustDanceEditor.UI/Converting/ConverterDialogue.cs @@ -68,19 +68,21 @@ public static void ConvertAllSongsInFolder() string outputFolder = AskOutputFolder(); ExportType exportType; - // First parse the cachingStatus.json - JDCacheJSON? cacheJSON = null; + List existingSongs = []; string cacheStatusPath = Path.Combine(outputFolder, "SD_Cache.0000", "MapBaseCache", "cachingStatus.json"); if (File.Exists(cacheStatusPath)) { string json = File.ReadAllText(cacheStatusPath); - cacheJSON = JsonSerializer.Deserialize(json); + existingSongs = JsonSerializer.Deserialize(json)!.MapsDict.Select(x => x.Value.SongDatabaseEntry.ParentMapId).ToList(); exportType = ExportType.OfflineCache; } else { exportType = ExportType.CustomServer; + // Get all names in the output folder + string[] outputSongs = Directory.GetDirectories(outputFolder); + existingSongs = outputSongs.Select(Path.GetFileName).ToList()!; } bool onlineCover = AskOnlineCover(); @@ -117,7 +119,7 @@ public static void ConvertAllSongsInFolder() } // If the song is already cached, skip it - if (cacheJSON != null && cacheJSON.MapsDict.Any(x => x.Value.SongDatabaseEntry.ParentMapId.Equals(song, StringComparison.OrdinalIgnoreCase))) + if (existingSongs.Contains(song, StringComparer.OrdinalIgnoreCase)) { Logger.Log($"Skipping {song} as it is already cached", LogLevel.Important); continue;