cemu-DS4Windows/DS4Windows/DS4Forms/WelcomeDialog.cs

108 lines
3.5 KiB
C#
Raw Normal View History

using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.IO.Compression;
using System.Diagnostics;
2018-01-31 07:04:56 +01:00
//using NonFormTimer = System.Threading.Timer;
using NonFormTimer = System.Timers.Timer;
using System.Threading.Tasks;
using static DS4Windows.Global;
2019-04-30 21:29:50 +02:00
namespace DS4Windows.Forms
{
public partial class WelcomeDialog : Form
{
2019-04-23 00:26:51 +02:00
private const string InstallerDL =
"https://github.com/ViGEm/ViGEmBus/releases/download/v1.16.112/ViGEmBus_Setup_1.16.112.exe";
private const string InstFileName = "ViGEmBus_Setup_1.16.112.exe";
public WelcomeDialog(bool loadConfig=false)
{
if (loadConfig)
{
Global.FindConfigLocation();
Global.Load();
Global.SetCulture(Global.UseLang);
}
InitializeComponent();
Icon = Properties.Resources.DS4;
}
private void bnFinish_Click(object sender, EventArgs e)
{
this.Close();
}
private void linkBluetoothSettings_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("control", "bthprops.cpl");
}
private void bnStep1_Click(object sender, EventArgs e)
{
2019-04-23 00:26:51 +02:00
if (File.Exists(exepath + $"\\{InstFileName}"))
{
File.Delete(exepath + $"\\{InstFileName}");
}
WebClient wb = new WebClient();
2019-04-23 00:26:51 +02:00
wb.DownloadFileAsync(new Uri(InstallerDL), exepath + $"\\{InstFileName}");
wb.DownloadProgressChanged += wb_DownloadProgressChanged;
wb.DownloadFileCompleted += wb_DownloadFileCompleted;
}
private void wb_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
bnStep1.Text = Properties.Resources.Downloading.Replace("*number*", e.ProgressPercentage.ToString());
}
private void wb_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (Directory.Exists(exepath + "\\ViGEmBusInstaller"))
{
Directory.Delete(exepath + "\\ViGEmBusInstaller", true);
}
2019-04-23 00:26:51 +02:00
if (File.Exists(exepath + $"\\{InstFileName}"))
{
bnStep1.Text = Properties.Resources.OpeningInstaller;
2019-04-23 00:26:51 +02:00
Process.Start(exepath + $"\\{InstFileName}", "/quiet");
bnStep1.Text = Properties.Resources.Installing;
}
2018-01-31 07:04:56 +01:00
NonFormTimer timer = new NonFormTimer();
timer.Elapsed += timer_Tick;
timer.Start();
}
2018-01-31 07:04:56 +01:00
private void timer_Tick(object sender, EventArgs e)
{
2019-04-23 00:26:51 +02:00
Process[] processes = Process.GetProcessesByName("ViGEmBus_Setup_1.16.112");
if (processes.Length < 1)
{
if (Global.IsViGEmBusInstalled())
{
2018-01-31 07:04:56 +01:00
this.BeginInvoke((Action)(() => { bnStep1.Text = Properties.Resources.InstallComplete; }));
}
else
{
this.BeginInvoke((Action)(() => { bnStep1.Text = Properties.Resources.InstallFailed; }), null);
}
2018-01-31 07:04:56 +01:00
2019-04-23 00:26:51 +02:00
File.Delete(exepath + $"\\{InstFileName}");
2018-02-04 21:18:49 +01:00
((NonFormTimer)sender).Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
Process.Start("http://www.microsoft.com/accessories/en-gb/d/xbox-360-controller-for-windows");
}
}
}