Fixed installer for Discord, PTB, Canary

This commit is contained in:
ivenovalue 2016-02-11 17:09:56 +01:00
parent bcf4867474
commit 069fb6b05b
4 changed files with 129 additions and 320 deletions

View File

@ -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);

View File

@ -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,161 +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;
pickVersion();
}
if (String.CompareOrdinal(s, highestVersion) > 0)
{
highestVersion = s;
}
}
tbPath.Text = highestVersion;
}
public FormMain GetParent()
{
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)
{
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)
{
private void checkBox1_CheckedChanged(object sender, EventArgs e) {
pickVersion();
}
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;
String[] directories = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\DiscordCanary");
} else if(checkBox2.Checked == true) {
dirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\DiscordPTB";
if(!Directory.Exists(dirPath)) checkBox2.Checked = false;
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 checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked == true)
{
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)
{
highestVersion = s;
}
}
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)
{
if(String.CompareOrdinal(s, highestVersion) > 0) {
highestVersion = s;
}
}
@ -186,4 +90,3 @@ namespace BetterDiscordWI.panels
}
}
}
}

View File

@ -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,49 +26,33 @@ 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")) {
@ -90,14 +70,12 @@ namespace BetterDiscordWI.panels
} 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,19 +142,16 @@ 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);
@ -198,8 +163,7 @@ namespace BetterDiscordWI.panels
}
private void DownloadResource(String resource, String url)
{
private void DownloadResource(String resource, String url) {
AppendLog("Downloading Resource: " + resource);
WebClient webClient = new WebClient();
@ -208,73 +172,29 @@ namespace BetterDiscordWI.panels
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<String> lines = new List<string>();
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"))
{
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.Contains("mainWindow = new _electron.BrowserWindow"))
{
} else if(line.Replace(" ", "").Contains("mainWindow=new")) {
lines.Add(line);
lines.Add(File.ReadAllText("splice"));
}
else
{
} 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);
}
}
//}
}
}
}
@ -290,16 +210,14 @@ namespace BetterDiscordWI.panels
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++;
}
@ -308,8 +226,7 @@ namespace BetterDiscordWI.panels
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)))
{
foreach(string s in bdFiles.Where(s => !File.Exists(basePath + s))) {
AppendLog("ERROR: FILE: " + basePath + s + " DOES NOT EXIST");
errors++;
}
@ -321,54 +238,43 @@ 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();

Binary file not shown.