--- trunk/RomCheater.Logging/LogWriter.cs 2012/05/10 10:10:55 104 +++ trunk/RomCheater.Logging/LogWriter.cs 2012/05/10 10:53:07 105 @@ -50,7 +50,8 @@ namespace RomCheater.Logging private MemoryStream ms; private StreamWriter sw; private StreamReader sr; - + private bool _AutoScroll; + new public bool AutoScroll { get { return _AutoScroll; } set { _AutoScroll = value; autoscroll_timer.Enabled = value; } } private bool _RedirectConsoleOutput; public bool RedirectConsoleOutput @@ -143,7 +144,9 @@ namespace RomCheater.Logging else { writer.Write(value); } writer.Close(); sw.Write(value); + Application.DoEvents(); } + new public string Text { get @@ -163,7 +166,7 @@ namespace RomCheater.Logging if (fi.Exists) fi.Delete(); } - Log.WriteLine("{0} ({2} v{3} {4}) created on {1}", LoggingConstants.AppLogFile, DateTime.Now.ToString(), LoggingConstants.AppName, LoggingConstants.AppVersion, LoggingConstants.AppBuild); + Log.WriteLine("{0} ({2} v{3} {4}) created on {1}", LoggingConstants.AppLogFile, DateTime.Now.ToString(), LoggingConstants.AppName, LoggingConstants.AppVersion, LoggingConstants.AppBuild); } public void Clear() { @@ -188,15 +191,76 @@ namespace RomCheater.Logging #region sub-classes public class LogStream : TextWriter { + private StringBuilder strMessage = new StringBuilder(); public LogStream() : this(null) { } public LogStream(LogWriter text) : base() { _text_writer = text; this.NewLine = "\n"; } private LogWriter _text_writer; - private void _write(string message) { if (_text_writer == null) return; _text_writer.SetLogText(string.Format("{0}", message)); } + private void _write(string message) + { + if (_text_writer == null) return; + + if (message.EndsWith("\n")) + { + //_text_writer.SetLogText(string.Format("{0}", strMessage.ToString())); + while (_text_writer.logupdater.IsBusy) + { + Application.DoEvents(); + } + _text_writer.logupdater.RunWorkerAsync((string.Format("{0}", strMessage.ToString()))); + strMessage = new StringBuilder(); + } + strMessage.Append(message); + } #region Overriden Methods public override Encoding Encoding { get { return Encoding.UTF8; } } public override void Write(char value) { base.Write(value); _write(value.ToString()); if (!_text_writer.BeginUpdate) _text_writer.EndLogUpdate(); } #endregion } #endregion + + private void autoscroll_timer_Tick(object sender, EventArgs e) + { + if (this.DesignMode) { return; } + //txtLog.ScrollToEnd(); + //txtLog.SelectionStart = txtLog.Text.Length-100; + //txtLog.ScrollToCaret(); + //txtLog.Refresh(); + + txtLog.SelectionStart = 0; + txtLog.ScrollToCaret(); + txtLog.Refresh(); + + int last_line_position = -1; + int position = -1; + int len = txtLog.Text.Length; + StringReader sr = new StringReader(this.StreamToString()); + string line = ""; + while ((line = sr.ReadLine()) != null) + { + position += (line.Length); + last_line_position = (line.Length*2); + //if (line.EndsWith("/n")) + //{ + // position++; + //} + //logger.VerboseDebug.WriteLine("current line: {0}", line); + } + txtLog.SelectionStart = position; + txtLog.ScrollToCaret(); + txtLog.Refresh(); + //autoscroll_timer.Enabled = false; + } + + private void logupdater_DoWork(object sender, DoWorkEventArgs e) + { + string message = e.Argument.ToString(); + SetLogText(string.Format("{0}", message)); + } + + private void logupdater_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + + } } } + \ No newline at end of file |