BetterDiscordApp-v1/WindowsInstaller/BetterDiscordWI/FormMain.cs

89 lines
2.6 KiB
C#
Raw Normal View History

2015-08-27 14:46:05 +02:00
using System;
using System.Drawing;
using System.Windows.Forms;
2015-12-04 02:17:37 +01:00
using System.Xml;
using BetterDiscordWI.panels;
2015-08-27 14:46:05 +02:00
namespace BetterDiscordWI
{
public partial class FormMain : Form
{
2015-12-04 02:17:37 +01:00
private readonly IPanel[] _panels = { new Panel0(), new Panel1(), new Panel2() };
private int _index;
public String DiscordPath;
public String Sha;
2015-12-05 02:15:00 +01:00
public Boolean finished = false;
2015-12-04 02:17:37 +01:00
public XmlNodeList ResourceList;
2015-08-27 14:46:05 +02:00
public FormMain()
{
InitializeComponent();
2015-12-04 02:17:37 +01:00
Sha = Utils.GetHash();
if (Sha.Length < 1)
{
MessageBox.Show("Failed to get sha", "Error", MessageBoxButtons.OK);
Environment.Exit(0);
}
foreach (IPanel ipanel in _panels)
{
panelContainer.Controls.Add((UserControl)ipanel);
((UserControl)ipanel).Dock = DockStyle.Fill;
((UserControl)ipanel).Hide();
}
((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)
{
((UserControl)_panels[_index]).Hide();
_index = index;
((UserControl)_panels[_index]).Show();
_panels[_index].SetVisible();
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
2015-12-05 02:15:00 +01:00
if (!finished)
2015-12-04 02:17:37 +01:00
{
2015-12-05 02:15:00 +01:00
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;
}
2015-12-04 02:17:37 +01:00
}
}
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.DrawLine(SystemPens.Window, 0, 51, Width, 51);
g.DrawLine(borderPen, 0, 310, Width, 310);
g.DrawLine(SystemPens.Window, 0, 311, Width, 311);
base.OnPaint(e);
2015-08-27 14:46:05 +02:00
}
}
}