diff --git a/WindowsInstaller/BetterDiscordWI/FormMain.cs b/WindowsInstaller/BetterDiscordWI/FormMain.cs index a56c51a59..792616217 100644 --- a/WindowsInstaller/BetterDiscordWI/FormMain.cs +++ b/WindowsInstaller/BetterDiscordWI/FormMain.cs @@ -4,35 +4,30 @@ using System.Xml; using BetterDiscordWI.panels; -namespace BetterDiscordWI -{ - public partial class FormMain : Form - { +namespace BetterDiscordWI { + public partial class FormMain : Form { private readonly IPanel[] _panels = { new Panel0(), new Panel1(), new Panel2() }; private int _index; - public String DiscordPath; - public Boolean RestartDiscord = false; - public String Sha; - public Boolean finished = false; + public string DiscordPath; + public bool RestartDiscord = false; + public string Sha; + public bool Finished = false; public XmlNodeList ResourceList; - public FormMain() - { + public FormMain() { InitializeComponent(); Sha = Utils.GetHash(); - if (Sha.Length < 1) - { - MessageBox.Show("Failed to get sha", "Error", MessageBoxButtons.OK); + if (Sha.Length < 1) { + MessageBox.Show(@"Failed to get sha", @"Error", MessageBoxButtons.OK); Environment.Exit(0); } - - foreach (IPanel ipanel in _panels) - { + + foreach (IPanel ipanel in _panels) { panelContainer.Controls.Add((UserControl)ipanel); ((UserControl)ipanel).Dock = DockStyle.Fill; ((UserControl)ipanel).Hide(); @@ -40,48 +35,35 @@ public FormMain() ((UserControl)_panels[_index]).Show(); _panels[_index].SetVisible(); - - btnCancel.Click += (sender, args) => Close(); btnNext.Click += (sender, args) => _panels[_index].BtnNext(); btnBack.Click += (sender, args) => _panels[_index].BtnPrev(); } - public void SwitchPanel(int index) - { + public void SwitchPanel(int index) { ((UserControl)_panels[_index]).Hide(); _index = index; ((UserControl)_panels[_index]).Show(); _panels[_index].SetVisible(); } - protected override void OnFormClosing(FormClosingEventArgs e) - { - if (!finished) - { - DialogResult dr = - MessageBox.Show( - "Setup is not complete. If you exit now, BetterDiscord will not be installed.\n\nExit Setup?", - "Exit Setup?", MessageBoxButtons.YesNo); - - if (dr == DialogResult.No) - { - e.Cancel = true; - } + protected override void OnFormClosing(FormClosingEventArgs e) { + if (Finished) return; + DialogResult dr = MessageBox.Show(@"Setup is not complete. If you exit now, BetterDiscord will not be installed. Exit Setup?", @"Exit Setup?", MessageBoxButtons.YesNo); + if (dr == DialogResult.No) { + e.Cancel = true; } } - readonly Pen borderPen = new Pen(Color.FromArgb(160,160,160)); - protected override void OnPaint(PaintEventArgs e) - { + readonly Pen _borderPen = new Pen(Color.FromArgb(160, 160, 160)); + protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; - g.FillRectangle(SystemBrushes.Window, new Rectangle(0,0, Width, 50) ); - g.DrawLine(borderPen, 0, 50, Width, 50); + g.FillRectangle(SystemBrushes.Window, new Rectangle(0, 0, Width, 50)); + g.DrawLine(_borderPen, 0, 50, Width, 50); g.DrawLine(SystemPens.Window, 0, 51, Width, 51); - g.DrawLine(borderPen, 0, 310, Width, 310); + g.DrawLine(_borderPen, 0, 310, Width, 310); g.DrawLine(SystemPens.Window, 0, 311, Width, 311); - base.OnPaint(e); } diff --git a/WindowsInstaller/BetterDiscordWI/Program.cs b/WindowsInstaller/BetterDiscordWI/Program.cs index 95c66f2f6..ff3919b15 100644 --- a/WindowsInstaller/BetterDiscordWI/Program.cs +++ b/WindowsInstaller/BetterDiscordWI/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; namespace BetterDiscordWI diff --git a/WindowsInstaller/BetterDiscordWI/Utils.cs b/WindowsInstaller/BetterDiscordWI/Utils.cs index 99ed263b1..1d884d014 100644 --- a/WindowsInstaller/BetterDiscordWI/Utils.cs +++ b/WindowsInstaller/BetterDiscordWI/Utils.cs @@ -1,29 +1,18 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; using System.Diagnostics; -using System.Linq; using System.Net; -using System.Text; using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; namespace BetterDiscordWI { class Utils { - - - public void StartDownload(ProgressBar pb, String url, String name) + public void StartDownload(ProgressBar pb, string url, string name) { - - - Thread t = new Thread(() => { - WebClient webClient = new WebClient(); - webClient.Headers["User-Agent"] = "Mozilla/5.0"; + WebClient webClient = new WebClient {Headers = {["User-Agent"] = "Mozilla/5.0"}}; webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs args) { double percentage = (double.Parse(args.BytesReceived.ToString()) /double.Parse(args.TotalBytesToReceive.ToString())) * 100; @@ -43,18 +32,15 @@ public void StartDownload(ProgressBar pb, String url, String name) t.Start(); } - public static String GetHash() + public static string GetHash() { - WebClient wc = new WebClient(); - wc.Headers["User-Agent"] = "Mozilla/5.0"; - String result = wc.DownloadString("https://api.github.com/repos/Jiiks/BetterDiscordApp/commits/master"); + WebClient wc = new WebClient {Headers = {["User-Agent"] = "Mozilla/5.0"}}; + string result = wc.DownloadString(@"https://api.github.com/repos/Jiiks/BetterDiscordApp/commits/master"); int start = result.IndexOf("{\"sha\":"); int end = result.IndexOf("\",\""); return result.Substring(start + 8, end - 8); } - - } -} +} \ No newline at end of file diff --git a/WindowsInstaller/BetterDiscordWI/panels/IPanel.cs b/WindowsInstaller/BetterDiscordWI/panels/IPanel.cs index 445ec2e0f..c386d7c85 100644 --- a/WindowsInstaller/BetterDiscordWI/panels/IPanel.cs +++ b/WindowsInstaller/BetterDiscordWI/panels/IPanel.cs @@ -1,19 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; - -namespace BetterDiscordWI.panels -{ - interface IPanel - { - +namespace BetterDiscordWI.panels { + interface IPanel { void SetVisible(); FormMain GetParent(); void BtnNext(); void BtnPrev(); - } -} +} \ No newline at end of file diff --git a/WindowsInstaller/BetterDiscordWI/panels/Panel0.cs b/WindowsInstaller/BetterDiscordWI/panels/Panel0.cs index 5c99d37f1..996945352 100644 --- a/WindowsInstaller/BetterDiscordWI/panels/Panel0.cs +++ b/WindowsInstaller/BetterDiscordWI/panels/Panel0.cs @@ -1,41 +1,31 @@ using System.Windows.Forms; -namespace BetterDiscordWI.panels -{ - public partial class Panel0 : UserControl, IPanel - { - public Panel0() - { +namespace BetterDiscordWI.panels { + public partial class Panel0 : UserControl, IPanel { + public Panel0() { InitializeComponent(); - radioAcceptLicense.CheckedChanged += (sender, args) => - { + radioAcceptLicense.CheckedChanged += (sender, args) => { GetParent().btnNext.Enabled = radioAcceptLicense.Checked; }; } - public void SetVisible() - { + public void SetVisible() { GetParent().btnBack.Visible = false; GetParent().btnNext.Enabled = false; - GetParent().btnNext.Text = "Next >"; - GetParent().lblPanelTitle.Text = "BetterDiscord License Agreement"; + GetParent().btnNext.Text = @"Next >"; + GetParent().lblPanelTitle.Text = @"BetterDiscord License Agreement"; GetParent().btnNext.Enabled = radioAcceptLicense.Checked; } - public FormMain GetParent() - { - return (FormMain) ParentForm; + public FormMain GetParent() { + return (FormMain)ParentForm; } - public void BtnNext() - { + public void BtnNext() { GetParent().SwitchPanel(1); } - public void BtnPrev() - { - throw new System.NotImplementedException(); - } + public void BtnPrev() {} } } diff --git a/WindowsInstaller/BetterDiscordWI/panels/Panel1.cs b/WindowsInstaller/BetterDiscordWI/panels/Panel1.cs index 6a0ae8837..7529420c0 100644 --- a/WindowsInstaller/BetterDiscordWI/panels/Panel1.cs +++ b/WindowsInstaller/BetterDiscordWI/panels/Panel1.cs @@ -14,10 +14,10 @@ public void SetVisible() { GetParent().btnBack.Visible = true; GetParent().btnNext.Enabled = true; GetParent().btnBack.Enabled = true; - GetParent().btnNext.Text = "Install"; - GetParent().lblPanelTitle.Text = "BetterDiscord Installation"; + GetParent().btnNext.Text = @"Install"; + GetParent().lblPanelTitle.Text = @"BetterDiscord Installation"; - pickVersion(); + PickVersion(); } public FormMain GetParent() { @@ -42,51 +42,49 @@ private void btnBrowser_Click(object sender, EventArgs e) { } private void checkBox1_CheckedChanged(object sender, EventArgs e) { - pickVersion(); + PickVersion(); } private void checkBox2_CheckedChanged(object sender, EventArgs e) { - pickVersion(); + PickVersion(); } - private void pickVersion() { - string dirPath = null; - if(checkBox1.Checked == true) { - dirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\DiscordCanary"; + private void PickVersion() { + string dirPath; + if(checkBox1.Checked) { + dirPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\DiscordCanary"; if(!Directory.Exists(dirPath)) checkBox1.Checked = false; checkBox2.Checked = false; - } else if(checkBox2.Checked == true) { - dirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\DiscordPTB"; + } else if(checkBox2.Checked) { + dirPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\DiscordPTB"; if(!Directory.Exists(dirPath)) checkBox2.Checked = false; checkBox1.Checked = false; } else { - dirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Discord"; + dirPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Discord"; } - if(Directory.Exists(dirPath)) { - String[] directories = Directory.GetDirectories(dirPath); + if (!Directory.Exists(dirPath)) return; + string[] directories = Directory.GetDirectories(dirPath); - String highestVersion = null; + string highestVersion = null; - foreach(String s in directories) { - Debug.Print(s); - if(!s.Contains("app-")) - continue; - if(String.IsNullOrEmpty(highestVersion)) { - highestVersion = s; - continue; - } - - if(String.CompareOrdinal(s, highestVersion) > 0) { - highestVersion = s; - } + foreach(string s in directories) { + Debug.Print(s); + if(!s.Contains("app-")) + continue; + if(string.IsNullOrEmpty(highestVersion)) { + highestVersion = s; + continue; } - - tbPath.Text = highestVersion; + if(string.CompareOrdinal(s, highestVersion) > 0) { + highestVersion = s; + } } + + tbPath.Text = highestVersion; } } -} +} \ No newline at end of file diff --git a/WindowsInstaller/BetterDiscordWI/panels/Panel2.cs b/WindowsInstaller/BetterDiscordWI/panels/Panel2.cs index 84b119428..2f8c96c35 100644 --- a/WindowsInstaller/BetterDiscordWI/panels/Panel2.cs +++ b/WindowsInstaller/BetterDiscordWI/panels/Panel2.cs @@ -11,7 +11,7 @@ namespace BetterDiscordWI.panels { public partial class Panel2: UserControl, IPanel { - private String _dataPath, _tempPath; + private string _dataPath, _tempPath; private Utils _utils; public Panel2() { @@ -35,41 +35,39 @@ public void SetVisible() { } private void KillProcessIfInstalling(string app) { - if(GetParent().DiscordPath.Contains(app + "\\")) { - AppendLog("Killing " + app); - foreach(var process in Process.GetProcessesByName(app)) { - process.Kill(); - } + if (!GetParent().DiscordPath.Contains(app + "\\")) return; + AppendLog("Killing " + app); + foreach(var process in Process.GetProcessesByName(app)) { + process.Kill(); } } private void CreateDirectories() { Thread t = new Thread(() => { - _dataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord"; - _tempPath = _dataPath + "\\temp"; + _dataPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\BetterDiscord"; + _tempPath = $"{_dataPath}\\temp"; AppendLog("Deleting old cached files"); try { - if(File.Exists(_dataPath + "\\emotes_bttv.json")) { - File.Delete(_dataPath + "\\emotes_bttv.json"); + if(File.Exists($"{_dataPath}\\emotes_bttv.json")) { + File.Delete($"{_dataPath}\\emotes_bttv.json"); } - if(File.Exists(_dataPath + "\\emotes_bttv_2.json")) { - File.Delete(_dataPath + "\\emotes_bttv_2.json"); + if(File.Exists($"{_dataPath}\\emotes_bttv_2.json")) { + File.Delete($"{_dataPath}\\emotes_bttv_2.json"); } - if(File.Exists(_dataPath + "\\emotes_ffz.json")) { - File.Delete(_dataPath + "\\emotes_ffz.json"); + if(File.Exists($"{_dataPath}\\emotes_ffz.json")) { + File.Delete($"{_dataPath}\\emotes_ffz.json"); } - if(File.Exists(_dataPath + "\\emotes_twitch_global.json")) { - File.Delete(_dataPath + "\\emotes_twitch_global.json"); + if(File.Exists($"{_dataPath}\\emotes_twitch_global.json")) { + File.Delete($"{_dataPath}\\emotes_twitch_global.json"); } - if(File.Exists(_dataPath + "\\emotes_twitch_subscriber.json")) { - File.Delete(_dataPath + "\\emotes_twitch_subscriber.json"); + if(File.Exists($"{_dataPath}\\emotes_twitch_subscriber.json")) { + File.Delete($"{_dataPath}\\emotes_twitch_subscriber.json"); } - if(File.Exists(_dataPath + "\\user.json")) { - File.Delete(_dataPath + "\\user.json"); + if(File.Exists($"{_dataPath}\\user.json")) { + File.Delete($"{_dataPath}\\user.json"); } } catch(Exception e) { AppendLog("Failed to delete one or more cached files"); } - if(Directory.Exists(_tempPath)) { AppendLog("Deleting temp path"); Directory.Delete(_tempPath, true); @@ -82,9 +80,9 @@ private void CreateDirectories() { Directory.CreateDirectory(_tempPath); - DownloadResource("BetterDiscord.zip", "https://github.com/Jiiks/BetterDiscordApp/archive/stable.zip"); + DownloadResource("BetterDiscord.zip", "https://github.com/Jiiks/BetterDiscordApp/archive/stable16.zip"); - while(!File.Exists(_tempPath + "\\BetterDiscord.zip")) { + while(!File.Exists($"{_tempPath}\\BetterDiscord.zip")) { Debug.Print("Waiting for download"); Thread.Sleep(100); } @@ -92,10 +90,8 @@ private void CreateDirectories() { AppendLog("Extracting BetterDiscord"); ZipArchive zar = - ZipFile.OpenRead(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + - "\\BetterDiscord\\temp\\BetterDiscord.zip"); - zar.ExtractToDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + - "\\BetterDiscord\\temp\\"); + ZipFile.OpenRead($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\BetterDiscord\\temp\\BetterDiscord.zip"); + zar.ExtractToDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\BetterDiscord\\temp\\"); DeleteDirs(); }); @@ -107,14 +103,14 @@ private void CreateDirectories() { private void DeleteDirs() { int errors = 0; Thread t = new Thread(() => { - String dir = GetParent().DiscordPath + "\\resources\\app"; + string dir = $"{GetParent().DiscordPath}\\resources\\app"; if(Directory.Exists(dir)) { try { AppendLog("Deleting " + dir); Directory.Delete(dir, true); } catch { - AppendLog("Error: Failed to Delete the '" + dir + "\\resources\\app' Directory."); + AppendLog($"Error: Failed to Delete the '{dir}\\resources\\app' Directory."); errors = 1; Finalize(errors); } @@ -125,11 +121,11 @@ private void DeleteDirs() { Thread.Sleep(100); } - dir = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord"; + dir = $"{GetParent().DiscordPath}\\resources\\node_modules\\BetterDiscord"; if(Directory.Exists(dir)) { - AppendLog("Deleting " + dir); + AppendLog($"Deleting {dir}"); Directory.Delete(dir, true); } @@ -139,12 +135,12 @@ private void DeleteDirs() { } AppendLog("Extracting app.asar"); - string appAsarPath = GetParent().DiscordPath + "\\resources\\app.asar"; + string appAsarPath = $"{GetParent().DiscordPath}\\resources\\app.asar"; if(File.Exists(appAsarPath)) { AsarArchive archive = new AsarArchive(appAsarPath); AsarExtractor extractor = new AsarExtractor(); - extractor.ExtractAll(archive, GetParent().DiscordPath + "\\resources\\app\\"); + extractor.ExtractAll(archive, $"{GetParent().DiscordPath}\\resources\\app\\"); } else { AppendLog("Error: app.asar file couldn't be found in 'resources' folder. Installation cannot Continue."); errors = 1; @@ -153,7 +149,7 @@ private void DeleteDirs() { if(errors == 0) { AppendLog("Moving BetterDiscord to resources\\node_modules\\"); - Directory.Move(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord\\temp\\BetterDiscordApp-stable", GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord"); + Directory.Move($"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\BetterDiscord\\temp\\BetterDiscordApp-stable16", $"{GetParent().DiscordPath}\\resources\\node_modules\\BetterDiscord"); try { Splice(); @@ -169,25 +165,23 @@ private void DeleteDirs() { t.Start(); } - - private void DownloadResource(String resource, String url) { + private void DownloadResource(string resource, string url) { AppendLog("Downloading Resource: " + resource); - WebClient webClient = new WebClient(); - webClient.Headers["User-Agent"] = "Mozilla/5.0"; + WebClient webClient = new WebClient {Headers = {["User-Agent"] = "Mozilla/5.0"}}; - webClient.DownloadFile(new Uri(url), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord\\temp\\" + resource); + webClient.DownloadFile(new Uri(url), $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\BetterDiscord\\temp\\{resource}"); } private void Splice() { - String indexloc = GetParent().DiscordPath + "\\resources\\app\\app\\index.js"; + string indexloc = $"{GetParent().DiscordPath}\\resources\\app\\app\\index.js"; Thread t = new Thread(() => { - List lines = new List(); + List lines = new List(); AppendLog("Spicing index"); using(FileStream fs = new FileStream(indexloc, FileMode.Open)) { using(StreamReader reader = new StreamReader(fs)) { - String line = ""; + string line = ""; while((line = reader.ReadLine()) != null) { //if(GetParent().DiscordPath.Contains("Discord\\")) { //if(GetParent().DiscordPath.Contains("DiscordCanary\\")) { @@ -195,9 +189,10 @@ private void Splice() { if(line.Replace(" ", "").Contains("var_fs=")) { lines.Add(line); lines.Add("var _betterDiscord = require('betterdiscord');"); + lines.Add("var _betterDiscord2;"); } else if(line.Replace(" ", "").Contains("mainWindow=new")) { lines.Add(line); - lines.Add(File.ReadAllText("splice")); + lines.Add(File.ReadAllText(@"splice")); } else { lines.Add(line); } @@ -210,35 +205,32 @@ private void Splice() { File.WriteAllLines(indexloc, lines.ToArray()); - AppendLog("Finished installation, verifying installation..."); int errors = 0; - String curPath = GetParent().DiscordPath + "\\resources\\app\\app\\index.js"; + string curPath = $"{GetParent().DiscordPath}\\resources\\app\\app\\index.js"; if(!File.Exists(curPath)) { - AppendLog("ERROR: FILE: " + curPath + " DOES NOT EXIST!"); + AppendLog($"ERROR: FILE: {curPath} DOES NOT EXIST!"); errors++; } - curPath = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord"; + curPath = $"{GetParent().DiscordPath}\\resources\\node_modules\\BetterDiscord"; if(!Directory.Exists(curPath)) { - AppendLog("ERROR: DIRECTORY: " + curPath + " DOES NOT EXIST"); + AppendLog($"ERROR: DIRECTORY: {curPath} DOES NOT EXIST!"); errors++; } - String basePath = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord"; - String[] bdFiles = { "\\package.json", "\\betterdiscord.js", "\\lib\\BetterDiscord.js", "\\lib\\config.json", "\\lib\\Utils.js" }; + string basePath = $"{GetParent().DiscordPath}\\resources\\node_modules\\BetterDiscord"; + string[] bdFiles = { "\\package.json", "\\betterdiscord.js", "\\lib\\BetterDiscord.js", "\\lib\\config.json", "\\lib\\Utils.js" }; foreach(string s in bdFiles.Where(s => !File.Exists(basePath + s))) { - AppendLog("ERROR: FILE: " + basePath + s + " DOES NOT EXIST"); + AppendLog($"ERROR: FILE: {basePath}{s} DOES NOT EXIST"); errors++; } - - Finalize(errors); }); @@ -246,24 +238,23 @@ private void Splice() { } private void Finalize(int errors) { - AppendLog("Finished installing BetterDiscord with " + errors + " errors"); - + AppendLog($"Finished installing BetterDiscord with {errors} errors"); Invoke((MethodInvoker)delegate { - GetParent().finished = true; - GetParent().btnCancel.Text = "OK"; + GetParent().Finished = true; + GetParent().btnCancel.Text = @"OK"; GetParent().btnCancel.Enabled = true; }); if(GetParent().RestartDiscord) { if(GetParent().DiscordPath.Contains("\\Discord\\")) { - Process.Start(GetParent().DiscordPath + "\\Discord.exe"); + Process.Start($"{GetParent().DiscordPath}\\Discord.exe"); } if(GetParent().DiscordPath.Contains("\\DiscordCanary\\")) { - Process.Start(GetParent().DiscordPath + "\\DiscordCanary.exe"); + Process.Start($"{GetParent().DiscordPath}\\DiscordCanary.exe"); } if(GetParent().DiscordPath.Contains("\\DiscordPTB\\")) { - Process.Start(GetParent().DiscordPath + "\\DiscordPTB.exe"); + Process.Start($"{GetParent().DiscordPath}\\DiscordPTB.exe"); } } } @@ -272,15 +263,11 @@ public FormMain GetParent() { return (FormMain)ParentForm; } - public void BtnNext() { - throw new NotImplementedException(); - } + public void BtnNext() { } - public void BtnPrev() { - throw new NotImplementedException(); - } + public void BtnPrev() { } - private void AppendLog(String message) { + private void AppendLog(string message) { Invoke((MethodInvoker)delegate { rtLog.AppendText(message + "\n"); rtLog.SelectionStart = rtLog.Text.Length;