/[RomCheater]/trunk/RomCheater.Logging/LogWriter.cs
ViewVC logotype

Diff of /trunk/RomCheater.Logging/LogWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 17 by william, Wed May 9 08:02:18 2012 UTC revision 19 by william, Wed May 9 08:22:41 2012 UTC
# Line 13  namespace RomCheater.Logging Line 13  namespace RomCheater.Logging
13  {  {
14      public partial class LogWriter : UserControl      public partial class LogWriter : UserControl
15      {      {
16            private const string LOG_FILE = "RomCheater.log";
17            private static string LOG_PATH = string.Format(@"{0}\{1}", Application.StartupPath, LOG_FILE);
18    
19          private delegate string OnGetLogText();          private delegate string OnGetLogText();
20          private delegate void OnSetLogText(string value);          private delegate void OnSetLogText(string value);
21          private delegate void GenericVoidDelegate();          private delegate void GenericVoidDelegate();
# Line 34  namespace RomCheater.Logging Line 37  namespace RomCheater.Logging
37              this.RedirectConsoleOutput = redirectConsole;              this.RedirectConsoleOutput = redirectConsole;
38              toolTip1.SetToolTip(btnClearLog, "Clears the Log");              toolTip1.SetToolTip(btnClearLog, "Clears the Log");
39              toolTip1.SetToolTip(btnCopyLogToClipboard, "Copies the Log to the Clipboard");              toolTip1.SetToolTip(btnCopyLogToClipboard, "Copies the Log to the Clipboard");
40    
41              ms = new MemoryStream();              ms = new MemoryStream();
42              sw = new StreamWriter(ms);              sw = new StreamWriter(ms);
43              sw.AutoFlush = true;              sw.AutoFlush = true;
44              sr = new StreamReader(ms);              sr = new StreamReader(ms);
45    
46                FileInfo fi = new FileInfo(LOG_PATH);
47                if (fi.Exists)
48                    fi.Delete();
49    
50          }          }
51          private LogStream _Log;          private LogStream _Log;
52          public LogStream Log { get { return _Log; } private set { _Log = value;  } }          public LogStream Log { get { return _Log; } private set { _Log = value; } }
53    
54    
55          private MemoryStream ms;          private MemoryStream ms;
# Line 55  namespace RomCheater.Logging Line 64  namespace RomCheater.Logging
64              set              set
65              {              {
66                  _RedirectConsoleOutput = value;                  _RedirectConsoleOutput = value;
67                  if (value) { Console.SetOut(this.Log); }                  if (value) { Console.SetOut(this.Log); }
68                  else                  else
69                  {                  {
70                      Stream stream = Console.OpenStandardOutput(0x100);                      Stream stream = Console.OpenStandardOutput(0x100);
71                      TextWriter writer = null;                      TextWriter writer = null;
# Line 66  namespace RomCheater.Logging Line 75  namespace RomCheater.Logging
75                      //writer2.HaveWrittenPreamble = true;                      //writer2.HaveWrittenPreamble = true;
76                      writer2.AutoFlush = true;                      writer2.AutoFlush = true;
77                      writer = TextWriter.Synchronized(writer2);                      writer = TextWriter.Synchronized(writer2);
78                      Console.SetOut(writer);                      Console.SetOut(writer);
79                  }                  }
80              }              }
81          }          }
# Line 132  namespace RomCheater.Logging Line 141  namespace RomCheater.Logging
141              //{              //{
142              //    txtLog.AppendText(value);              //    txtLog.AppendText(value);
143              //}              //}
144                FileStream fs = new FileStream(LOG_PATH, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
145                StreamWriter writer = new StreamWriter(fs);
146                writer.AutoFlush = true;
147                if (value == Log.NewLine) { writer.Write(System.Environment.NewLine); }
148                else { writer.Write(value); }
149                writer.Close();
150              sw.Write(value);              sw.Write(value);
151          }          }
152          new public string Text          new public string Text
# Line 146  namespace RomCheater.Logging Line 161  namespace RomCheater.Logging
161              }              }
162          }          }
163    
164          public void Clear()          public void Clear()
165          {          {
166              Clear(false);              Clear(false);
167          }          }
# Line 158  namespace RomCheater.Logging Line 173  namespace RomCheater.Logging
173  #endif  #endif
174              if (force || allow_log_clearing)              if (force || allow_log_clearing)
175              {              {
176                
177                  txtLog.Clear();                  txtLog.Clear();
178                  ms = new MemoryStream();                  ms = new MemoryStream();
179                  sw = new StreamWriter(ms);                  sw = new StreamWriter(ms);
# Line 168  namespace RomCheater.Logging Line 183  namespace RomCheater.Logging
183          }          }
184          #region sub-classes          #region sub-classes
185          public class LogStream : TextWriter          public class LogStream : TextWriter
186          {                      {
187              public LogStream() : this(null) { }              public LogStream() : this(null) { }
188              public LogStream(LogWriter text) : base() { _text_writer = text; this.NewLine = "\n"; }              public LogStream(LogWriter text) : base() { _text_writer = text; this.NewLine = "\n"; }
189              private LogWriter _text_writer;              private LogWriter _text_writer;
# Line 176  namespace RomCheater.Logging Line 191  namespace RomCheater.Logging
191              #region Overriden Methods              #region Overriden Methods
192              public override Encoding Encoding { get { return Encoding.UTF8; } }              public override Encoding Encoding { get { return Encoding.UTF8; } }
193              public override void Write(char value) { base.Write(value); _write(value.ToString()); if (!_text_writer.BeginUpdate) _text_writer.EndLogUpdate(); }              public override void Write(char value) { base.Write(value); _write(value.ToString()); if (!_text_writer.BeginUpdate) _text_writer.EndLogUpdate(); }
194              #endregion                        #endregion
195          }          }
196          #endregion                  #endregion
197      }      }
198  }  }

Legend:
Removed from v.17  
changed lines
  Added in v.19

  ViewVC Help
Powered by ViewVC 1.1.22