using System; using System.Linq; using System.Text; using System.IO; using System.Collections.Generic; namespace BizHawk.Emulation.DiscSystem { /// /// Returns ERRORS for things which will can't be processed any further. Processing of this job will continue though to try to collect the maximum amount of feedback. /// Returns WARNINGS for things which will are irregular or erroneous but later jobs might be able to handle, or which can be worked around by configuration assumptions. /// TODO - make IDisposable so I don't have to remember to Finish() it? /// public class DiscJob { internal int CurrentLine = -1; internal StringWriter swLog = new StringWriter(); internal void Warn(string format, params object[] args) { Log("WARN ", format, args); } internal void Error(string format, params object[] args) { OUT_ErrorLevel = true; Log("ERROR", format, args); } internal void Log(string level, string format, params object[] args) { var msg = string.Format(format, args); if (CurrentLine == -1) swLog.WriteLine("{0}: {1}", level, msg); else swLog.WriteLine("[{0,3}] {1}: {2}", CurrentLine, level, msg); } /// /// Whether there were any errors /// public bool OUT_ErrorLevel = false; /// /// output: log transcript of the job /// public string OUT_Log; /// /// Finishes logging. Flushes the output and closes the logging mechanism /// internal void FinishLog() { OUT_Log = swLog.ToString(); swLog.Close(); } /// /// Concatenates the log results from the provided job into this log /// public void ConcatenateJobLog(DiscJob job) { OUT_ErrorLevel |= job.OUT_ErrorLevel; swLog.Write(job.OUT_Log); } } }