Merge pull request #184 from iVEnoVaLue/master
Fixed installer for Discord, PTB, Canary
This commit is contained in:
commit
f62b53866d
|
@ -31,11 +31,11 @@
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
this.btnBrowser = new System.Windows.Forms.Button();
|
this.btnBrowser = new System.Windows.Forms.Button();
|
||||||
this.label2 = new System.Windows.Forms.Label();
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
this.tbPath = new BetterDiscordWI.components.CTextBox();
|
|
||||||
this.label3 = new System.Windows.Forms.Label();
|
this.label3 = new System.Windows.Forms.Label();
|
||||||
this.cbRestart = new System.Windows.Forms.CheckBox();
|
this.cbRestart = new System.Windows.Forms.CheckBox();
|
||||||
this.checkBox1 = new System.Windows.Forms.CheckBox();
|
this.checkBox1 = new System.Windows.Forms.CheckBox();
|
||||||
this.checkBox2 = new System.Windows.Forms.CheckBox();
|
this.checkBox2 = new System.Windows.Forms.CheckBox();
|
||||||
|
this.tbPath = new BetterDiscordWI.components.CTextBox();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
|
@ -67,15 +67,6 @@
|
||||||
this.label2.TabIndex = 3;
|
this.label2.TabIndex = 3;
|
||||||
this.label2.Text = "*If the path is not pointing to the latest version of Discord then click browse a" +
|
this.label2.Text = "*If the path is not pointing to the latest version of Discord then click browse a" +
|
||||||
"nd select it.";
|
"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
|
// label3
|
||||||
//
|
//
|
||||||
|
@ -119,6 +110,15 @@
|
||||||
this.checkBox2.UseVisualStyleBackColor = true;
|
this.checkBox2.UseVisualStyleBackColor = true;
|
||||||
this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
|
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
|
// Panel1
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
|
|
@ -3,17 +3,13 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace BetterDiscordWI.panels
|
namespace BetterDiscordWI.panels {
|
||||||
{
|
public partial class Panel1: UserControl, IPanel {
|
||||||
public partial class Panel1 : UserControl, IPanel
|
public Panel1() {
|
||||||
{
|
|
||||||
public Panel1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVisible()
|
public void SetVisible() {
|
||||||
{
|
|
||||||
|
|
||||||
GetParent().btnBack.Visible = true;
|
GetParent().btnBack.Visible = true;
|
||||||
GetParent().btnNext.Enabled = true;
|
GetParent().btnNext.Enabled = true;
|
||||||
|
@ -21,134 +17,69 @@ namespace BetterDiscordWI.panels
|
||||||
GetParent().btnNext.Text = "Install";
|
GetParent().btnNext.Text = "Install";
|
||||||
GetParent().lblPanelTitle.Text = "BetterDiscord Installation";
|
GetParent().lblPanelTitle.Text = "BetterDiscord Installation";
|
||||||
|
|
||||||
String[] directories = Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Discord");
|
pickVersion();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormMain GetParent()
|
public FormMain GetParent() {
|
||||||
{
|
return (FormMain)ParentForm;
|
||||||
return (FormMain) ParentForm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BtnNext()
|
public void BtnNext() {
|
||||||
{
|
|
||||||
GetParent().DiscordPath = tbPath.Text;
|
GetParent().DiscordPath = tbPath.Text;
|
||||||
GetParent().RestartDiscord = cbRestart.Checked;
|
GetParent().RestartDiscord = cbRestart.Checked;
|
||||||
GetParent().SwitchPanel(2);
|
GetParent().SwitchPanel(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BtnPrev()
|
public void BtnPrev() {
|
||||||
{
|
|
||||||
GetParent().SwitchPanel(0);
|
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 };
|
||||||
FolderBrowserDialog fbd = new FolderBrowserDialog {SelectedPath = tbPath.Text};
|
|
||||||
fbd.ShowDialog(GetParent());
|
fbd.ShowDialog(GetParent());
|
||||||
|
|
||||||
tbPath.Text = fbd.SelectedPath;
|
tbPath.Text = fbd.SelectedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBox1_CheckedChanged(object sender, EventArgs e)
|
private void checkBox1_CheckedChanged(object sender, EventArgs e) {
|
||||||
{
|
pickVersion();
|
||||||
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 checkBox2_CheckedChanged(object sender, EventArgs e)
|
private void checkBox2_CheckedChanged(object sender, EventArgs e) {
|
||||||
{
|
pickVersion();
|
||||||
if (checkBox2.Checked == true)
|
}
|
||||||
{
|
|
||||||
|
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;
|
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;
|
String highestVersion = null;
|
||||||
|
|
||||||
foreach (String s in directories)
|
foreach(String s in directories) {
|
||||||
{
|
|
||||||
Debug.Print(s);
|
Debug.Print(s);
|
||||||
if (!s.Contains("app-")) continue;
|
if(!s.Contains("app-"))
|
||||||
if (String.IsNullOrEmpty(highestVersion))
|
continue;
|
||||||
{
|
if(String.IsNullOrEmpty(highestVersion)) {
|
||||||
highestVersion = s;
|
highestVersion = s;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String.CompareOrdinal(s, highestVersion) > 0)
|
if(String.CompareOrdinal(s, highestVersion) > 0) {
|
||||||
{
|
|
||||||
highestVersion = s;
|
highestVersion = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,34 +87,6 @@ namespace BetterDiscordWI.panels
|
||||||
|
|
||||||
tbPath.Text = highestVersion;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,20 +9,16 @@ using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using asardotnet;
|
using asardotnet;
|
||||||
|
|
||||||
namespace BetterDiscordWI.panels
|
namespace BetterDiscordWI.panels {
|
||||||
{
|
public partial class Panel2: UserControl, IPanel {
|
||||||
public partial class Panel2 : UserControl, IPanel
|
|
||||||
{
|
|
||||||
private String _dataPath, _tempPath;
|
private String _dataPath, _tempPath;
|
||||||
private Utils _utils;
|
private Utils _utils;
|
||||||
|
|
||||||
public Panel2()
|
public Panel2() {
|
||||||
{
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVisible()
|
public void SetVisible() {
|
||||||
{
|
|
||||||
GetParent().btnBack.Enabled = false;
|
GetParent().btnBack.Enabled = false;
|
||||||
GetParent().btnNext.Enabled = false;
|
GetParent().btnNext.Enabled = false;
|
||||||
GetParent().btnBack.Visible = false;
|
GetParent().btnBack.Visible = false;
|
||||||
|
@ -30,74 +26,56 @@ namespace BetterDiscordWI.panels
|
||||||
GetParent().btnCancel.Enabled = false;
|
GetParent().btnCancel.Enabled = false;
|
||||||
|
|
||||||
_utils = new Utils();
|
_utils = new Utils();
|
||||||
if (GetParent().DiscordPath.Contains("Discord\\"))
|
|
||||||
{
|
KillProcessIfInstalling("Discord");
|
||||||
AppendLog("Killing Discord");
|
KillProcessIfInstalling("DiscordCanary");
|
||||||
foreach (var process in Process.GetProcessesByName("Discord"))
|
KillProcessIfInstalling("DiscordPTB");
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateDirectories();
|
CreateDirectories();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateDirectories()
|
private void KillProcessIfInstalling(string app) {
|
||||||
{
|
if(GetParent().DiscordPath.Contains(app + "\\")) {
|
||||||
Thread t = new Thread(() =>
|
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";
|
_dataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord";
|
||||||
_tempPath = _dataPath + "\\temp";
|
_tempPath = _dataPath + "\\temp";
|
||||||
AppendLog("Deleting old cached files");
|
AppendLog("Deleting old cached files");
|
||||||
try
|
try {
|
||||||
{
|
if(File.Exists(_dataPath + "\\emotes_bttv.json")) {
|
||||||
if (File.Exists(_dataPath + "\\emotes_bttv.json"))
|
|
||||||
{
|
|
||||||
File.Delete(_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");
|
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");
|
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");
|
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");
|
File.Delete(_dataPath + "\\emotes_twitch_subscriber.json");
|
||||||
}
|
}
|
||||||
if (File.Exists(_dataPath + "\\user.json")) {
|
if(File.Exists(_dataPath + "\\user.json")) {
|
||||||
File.Delete(_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");
|
AppendLog("Deleting temp path");
|
||||||
Directory.Delete(_tempPath, true);
|
Directory.Delete(_tempPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (Directory.Exists(_tempPath))
|
while(Directory.Exists(_tempPath)) {
|
||||||
{
|
|
||||||
Debug.Print("Waiting for dirdel");
|
Debug.Print("Waiting for dirdel");
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
|
@ -106,8 +84,7 @@ namespace BetterDiscordWI.panels
|
||||||
|
|
||||||
DownloadResource("BetterDiscord.zip", "https://github.com/Jiiks/BetterDiscordApp/archive/stable.zip");
|
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");
|
Debug.Print("Waiting for download");
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
|
@ -127,30 +104,23 @@ namespace BetterDiscordWI.panels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void DeleteDirs()
|
private void DeleteDirs() {
|
||||||
{
|
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
Thread t = new Thread(() =>
|
Thread t = new Thread(() => {
|
||||||
{
|
|
||||||
String dir = GetParent().DiscordPath + "\\resources\\app";
|
String dir = GetParent().DiscordPath + "\\resources\\app";
|
||||||
|
|
||||||
if (Directory.Exists(dir))
|
if(Directory.Exists(dir)) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
AppendLog("Deleting " + dir);
|
AppendLog("Deleting " + dir);
|
||||||
Directory.Delete(dir, true);
|
Directory.Delete(dir, true);
|
||||||
}
|
} catch {
|
||||||
catch
|
AppendLog("Error: Failed to Delete the '" + dir + "\\resources\\app' Directory.");
|
||||||
{
|
|
||||||
AppendLog("Error Failed to Delete the '" + dir + "\\resources\\app' Directory.");
|
|
||||||
errors = 1;
|
errors = 1;
|
||||||
Finalize(errors);
|
Finalize(errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (Directory.Exists(dir))
|
while(Directory.Exists(dir)) {
|
||||||
{
|
|
||||||
Debug.Print("Waiting for direl");
|
Debug.Print("Waiting for direl");
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
|
@ -158,123 +128,80 @@ namespace BetterDiscordWI.panels
|
||||||
dir = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord";
|
dir = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord";
|
||||||
|
|
||||||
|
|
||||||
if (Directory.Exists(dir))
|
if(Directory.Exists(dir)) {
|
||||||
{
|
|
||||||
AppendLog("Deleting " + dir);
|
AppendLog("Deleting " + dir);
|
||||||
Directory.Delete(dir, true);
|
Directory.Delete(dir, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (Directory.Exists(dir))
|
while(Directory.Exists(dir)) {
|
||||||
{
|
|
||||||
Debug.Print("Waiting for direl");
|
Debug.Print("Waiting for direl");
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendLog("Moving BetterDiscord to resources\\node_modules\\");
|
AppendLog("Extracting app.asar");
|
||||||
|
string appAsarPath = GetParent().DiscordPath + "\\resources\\app.asar";
|
||||||
|
|
||||||
Directory.Move(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord\\temp\\BetterDiscordApp-stable", GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord");
|
if(File.Exists(appAsarPath)) {
|
||||||
|
AsarArchive archive = new AsarArchive(appAsarPath);
|
||||||
|
AsarExtractor extractor = new AsarExtractor();
|
||||||
|
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;
|
||||||
|
Finalize(errors);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
if(errors == 0) {
|
||||||
{
|
AppendLog("Moving BetterDiscord to resources\\node_modules\\");
|
||||||
AppendLog("Extracting app.asar");
|
Directory.Move(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BetterDiscord\\temp\\BetterDiscordApp-stable", GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord");
|
||||||
AsarArchive archive = new AsarArchive(GetParent().DiscordPath + "\\resources\\app.asar");
|
|
||||||
|
|
||||||
AsarExtractor extractor = new AsarExtractor();
|
try {
|
||||||
//Add extraoffset of 3
|
Splice();
|
||||||
extractor.ExtractAll(archive, GetParent().DiscordPath + "\\resources\\app\\", 3);
|
} catch {
|
||||||
|
AppendLog("Error: Extracting app.asar: Newtonsoft.Json.dll might not be present in the Installer Folder. Installation cannot Continue.");
|
||||||
Splice();
|
errors = 1;
|
||||||
}
|
Finalize(errors);
|
||||||
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();
|
t.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void DownloadResource(String resource, String url)
|
private void DownloadResource(String resource, String url) {
|
||||||
{
|
|
||||||
AppendLog("Downloading Resource: " + resource);
|
AppendLog("Downloading Resource: " + resource);
|
||||||
|
|
||||||
WebClient webClient = new WebClient();
|
WebClient webClient = new WebClient();
|
||||||
webClient.Headers["User-Agent"] = "Mozilla/5.0";
|
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()
|
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(() =>
|
Thread t = new Thread(() => {
|
||||||
{
|
|
||||||
List<String> lines = new List<string>();
|
List<String> lines = new List<string>();
|
||||||
AppendLog("Spicing index");
|
AppendLog("Spicing index");
|
||||||
using (FileStream fs = new FileStream(indexloc, FileMode.Open))
|
using(FileStream fs = new FileStream(indexloc, FileMode.Open)) {
|
||||||
{
|
using(StreamReader reader = new StreamReader(fs)) {
|
||||||
using (StreamReader reader = new StreamReader(fs))
|
|
||||||
{
|
|
||||||
String line = "";
|
String line = "";
|
||||||
while((line = reader.ReadLine()) != null)
|
while((line = reader.ReadLine()) != null) {
|
||||||
{
|
//if(GetParent().DiscordPath.Contains("Discord\\")) {
|
||||||
if (GetParent().DiscordPath.Contains("Discord\\"))
|
//if(GetParent().DiscordPath.Contains("DiscordCanary\\")) {
|
||||||
{
|
//if(GetParent().DiscordPath.Contains("DiscordPTB\\")) {
|
||||||
if (line.Contains("var _discord_overlay2"))
|
if(line.Replace(" ", "").Contains("var_fs=")) {
|
||||||
{
|
lines.Add(line);
|
||||||
lines.Add(line);
|
lines.Add("var _betterDiscord = require('betterdiscord');");
|
||||||
lines.Add("var _betterDiscord = require('betterdiscord');");
|
} else if(line.Replace(" ", "").Contains("mainWindow=new")) {
|
||||||
}
|
lines.Add(line);
|
||||||
else if (line.Contains("mainWindow = new _electron.BrowserWindow"))
|
lines.Add(File.ReadAllText("splice"));
|
||||||
{
|
} else {
|
||||||
lines.Add(line);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,33 +210,30 @@ namespace BetterDiscordWI.panels
|
||||||
|
|
||||||
File.WriteAllLines(indexloc, lines.ToArray());
|
File.WriteAllLines(indexloc, lines.ToArray());
|
||||||
|
|
||||||
|
|
||||||
AppendLog("Finished installation, verifying installation...");
|
AppendLog("Finished installation, verifying installation...");
|
||||||
|
|
||||||
int errors = 0;
|
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))
|
if(!File.Exists(curPath)) {
|
||||||
{
|
|
||||||
AppendLog("ERROR: FILE: " + curPath + " DOES NOT EXIST!");
|
AppendLog("ERROR: FILE: " + curPath + " DOES NOT EXIST!");
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
curPath = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord";
|
curPath = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord";
|
||||||
|
|
||||||
if (!Directory.Exists(curPath))
|
if(!Directory.Exists(curPath)) {
|
||||||
{
|
|
||||||
AppendLog("ERROR: DIRECTORY: " + curPath + " DOES NOT EXIST");
|
AppendLog("ERROR: DIRECTORY: " + curPath + " DOES NOT EXIST");
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String basePath = GetParent().DiscordPath + "\\resources\\node_modules\\BetterDiscord";
|
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");
|
AppendLog("ERROR: FILE: " + basePath + s + " DOES NOT EXIST");
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
|
@ -321,59 +245,48 @@ namespace BetterDiscordWI.panels
|
||||||
t.Start();
|
t.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Finalize(int errors)
|
private void Finalize(int errors) {
|
||||||
{
|
|
||||||
AppendLog("Finished installing BetterDiscord with " + errors + " errors");
|
AppendLog("Finished installing BetterDiscord with " + errors + " errors");
|
||||||
|
|
||||||
|
|
||||||
Invoke((MethodInvoker) delegate
|
Invoke((MethodInvoker)delegate {
|
||||||
{
|
|
||||||
GetParent().finished = true;
|
GetParent().finished = true;
|
||||||
GetParent().btnCancel.Text = "OK";
|
GetParent().btnCancel.Text = "OK";
|
||||||
GetParent().btnCancel.Enabled = true;
|
GetParent().btnCancel.Enabled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (GetParent().RestartDiscord)
|
if(GetParent().RestartDiscord) {
|
||||||
{
|
if(GetParent().DiscordPath.Contains("\\Discord\\")) {
|
||||||
if (GetParent().DiscordPath.Contains("\\Discord\\"))
|
|
||||||
{
|
|
||||||
Process.Start(GetParent().DiscordPath + "\\Discord.exe");
|
Process.Start(GetParent().DiscordPath + "\\Discord.exe");
|
||||||
}
|
}
|
||||||
if (GetParent().DiscordPath.Contains("\\DiscordCanary\\"))
|
if(GetParent().DiscordPath.Contains("\\DiscordCanary\\")) {
|
||||||
{
|
|
||||||
Process.Start(GetParent().DiscordPath + "\\DiscordCanary.exe");
|
Process.Start(GetParent().DiscordPath + "\\DiscordCanary.exe");
|
||||||
}
|
}
|
||||||
if (GetParent().DiscordPath.Contains("\\DiscordPTB\\"))
|
if(GetParent().DiscordPath.Contains("\\DiscordPTB\\")) {
|
||||||
{
|
|
||||||
Process.Start(GetParent().DiscordPath + "\\DiscordPTB.exe");
|
Process.Start(GetParent().DiscordPath + "\\DiscordPTB.exe");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormMain GetParent()
|
public FormMain GetParent() {
|
||||||
{
|
|
||||||
return (FormMain)ParentForm;
|
return (FormMain)ParentForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BtnNext()
|
public void BtnNext() {
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BtnPrev()
|
public void BtnPrev() {
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AppendLog(String message)
|
private void AppendLog(String message) {
|
||||||
{
|
Invoke((MethodInvoker)delegate {
|
||||||
Invoke((MethodInvoker) delegate
|
|
||||||
{
|
|
||||||
rtLog.AppendText(message + "\n");
|
rtLog.AppendText(message + "\n");
|
||||||
rtLog.SelectionStart = rtLog.Text.Length;
|
rtLog.SelectionStart = rtLog.Text.Length;
|
||||||
rtLog.ScrollToCaret();
|
rtLog.ScrollToCaret();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue