public List <SoundList> ReadSoundTargetFiles() { List <SoundList> fileData = new List <SoundList>(); // Get a list of all the text files in the target folder. // This gets the full path of files. string[] files = Directory.GetFiles(parent.Folder_SoundTargetFolder); string[] temp; // Get just the file name. for (int i = 0; i < files.Length; i++) { // Split each path at folder breaks. temp = files[i].Split('\\'); // Last split contains just the file name. files[i] = temp[temp.Length - 1]; if (File.Exists(parent.Folder_SoundTargetFolder + files[i])) { SoundList tempList = ParseFile(files[i]); if (tempList != null) { fileData.Add(tempList); } } else { parent.AppendError("Could not find file: " + files[i] + ".\n", 3); } } return(fileData); }
// This is where the magic happens. Matches SoundKitIDs to FileDataIDS and returns a formatted lua string. private string GetFileDataID(string ListName, List <SoundFileEntry> SoundKitData, SoundList SoundKitIds) { List <SoundFileEntry> FilteredSoundData; string formattedString = ""; string soundKitErrors = ""; int errorCount = 0; bool hasError = false; // For each SoundKitID we are targetting for a mute. foreach (SoundTarget st in SoundKitIds.targets) { // Append the entry comment to the top of the current block. formattedString = formattedString + " -- " + st.EntryComment + "\n"; foreach (ulong i in st.SoundKitIDs) { // Create a filtered list that contains the FileDataIds with the matching SoundKitID FilteredSoundData = SoundKitData.FindAll(x => x.SoundKitID == i); if (FilteredSoundData.Count > 0) { // Lua file indentation. formattedString += " "; // Write each FileDataID in sequence. foreach (SoundFileEntry SFE in FilteredSoundData) { formattedString = formattedString + SFE.FileDataID + ","; } // Append the SoundKitID at the end as comment. formattedString = formattedString + " -- " + i + "\n"; } else { hasError = true; soundKitErrors += "'" + i + "', "; errorCount++; } } // For sounds not part of a soundkit // In this case the sound ID is the FileDataID, no matching required. if (st.SingleSounds.Count > 0) { foreach (int j in st.SingleSounds) { formattedString = formattedString + j + ","; } formattedString += "-- Non soundkit sounds\n"; } } if (hasError) { soundKitErrors = parent.ReplaceLastOccurrence(soundKitErrors, ", ", "."); parent.AppendError("File: " + ListName + ".txt\nNo matches found for: " + soundKitErrors + "\n\n", 1); parent.LogMessage(" ...done with (" + errorCount + ") error(s).\n", Color.Orange, parent.Bold_Font); } else { parent.LogMessage(" ...done!\n", Color.Green, parent.Bold_Font); } return(formattedString); }
public List <SoundFileEntry> ParseCSV() { parent.LogMessage("Loading SoundKitEntry data", Color.Black, parent.Bold_Font); try { CsvParserOptions csvOp = new CsvParserOptions(false, ','); SoundFileEntryMapping csvMapper = new SoundFileEntryMapping(); CsvParser <SoundFileEntry> csvParser = new CsvParser <SoundFileEntry>(csvOp, csvMapper); if (Directory.Exists(parent.Folder_SoundDataLocation) && File.Exists(parent.Folder_SoundDataLocation + "soundkitentry.csv")) { var result = csvParser.ReadFromFile(parent.Folder_SoundDataLocation + "soundkitentry.csv", Encoding.ASCII).Where(x => x.IsValid).Select(x => x.Result).ToList(); parent.LogMessage(" ...done!\n", Color.Green, parent.Bold_Font); return(result); } else { DataNotFound(); return(null); } } catch (Exception ex) { parent.AppendError(ex.Message, 2); return(null); } }