private songnames ParseNamesFile(string filePath) { if (!File.Exists(filePath)) { Console.WriteLine($"Song names file missing! File: {filePath}"); return(null); } try { string songnamesJsonString = File.ReadAllText(filePath); songnames songnamesObject = JsonSerializer.Deserialize <songnames>(songnamesJsonString); return(songnamesObject); } catch (Exception e) { Console.WriteLine(e); Console.WriteLine($"Problem parsing song names file! File: {filePath}"); return(null); } }
public void ExtendSongsList() { int newNumSongs = ConsolePrompt.PromptInt("New Total Songs"); string originalConversionFile = $@"{currentDir}\music manager\idtowaveindex_original.json"; string outputConversionFile = $@"{currentDir}\music manager\idtowaveindex.json"; string originalNamesFile = $@"{currentDir}\music manager\songnames_original.json"; string outputNamesFile = $@"{currentDir}\music manager\songnames.json"; idtowaveindex originalConversions = ParseConversionFile(originalConversionFile); if (originalConversions == null) { return; } songnames originalNames = ParseNamesFile(originalNamesFile); if (originalNames == null) { return; } int normalNumSongs = originalConversions.conversions.Length; // new array of conversion objects with new total conversionObject[] newConversionList = new conversionObject[newNumSongs]; nameObject[] newNamesList = new nameObject[newNumSongs]; // copy original list to new list Array.Copy(originalConversions.conversions, newConversionList, originalConversions.conversions.Length); Array.Copy(originalNames.names, newNamesList, originalNames.names.Length); int startingIndex = 886; for (int i = normalNumSongs, total = newNumSongs, indexCounter = 0; i < total; i++, indexCounter++) { conversionObject newConversion = new conversionObject(); newConversion.trackID = i.ToString(); newConversion.uwusID = null; newConversion.waveIndex = (startingIndex + indexCounter).ToString(); newConversionList[i] = newConversion; nameObject newName = new nameObject(); newName.id = i.ToString(); newName.trackName = $"(BGME) Song Index {newConversion.waveIndex}"; newNamesList[i] = newName; } originalConversions.conversions = newConversionList; originalNames.names = newNamesList; string newConversionText = JsonSerializer.Serialize <idtowaveindex>(originalConversions, new JsonSerializerOptions { WriteIndented = true }); string newNamesText = JsonSerializer.Serialize <songnames>(originalNames, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(outputConversionFile, newConversionText); File.WriteAllText(outputNamesFile, newNamesText); }