/[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

--- trunk/RomCheater.Logging/LogWriter.cs	2012/06/05 13:52:37	308
+++ trunk/RomCheater.Logging/LogWriter.cs	2012/06/05 14:07:27	309
@@ -10,49 +10,25 @@
 using System.IO;
 using System.Reflection;
 using System.Security;
+using System.Threading;
 
 namespace RomCheater.Logging
 {
     public partial class LogWriter : UserControl
     {
         private static string LOG_PATH { get { return string.Format(@"{0}\{1}", typeof(LogWriter).Assembly.Location.Replace("RomCheater.Logging.dll", ""), LoggingConstants.AppLogFile); } }
-
-        private delegate string OnGetLogText();
-        private delegate void OnSetLogText(string value);
-        private delegate void GenericVoidDelegate();
-
-        //private OnGetLogText HandleGetLogText = null;
-        private OnSetLogText HandleSetLogText = null;
-        private GenericVoidDelegate delegate_EndLogUpdate = null;
-
         public LogWriter() : this(false) { }
         public LogWriter(bool redirectConsole)
         {
             InitializeComponent();
             this.Log = new LogStream(this);
-            //HandleGetLogText += new OnGetLogText(GetLogText);
-            HandleSetLogText += new OnSetLogText(SetLogText);
-
-            //delegate_EndLogUpdate += new GenericVoidDelegate(EndLogUpdate);
-
             this.RedirectConsoleOutput = redirectConsole;
             toolTip1.SetToolTip(btnClearLog, "Clears the Log");
             toolTip1.SetToolTip(btnCopyLogToClipboard, "Copies the Log to the Clipboard");
-
-            //ms = new MemoryStream();
-            //sw = new StreamWriter(ms);
-            //sw.AutoFlush = true;
-            //sr = new StreamReader(ms);
-
                 chkAutoScroll.Checked = this.AutoScroll;
         }
         private LogStream _Log;
         public LogStream Log { get { return _Log; } private set { _Log = value; } }
-
-
-        //private MemoryStream ms;
-        //private StreamWriter sw;
-        //private StreamReader sr;
         private bool _AutoScroll;
         new public bool AutoScroll
         {
@@ -67,7 +43,6 @@
                 if (AutoScroll && !value)
                     chkAutoScroll.Checked = false;
                 _AutoScroll = value; 
-                autoscroll_timer.Enabled = value;
             }
         }
 
@@ -96,70 +71,6 @@
 
         private void btnClearLog_Click(object sender, EventArgs e) { this.Clear(true); }
         private void btnCopyLogToClipboard_Click(object sender, EventArgs e) { Clipboard.SetText(txtLog.Text); }
-
-
-        private string PreserveLineEndings(string text) { return text.Replace("\n", System.Environment.NewLine); }
-
-
-        //private bool BeginUpdate;
-        //public void BeginLogUpdate()
-        //{
-        //    BeginUpdate = true;
-        //}
-        //public void EndLogUpdate()
-        //{
-        //    if (txtLog.InvokeRequired)
-        //    {
-        //        this.Invoke(delegate_EndLogUpdate);
-        //    }
-        //    else
-        //    {
-        //        StringReader _sr = new StringReader(GetLogText());
-        //        List<string> lines = new List<string>();
-        //        string line = "";
-        //        while ((line = _sr.ReadLine()) != null)
-        //        {
-        //            lines.Add(line);
-        //        }
-        //        txtLog.Lines = lines.ToArray();
-        //        BeginUpdate = false;
-        //    }
-        //}
-        //private string StreamToString()
-        //{
-        //    try
-        //    {
-        //        string value = "";
-        //        sr = new StreamReader(ms);
-        //        sr.BaseStream.Seek(0, SeekOrigin.Begin);
-        //        value = sr.ReadToEnd();
-        //        return value;
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //        return "";
-        //    }
-        //}
-        //public string GetLogText()
-        //{
-        //    if (txtLog.InvokeRequired)
-        //    {
-        //        return (string)this.Invoke(HandleGetLogText, new object[] { });
-        //    }
-        //    else
-        //    {
-        //        string text = PreserveLineEndings(StreamToString());
-        //        StringReader _sr = new StringReader(GetLogText());
-        //        List<string> lines = new List<string>();
-        //        string line = "";
-        //        while ((line = _sr.ReadLine()) != null)
-        //        {
-        //            lines.Add(line);
-        //        }
-        //        txtLog.Lines = lines.ToArray();
-        //        return text;
-        //    }
-        //}
         public void SetLogText(string value)
         {
             FileStream fs = new FileStream(LOG_PATH, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
@@ -168,15 +79,15 @@
             if (value == Log.NewLine) { writer.Write(System.Environment.NewLine); }
             else { writer.Write(value); }
             writer.Close();
-            //string text = value.Replace(System.Environment.NewLine,"");
-            //string text = value.Replace(System.Environment.NewLine, Log.NewLine);
-            ////if (text.StartsWith(Log.NewLine))
-            ////{
-            ////    text = text.Remove(0, Log.NewLine.Length);
-            ////}
-            //sw.Write(text);
-            //Application.DoEvents();
             txtLog.Text += value;
+
+            if (AutoScroll)
+            {
+                txtLog.SelectionStart = txtLog.TextLength;
+                txtLog.ScrollToCaret();
+                txtLog.Refresh();
+            }
+            Thread.Sleep(100);
         }
 
         new public string Text
@@ -210,15 +121,7 @@
 #if ALLOW_LOG_CLEARING
             allow_log_clearing = true;
 #endif
-            if (force || allow_log_clearing)
-            {
-
-                txtLog.Clear();
-                //ms = new MemoryStream();
-                //sw = new StreamWriter(ms);
-                //sw.AutoFlush = true;
-                //sr = new StreamReader(ms);
-            }
+            if (force || allow_log_clearing) { txtLog.Clear(); }
         }
         #region sub-classes
         public class LogStream : TextWriter
@@ -227,25 +130,8 @@
             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;
-
-            //    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(bool value) { _text_writer.SetLogText(value.ToString()); }
             public override void Write(char value) { _text_writer.SetLogText(value.ToString()); }
             public override void Write(char[] buffer) { _text_writer.SetLogText(new string(buffer)); }
@@ -306,39 +192,41 @@
 
         private void autoscroll_timer_Tick(object sender, EventArgs e)
         {           
-            try
-            {
-                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 * 2);
-                //    last_line_position = (line.Length * 2);
-                //    //if (line.EndsWith("/n"))
-                //    //{
-                //    //    position++;
-                //    //}
-                //    //logger.VerboseDebug.WriteLine("current line: {0}", line);
-                //}
-                txtLog.SelectionStart = len;
-                txtLog.ScrollToCaret();
-                txtLog.Refresh();
-                //autoscroll_timer.Enabled = false;
-            }
-            catch { }
+            //try
+            //{
+            //    if (this.DesignMode) { return; }
+            //    AUTO_SCROLL = true;
+            //    ////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 * 2);
+            //    //    last_line_position = (line.Length * 2);
+            //    //    //if (line.EndsWith("/n"))
+            //    //    //{
+            //    //    //    position++;
+            //    //    //}
+            //    //    //logger.VerboseDebug.WriteLine("current line: {0}", line);
+            //    //}
+            //    txtLog.SelectionStart = len;
+            //    txtLog.ScrollToCaret();
+            //    txtLog.Refresh();
+            //    //autoscroll_timer.Enabled = false;
+            //    FIRST_LOAD = false;
+            //}
+            //catch { }
 
         }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22