Skip to content

Commit

Permalink
Refactor song caching mechanism
Browse files Browse the repository at this point in the history
Replaced `JDCacheJSON` with `List<string>` `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`.
  • Loading branch information
MrKev312 committed Dec 21, 2024
1 parent e68f893 commit a6e2a55
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions JustDanceEditor.UI/Converting/ConverterDialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,21 @@ public static void ConvertAllSongsInFolder()
string outputFolder = AskOutputFolder();
ExportType exportType;

// First parse the cachingStatus.json
JDCacheJSON? cacheJSON = null;
List<string> existingSongs = [];

string cacheStatusPath = Path.Combine(outputFolder, "SD_Cache.0000", "MapBaseCache", "cachingStatus.json");
if (File.Exists(cacheStatusPath))
{
string json = File.ReadAllText(cacheStatusPath);
cacheJSON = JsonSerializer.Deserialize<JDCacheJSON>(json);
existingSongs = JsonSerializer.Deserialize<JDCacheJSON>(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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a6e2a55

Please sign in to comment.