BetterDiscordApp-v2/Installers/dotNet/BetterDiscordWI/panels/Panel1.cs

90 lines
2.8 KiB
C#
Raw Normal View History

2015-12-04 02:17:37 +01:00
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace BetterDiscordWI.panels {
public partial class Panel1: UserControl, IPanel {
public Panel1() {
2015-12-04 02:17:37 +01:00
InitializeComponent();
}
public void SetVisible() {
2015-12-04 02:17:37 +01:00
GetParent().btnBack.Visible = true;
GetParent().btnNext.Enabled = true;
GetParent().btnBack.Enabled = true;
2016-05-06 21:03:17 +02:00
GetParent().btnNext.Text = @"Install";
GetParent().lblPanelTitle.Text = @"BetterDiscord Installation";
2015-12-04 02:17:37 +01:00
2016-05-06 21:03:17 +02:00
PickVersion();
2015-12-04 02:17:37 +01:00
}
public FormMain GetParent() {
return (FormMain)ParentForm;
2015-12-04 02:17:37 +01:00
}
public void BtnNext() {
2015-12-04 02:17:37 +01:00
GetParent().DiscordPath = tbPath.Text;
2015-12-18 17:00:52 +01:00
GetParent().RestartDiscord = cbRestart.Checked;
2015-12-04 02:17:37 +01:00
GetParent().SwitchPanel(2);
}
public void BtnPrev() {
2015-12-04 02:17:37 +01:00
GetParent().SwitchPanel(0);
}
private void btnBrowser_Click(object sender, EventArgs e) {
FolderBrowserDialog fbd = new FolderBrowserDialog { SelectedPath = tbPath.Text };
2015-12-04 02:17:37 +01:00
fbd.ShowDialog(GetParent());
tbPath.Text = fbd.SelectedPath;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e) {
2016-05-06 21:03:17 +02:00
PickVersion();
}
private void checkBox2_CheckedChanged(object sender, EventArgs e) {
2016-05-06 21:03:17 +02:00
PickVersion();
}
2016-05-06 21:03:17 +02:00
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;
2016-05-06 21:03:17 +02:00
} else if(checkBox2.Checked) {
dirPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\DiscordPTB";
if(!Directory.Exists(dirPath)) checkBox2.Checked = false;
checkBox1.Checked = false;
} else {
2016-05-06 21:03:17 +02:00
dirPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Discord";
}
2016-05-06 21:03:17 +02:00
if (!Directory.Exists(dirPath)) return;
string[] directories = Directory.GetDirectories(dirPath);
2016-05-06 21:03:17 +02:00
string highestVersion = null;
2016-05-06 21:03:17 +02:00
foreach(string s in directories) {
Debug.Print(s);
if(!s.Contains("app-"))
continue;
if(string.IsNullOrEmpty(highestVersion)) {
highestVersion = s;
continue;
}
2016-05-06 21:03:17 +02:00
if(string.CompareOrdinal(s, highestVersion) > 0) {
highestVersion = s;
}
}
2016-05-06 21:03:17 +02:00
tbPath.Text = highestVersion;
}
2015-12-04 02:17:37 +01:00
}
2016-05-06 21:03:17 +02:00
}