diff --git a/WindowsInstaller/BetterDiscordWI/panels/Panel1.Designer.cs b/WindowsInstaller/BetterDiscordWI/panels/Panel1.Designer.cs index 31ddf84..1f37864 100644 --- a/WindowsInstaller/BetterDiscordWI/panels/Panel1.Designer.cs +++ b/WindowsInstaller/BetterDiscordWI/panels/Panel1.Designer.cs @@ -31,11 +31,11 @@ this.label1 = new System.Windows.Forms.Label(); this.btnBrowser = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); - this.tbPath = new BetterDiscordWI.components.CTextBox(); this.label3 = new System.Windows.Forms.Label(); this.cbRestart = new System.Windows.Forms.CheckBox(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.checkBox2 = new System.Windows.Forms.CheckBox(); + this.tbPath = new BetterDiscordWI.components.CTextBox(); this.SuspendLayout(); // // label1 @@ -67,15 +67,6 @@ this.label2.TabIndex = 3; this.label2.Text = "*If the path is not pointing to the latest version of Discord then click browse a" + "nd select it."; - // - // tbPath - // - this.tbPath.CAutoSize = false; - this.tbPath.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.tbPath.Location = new System.Drawing.Point(23, 46); - this.tbPath.Name = "tbPath"; - this.tbPath.Size = new System.Drawing.Size(377, 26); - this.tbPath.TabIndex = 4; // // label3 // @@ -119,6 +110,15 @@ this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged); // + // tbPath + // + this.tbPath.CAutoSize = false; + this.tbPath.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tbPath.Location = new System.Drawing.Point(23, 46); + this.tbPath.Name = "tbPath"; + this.tbPath.Size = new System.Drawing.Size(377, 26); + this.tbPath.TabIndex = 4; + // // Panel1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); diff --git a/WindowsInstaller/BetterDiscordWI/panels/Panel1.cs b/WindowsInstaller/BetterDiscordWI/panels/Panel1.cs index 8106ffe..6a0ae88 100644 --- a/WindowsInstaller/BetterDiscordWI/panels/Panel1.cs +++ b/WindowsInstaller/BetterDiscordWI/panels/Panel1.cs @@ -3,17 +3,13 @@ using System.Diagnostics; using System.IO; using System.Windows.Forms; -namespace BetterDiscordWI.panels -{ - public partial class Panel1 : UserControl, IPanel - { - public Panel1() - { +namespace BetterDiscordWI.panels { + public partial class Panel1: UserControl, IPanel { + public Panel1() { InitializeComponent(); } - public void SetVisible() - { + public void SetVisible() { GetParent().btnBack.Visible = true; GetParent().btnNext.Enabled = true; @@ -21,134 +17,69 @@ namespace BetterDiscordWI.panels GetParent().btnNext.Text = "Install"; GetParent().lblPanelTitle.Text = "BetterDiscord Installation"; - String[] directories = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Discord"); - - 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; - } - } - - - tbPath.Text = highestVersion; + pickVersion(); } - public FormMain GetParent() - { - return (FormMain) ParentForm; + public FormMain GetParent() { + return (FormMain)ParentForm; } - public void BtnNext() - { + public void BtnNext() { GetParent().DiscordPath = tbPath.Text; GetParent().RestartDiscord = cbRestart.Checked; GetParent().SwitchPanel(2); } - public void BtnPrev() - { + public void BtnPrev() { GetParent().SwitchPanel(0); } - private void btnBrowser_Click(object sender, EventArgs e) - { - FolderBrowserDialog fbd = new FolderBrowserDialog {SelectedPath = tbPath.Text}; + private void btnBrowser_Click(object sender, EventArgs e) { + FolderBrowserDialog fbd = new FolderBrowserDialog { SelectedPath = tbPath.Text }; fbd.ShowDialog(GetParent()); tbPath.Text = fbd.SelectedPath; } - private void checkBox1_CheckedChanged(object sender, EventArgs e) - { - if (checkBox1.Checked == true) - { - checkBox2.Checked = false; - String[] directories = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\DiscordCanary"); - - 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; - } - } - - - tbPath.Text = highestVersion; - } - if (checkBox1.Checked == false) - { - if (checkBox2.Checked == false) - { - String[] directories = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Discord"); - - 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; - } - } - - - tbPath.Text = highestVersion; - } - } + private void checkBox1_CheckedChanged(object sender, EventArgs e) { + pickVersion(); } - private void checkBox2_CheckedChanged(object sender, EventArgs e) - { - if (checkBox2.Checked == true) - { + private void checkBox2_CheckedChanged(object sender, EventArgs e) { + pickVersion(); + } + + private void pickVersion() { + string dirPath = null; + if(checkBox1.Checked == true) { + 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"; + if(!Directory.Exists(dirPath)) checkBox2.Checked = false; + checkBox1.Checked = false; - String[] directories = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\DiscordPTB"); + } else { + dirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Discord"; + } + + if(Directory.Exists(dirPath)) { + String[] directories = Directory.GetDirectories(dirPath); String highestVersion = null; - foreach (String s in directories) - { + foreach(String s in directories) { Debug.Print(s); - if (!s.Contains("app-")) continue; - if (String.IsNullOrEmpty(highestVersion)) - { + if(!s.Contains("app-")) + continue; + if(String.IsNullOrEmpty(highestVersion)) { highestVersion = s; continue; } - if (String.CompareOrdinal(s, highestVersion) > 0) - { + if(String.CompareOrdinal(s, highestVersion) > 0) { highestVersion = s; } } @@ -156,34 +87,6 @@ namespace BetterDiscordWI.panels tbPath.Text = highestVersion; } - if (checkBox2.Checked == false) - { - if (checkBox1.Checked == false) - { - String[] directories = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Discord"); - - 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; - } - } - - - tbPath.Text = highestVersion; - } - } } } } diff --git a/WindowsInstaller/BetterDiscordWI/panels/Panel2.cs b/WindowsInstaller/BetterDiscordWI/panels/Panel2.cs index e4b81b1..173f47c 100644 --- a/WindowsInstaller/BetterDiscordWI/panels/Panel2.cs +++ b/WindowsInstaller/BetterDiscordWI/panels/Panel2.cs @@ -9,20 +9,16 @@ using System.Threading; using System.Windows.Forms; using asardotnet; -namespace BetterDiscordWI.panels -{ - public partial class Panel2 : UserControl, IPanel - { +namespace BetterDiscordWI.panels { + public partial class Panel2: UserControl, IPanel { private String _dataPath, _tempPath; private Utils _utils; - public Panel2() - { + public Panel2() { InitializeComponent(); } - public void SetVisible() - { + public void SetVisible() { GetParent().btnBack.Enabled = false; GetParent().btnNext.Enabled = false; GetParent().btnBack.Visible = false; @@ -30,74 +26,56 @@ namespace BetterDiscordWI.panels GetParent().btnCancel.Enabled = false; _utils = new Utils(); - if (GetParent().DiscordPath.Contains("Discord\\")) - { - AppendLog("Killing Discord"); - foreach (var process in Process.GetProcessesByName("Discord")) - { - process.Kill(); - } - } - if (GetParent().DiscordPath.Contains("DiscordCanary\\")) - { - AppendLog("Killing DiscordCanary"); - foreach (var process in Process.GetProcessesByName("DiscordCanary")) - { - process.Kill(); - } - } - if (GetParent().DiscordPath.Contains("DiscordPTB\\")) - { - AppendLog("Killing DiscordPTB"); - foreach (var process in Process.GetProcessesByName("DiscordPTB")) - { - process.Kill(); - } - } + + KillProcessIfInstalling("Discord"); + KillProcessIfInstalling("DiscordCanary"); + KillProcessIfInstalling("DiscordPTB"); CreateDirectories(); } - private void CreateDirectories() - { - Thread t = new Thread(() => - { + private void KillProcessIfInstalling(string app) { + if(GetParent().DiscordPath.Contains(app + "\\")) { + 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"; AppendLog("Deleting old cached files"); - try - { - if (File.Exists(_dataPath + "\\emotes_bttv.json")) - { + try { + if(File.Exists(_dataPath + "\\emotes_bttv.json")) { File.Delete(_dataPath + "\\emotes_bttv.json"); } - if (File.Exists(_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")) { + if(File.Exists(_dataPath + "\\emotes_ffz.json")) { File.Delete(_dataPath + "\\emotes_ffz.json"); } - if (File.Exists(_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")) { + if(File.Exists(_dataPath + "\\emotes_twitch_subscriber.json")) { File.Delete(_dataPath + "\\emotes_twitch_subscriber.json"); } - if (File.Exists(_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"); } + } catch(Exception e) { AppendLog("Failed to delete one or more cached files"); } - if (Directory.Exists(_tempPath)) - { + if(Directory.Exists(_tempPath)) { AppendLog("Deleting temp path"); Directory.Delete(_tempPath, true); } - while (Directory.Exists(_tempPath)) - { + while(Directory.Exists(_tempPath)) { Debug.Print("Waiting for dirdel"); Thread.Sleep(100); } @@ -106,8 +84,7 @@ namespace BetterDiscordWI.panels DownloadResource("BetterDiscord.zip", "https://github.com/Jiiks/BetterDiscordApp/archive/stable.zip"); - while (!File.Exists(_tempPath + "\\BetterDiscord.zip")) - { + while(!File.Exists(_tempPath + "\\BetterDiscord.zip")) { Debug.Print("Waiting for download"); Thread.Sleep(100); } @@ -127,30 +104,23 @@ namespace BetterDiscordWI.panels } - private void DeleteDirs() - { + private void DeleteDirs() { int errors = 0; - Thread t = new Thread(() => - { + Thread t = new Thread(() => { String dir = GetParent().DiscordPath + "\\resources\\app"; - if (Directory.Exists(dir)) - { - try - { + if(Directory.Exists(dir)) { + try { AppendLog("Deleting " + dir); Directory.Delete(dir, true); - } - catch - { + } catch { AppendLog("Error Failed to Delete the '" + dir + "\\resources\\app' Directory."); errors = 1; Finalize(errors); } } - while (Directory.Exists(dir)) - { + while(Directory.Exists(dir)) { Debug.Print("Waiting for direl"); Thread.Sleep(100); } @@ -158,14 +128,12 @@ namespace BetterDiscordWI.panels dir = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord"; - if (Directory.Exists(dir)) - { + if(Directory.Exists(dir)) { AppendLog("Deleting " + dir); Directory.Delete(dir, true); } - while (Directory.Exists(dir)) - { + while(Directory.Exists(dir)) { Debug.Print("Waiting for direl"); Thread.Sleep(100); } @@ -174,107 +142,59 @@ namespace BetterDiscordWI.panels Directory.Move(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord\\temp\\BetterDiscordApp-stable", GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord"); - try - { + try { AppendLog("Extracting app.asar"); AsarArchive archive = new AsarArchive(GetParent().DiscordPath + "\\resources\\app.asar"); AsarExtractor extractor = new AsarExtractor(); //Add extraoffset of 3 - extractor.ExtractAll(archive, GetParent().DiscordPath + "\\resources\\app\\", 3); + extractor.ExtractAll(archive, GetParent().DiscordPath + "\\resources\\app\\"); Splice(); - } - catch - { + } catch { AppendLog("Error Extracting app.asar: Newtonsoft.Json.dll might not be present in the Installer Folder. Installation cannot Continue."); errors = 1; Finalize(errors); } }); - - + + 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.DownloadFile(new Uri(url), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord\\temp\\" + resource); } - private void Splice() - { + private void Splice() { String indexloc = GetParent().DiscordPath + "\\resources\\app\\app\\index.js"; - Thread t = new Thread(() => - { + Thread t = new Thread(() => { List lines = new List(); AppendLog("Spicing index"); - using (FileStream fs = new FileStream(indexloc, FileMode.Open)) - { - using (StreamReader reader = new StreamReader(fs)) - { + using(FileStream fs = new FileStream(indexloc, FileMode.Open)) { + using(StreamReader reader = new StreamReader(fs)) { String line = ""; - while((line = reader.ReadLine()) != null) - { - if (GetParent().DiscordPath.Contains("Discord\\")) - { - if (line.Contains("var _discord_overlay2")) - { - lines.Add(line); - lines.Add("var _betterDiscord = require('betterdiscord');"); - } - else if (line.Contains("mainWindow = new _electron.BrowserWindow")) - { - lines.Add(line); - lines.Add(File.ReadAllText("splice")); - } - else - { - lines.Add(line); - } - } - if (GetParent().DiscordPath.Contains("DiscordCanary\\")) - { - if (line.Contains("var _discord_overlay2")) - { - lines.Add(line); - lines.Add("var _betterDiscord = require('betterdiscord');"); - } - else if (line.Contains("mainWindow = new _BrowserWindow2")) - { - lines.Add(line); - lines.Add(File.ReadAllText("splice")); - } - else - { - lines.Add(line); - } - } - if (GetParent().DiscordPath.Contains("DiscordPTB\\")) - { - if (line.Contains("var _discord_overlay2")) - { - lines.Add(line); - lines.Add("var _betterDiscord = require('betterdiscord');"); - } - //"mainWindow = new _browserWindow2" was changed in DiscordPTB v0.0.6 - else if (line.Contains("mainWindow = new _electron.BrowserWindow")) - { - lines.Add(line); - lines.Add(File.ReadAllText("splice")); - } - else - { - lines.Add(line); - } + while((line = reader.ReadLine()) != null) { + //if(GetParent().DiscordPath.Contains("Discord\\")) { + //if(GetParent().DiscordPath.Contains("DiscordCanary\\")) { + //if(GetParent().DiscordPath.Contains("DiscordPTB\\")) { + if(line.Replace(" ", "").Contains("var_fs=")) { + lines.Add(line); + lines.Add("var _betterDiscord = require('betterdiscord');"); + } else if(line.Replace(" ", "").Contains("mainWindow=new")) { + lines.Add(line); + lines.Add(File.ReadAllText("splice")); + } else { + lines.Add(line); } + //} } } } @@ -283,33 +203,30 @@ namespace BetterDiscordWI.panels File.WriteAllLines(indexloc, lines.ToArray()); - + AppendLog("Finished installation, verifying installation..."); int errors = 0; String curPath = GetParent().DiscordPath + "\\resources\\app\\app\\index.js"; - - if (!File.Exists(curPath)) - { + + if(!File.Exists(curPath)) { AppendLog("ERROR: FILE: " + curPath + " DOES NOT EXIST!"); errors++; } curPath = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord"; - if (!Directory.Exists(curPath)) - { + if(!Directory.Exists(curPath)) { 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[] 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))) - { + foreach(string s in bdFiles.Where(s => !File.Exists(basePath + s))) { AppendLog("ERROR: FILE: " + basePath + s + " DOES NOT EXIST"); errors++; } @@ -321,59 +238,48 @@ namespace BetterDiscordWI.panels t.Start(); } - private void Finalize(int errors) - { + private void Finalize(int errors) { AppendLog("Finished installing BetterDiscord with " + errors + " errors"); - Invoke((MethodInvoker) delegate - { + Invoke((MethodInvoker)delegate { GetParent().finished = true; GetParent().btnCancel.Text = "OK"; GetParent().btnCancel.Enabled = true; }); - if (GetParent().RestartDiscord) - { - if (GetParent().DiscordPath.Contains("\\Discord\\")) - { + if(GetParent().RestartDiscord) { + if(GetParent().DiscordPath.Contains("\\Discord\\")) { Process.Start(GetParent().DiscordPath + "\\Discord.exe"); } - if (GetParent().DiscordPath.Contains("\\DiscordCanary\\")) - { + if(GetParent().DiscordPath.Contains("\\DiscordCanary\\")) { Process.Start(GetParent().DiscordPath + "\\DiscordCanary.exe"); } - if (GetParent().DiscordPath.Contains("\\DiscordPTB\\")) - { + if(GetParent().DiscordPath.Contains("\\DiscordPTB\\")) { Process.Start(GetParent().DiscordPath + "\\DiscordPTB.exe"); } } } - public FormMain GetParent() - { + public FormMain GetParent() { return (FormMain)ParentForm; } - public void BtnNext() - { + public void BtnNext() { throw new NotImplementedException(); } - public void BtnPrev() - { + public void BtnPrev() { throw new NotImplementedException(); } - private void AppendLog(String message) - { - Invoke((MethodInvoker) delegate - { + private void AppendLog(String message) { + Invoke((MethodInvoker)delegate { rtLog.AppendText(message + "\n"); rtLog.SelectionStart = rtLog.Text.Length; rtLog.ScrollToCaret(); }); - + } } } diff --git a/WindowsInstaller/dlls/asardotnet.dll b/WindowsInstaller/dlls/asardotnet.dll index 0715832..baa83d4 100644 Binary files a/WindowsInstaller/dlls/asardotnet.dll and b/WindowsInstaller/dlls/asardotnet.dll differ