13 |
|
{ |
14 |
|
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(); |
20 |
|
private delegate void OnSetLogText(string value); |
21 |
|
private delegate void GenericVoidDelegate(); |
37 |
|
this.RedirectConsoleOutput = redirectConsole; |
38 |
|
toolTip1.SetToolTip(btnClearLog, "Clears the Log"); |
39 |
|
toolTip1.SetToolTip(btnCopyLogToClipboard, "Copies the Log to the Clipboard"); |
40 |
+ |
|
41 |
|
ms = new MemoryStream(); |
42 |
|
sw = new StreamWriter(ms); |
43 |
|
sw.AutoFlush = true; |
44 |
|
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; |
52 |
< |
public LogStream Log { get { return _Log; } private set { _Log = value; } } |
52 |
> |
public LogStream Log { get { return _Log; } private set { _Log = value; } } |
53 |
|
|
54 |
|
|
55 |
|
private MemoryStream ms; |
64 |
|
set |
65 |
|
{ |
66 |
|
_RedirectConsoleOutput = value; |
67 |
< |
if (value) { Console.SetOut(this.Log); } |
68 |
< |
else |
67 |
> |
if (value) { Console.SetOut(this.Log); } |
68 |
> |
else |
69 |
|
{ |
70 |
|
Stream stream = Console.OpenStandardOutput(0x100); |
71 |
|
TextWriter writer = null; |
75 |
|
//writer2.HaveWrittenPreamble = true; |
76 |
|
writer2.AutoFlush = true; |
77 |
|
writer = TextWriter.Synchronized(writer2); |
78 |
< |
Console.SetOut(writer); |
78 |
> |
Console.SetOut(writer); |
79 |
|
} |
80 |
|
} |
81 |
|
} |
141 |
|
//{ |
142 |
|
// 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 |
+ |
writer.Write(value); |
148 |
+ |
writer.Close(); |
149 |
|
sw.Write(value); |
150 |
|
} |
151 |
|
new public string Text |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
< |
public void Clear() |
163 |
> |
public void Clear() |
164 |
|
{ |
165 |
|
Clear(false); |
166 |
|
} |
172 |
|
#endif |
173 |
|
if (force || allow_log_clearing) |
174 |
|
{ |
175 |
< |
|
175 |
> |
|
176 |
|
txtLog.Clear(); |
177 |
|
ms = new MemoryStream(); |
178 |
|
sw = new StreamWriter(ms); |
182 |
|
} |
183 |
|
#region sub-classes |
184 |
|
public class LogStream : TextWriter |
185 |
< |
{ |
185 |
> |
{ |
186 |
|
public LogStream() : this(null) { } |
187 |
|
public LogStream(LogWriter text) : base() { _text_writer = text; this.NewLine = "\n"; } |
188 |
|
private LogWriter _text_writer; |
190 |
|
#region Overriden Methods |
191 |
|
public override Encoding Encoding { get { return Encoding.UTF8; } } |
192 |
|
public override void Write(char value) { base.Write(value); _write(value.ToString()); if (!_text_writer.BeginUpdate) _text_writer.EndLogUpdate(); } |
193 |
< |
#endregion |
193 |
> |
#endregion |
194 |
|
} |
195 |
< |
#endregion |
195 |
> |
#endregion |
196 |
|
} |
197 |
|
} |