public void WriteLuaFile(string text, string name) { parent.LogMessage("\nWriting 'CustomSounds.lua'.\n", Color.Green, parent.Default_Font, false); StreamWriter sw = new StreamWriter(parent.Folder_Output + name); sw.WriteLine(text); sw.Close(); }
public void WriteErrorLog(string fileDir, string fileName) { if (printLog) { parent.LogMessage("\nWriting error log -> ErrorLog.txt.\n", parent.eColor, parent.Bold_Font); StreamWriter sw = new StreamWriter(fileDir + fileName, false); sw.WriteLine(printString); sw.Close(); ClearErrors(); } }
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); } }
// Parse a given file. private SoundList ParseFile(string fileName) { parent.LogMessage("File: ", Color.Black, parent.Default_Font); parent.LogMessage(fileName + " ", Color.Black, parent.Default_Font); bool hasError = false; string errorLogs = ""; int errorCount = 0; SoundList newList = new SoundList { // Names the list the same as the filename with file extension. ListName = fileName }; using (StreamReader file = new StreamReader(parent.Folder_SoundTargetFolder + fileName)) { int lineNumber = 1; string lineData; string[] lineDataSplit; SoundTarget soundTarget; while ((lineData = file.ReadLine()) != null) { // Ignore comment lines. if (!lineData.Trim().StartsWith("#")) { if (!String.IsNullOrEmpty(lineData.Trim())) { try { // First we split the comment and soundkit data. lineDataSplit = lineData.Split('-'); // This will throw if there isn't exactly one - if (!(lineDataSplit.Length == 2)) { throw new InvalidFormatException("Must be exactly one '-' character per line."); } soundTarget = new SoundTarget { // Set the line comment. EntryComment = lineDataSplit[0].Trim() }; // Second we split the soundkit data IDs and add them one at a time. lineDataSplit = lineDataSplit[1].Split(','); for (int i = 0; i < lineDataSplit.Length; i++) { // Int parsing error. try { if (lineDataSplit[i].StartsWith("s")) { // For sounds not part of SoundKitID. soundTarget.SingleSounds.Add(ulong.Parse(lineDataSplit[i].Replace("s", ""))); } else { soundTarget.SoundKitIDs.Add(ulong.Parse(lineDataSplit[i])); } } catch { hasError = true; errorLogs = errorLogs + "Line: '" + lineNumber + "' Input Given: '" + lineDataSplit[i] + "' Error: Invalid SoundID or SoundKitID. (Must be an integer)\n"; errorCount++; } } newList.targets.Add(soundTarget); } catch (Exception ex) { hasError = true; errorLogs = errorLogs + "Line: '" + lineNumber + "' Error: Incorrect format. (" + ex.Message + ")\n"; errorCount++; } } } lineNumber++; } } if (hasError) { parent.AppendError("File: " + fileName + "\n" + errorLogs + "\n", 0); parent.LogMessage(" ...done with (" + errorCount + ") error(s).\n", Color.Orange, parent.Bold_Font); } else { parent.LogMessage(" ...done!\n", Color.Green, parent.Bold_Font); } // If its empty, skip it. if (newList.targets.Count == 0) { // If it was empty but not from a result of an error. if (!hasError) { parent.LogMessage(" ...file is empty. Skipping.\n", Color.Orange, parent.Bold_Font); } return(null); } else { return(newList); } }