public bool LoadIfNotLoaded(CustomLevelStaticData song) { string newId = CustomSongInfo.FromPath(song.jsonPath).GetIdentifier(); bool idMatched = newId == song.levelId; if (!idMatched) { Logger.Log("Song has been modified, old ID was " + song.levelId + " updating song content and ID"); song.wasLoaded = false; _database.UpdateSongID(song.levelId, newId); ReflectionUtil.SetPrivateField(song, "_levelId", newId); } if (!song.wasLoaded) { foreach (CustomLevelStaticData.CustomDifficultyLevel difficultyLevel in song.difficultyLevels) { StartCoroutine(LoadAudio("file://" + difficultyLevel.audioPath, difficultyLevel, "_audioClip")); ReflectionUtil.SetPrivateField(difficultyLevel, "_songLevelData", ParseDifficulty(difficultyLevel.jsonPath)); } song.wasLoaded = true; } return(idMatched); }
private void AddSong(string folder, xxHash.Hash64 hasher, List <ulong> scannedHashes, bool forceAdd) { // Hash info.json file to use as a key in the db hasher.Write(File.ReadAllText(folder + "/info.json")); ulong currentHash = hasher.Compute(); hasher.Reset(0); // Ignore duplicates if (scannedHashes.Contains(currentHash)) { Logger.Log("The song in directory " + folder + " has a duplicate hash " + currentHash + " and was ignored"); return; } scannedHashes.Add(currentHash); directoryParam.Value = folder; hashParam.Value = currentHash; if (forceAdd || (Int64)checkCommand.ExecuteScalar() == 0) { Logger.Log("Song is not in DB or has changed, adding or updating"); // We need to update the database entry for the current song CustomSongInfo songInfo = CustomSongInfo.FromPath(folder); beatsaveridParam.Value = 0; //TODO leaderboardidParam.Value = songInfo.GetIdentifier(); bpmParam.Value = songInfo.beatsPerMinute; previewStartTimeParam.Value = songInfo.previewStartTime; previewDurationParam.Value = songInfo.previewDuration; authorNameParam.Value = songInfo.authorName ?? ""; songNameParam.Value = songInfo.songName ?? ""; songSubnameParam.Value = songInfo.songSubName ?? ""; coverImagePathParam.Value = songInfo.coverImagePath ?? ""; environmentNameParam.Value = songInfo.environmentName ?? ""; updateCommand.ExecuteNonQuery(); // And add all the difficulties into the database foreach (CustomSongInfo.DifficultyLevel diff in songInfo.difficultyLevels) { difficultyNameParam.Value = diff.difficulty; difficultyRankParam.Value = diff.difficultyRank; audioPathParam.Value = diff.audioPath; fileNameParam.Value = diff.jsonPath; updateDiffCommand.ExecuteNonQuery(); } } }