Changed Welcome dialog to account for ViGEmBus installer program

This commit is contained in:
Travis Nickles 2019-03-19 00:47:26 -05:00
parent 94eff31290
commit fb73c19574
2 changed files with 29 additions and 67 deletions

View File

@ -37,17 +37,14 @@ namespace DS4Windows
{ {
Process.Start("control", "bthprops.cpl"); Process.Start("control", "bthprops.cpl");
} }
bool driverinstalling = false;
private void bnStep1_Click(object sender, EventArgs e) private void bnStep1_Click(object sender, EventArgs e)
{ {
WebClient wb = new WebClient(); WebClient wb = new WebClient();
if (!driverinstalling) wb.DownloadFileAsync(new Uri("https://github.com/Ryochan7/DS4Windows/raw/jay/extras/ViGEmBusInstaller_DS4Win.zip"),
{ exepath + "\\ViGEmBusInstaller_DS4Win.zip");
wb.DownloadFileAsync(new Uri("https://github.com/Ryochan7/DS4Windows/raw/jay/extras/Virtual Bus Driver.zip"), exepath + "\\VBus.zip");
wb.DownloadProgressChanged += wb_DownloadProgressChanged; wb.DownloadProgressChanged += wb_DownloadProgressChanged;
wb.DownloadFileCompleted += wb_DownloadFileCompleted; wb.DownloadFileCompleted += wb_DownloadFileCompleted;
driverinstalling = true;
}
} }
private void wb_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) private void wb_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
@ -57,82 +54,47 @@ namespace DS4Windows
private void wb_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) private void wb_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{ {
bnStep1.Text = Properties.Resources.OpeningInstaller; if (Directory.Exists(exepath + "\\ViGEmBusInstaller"))
try
{ {
File.Delete(exepath + "\\ScpDriver.exe"); Directory.Delete(exepath + "\\ViGEmBusInstaller", true);
File.Delete(exepath + "\\ScpDriver.log");
Directory.Delete(exepath + "\\System", true);
Directory.Delete(exepath + "\\DIFxAPI", true);
} }
catch { }
Directory.CreateDirectory(exepath + "\\Virtual Bus Driver"); if (File.Exists(exepath + "\\ViGEmBusInstaller_DS4Win.zip"))
try { ZipFile.ExtractToDirectory(exepath + "\\VBus.zip", exepath + "\\Virtual Bus Driver"); } //Saved so the user can uninstall later
catch { }
try { ZipFile.ExtractToDirectory(exepath + "\\VBus.zip", exepath); }
//Made here as starting the scpdriver.exe via process.start, the program looks for file from where it was called, not where the exe is
catch { }
if (File.Exists(exepath + "\\ScpDriver.exe"))
try
{ {
Process.Start(exepath + "\\ScpDriver.exe", "si"); Directory.CreateDirectory(exepath + "\\ViGEmBusInstaller");
try { ZipFile.ExtractToDirectory(exepath + "\\ViGEmBusInstaller_DS4Win.zip",
exepath + "\\ViGEmBusInstaller"); } //Saved so the user can uninstall later
catch { }
}
if (File.Exists(exepath + "\\ViGEmBusInstaller\\ViGEmBusInstaller.exe"))
{
bnStep1.Text = Properties.Resources.OpeningInstaller;
Process.Start(exepath + "\\ViGEmBusInstaller\\ViGEmBusInstaller.exe", "--silent");
bnStep1.Text = Properties.Resources.Installing; bnStep1.Text = Properties.Resources.Installing;
} }
catch { Process.Start(exepath + "\\Virtual Bus Driver"); }
/*Timer timer = new Timer();
timer.Start();
timer.Tick += timer_Tick;
*/
NonFormTimer timer = new NonFormTimer(); NonFormTimer timer = new NonFormTimer();
timer.Elapsed += timer_Tick; timer.Elapsed += timer_Tick;
timer.Start(); timer.Start();
} }
bool waitForFile;
DateTime waitFileCheck;
private void timer_Tick(object sender, EventArgs e) private void timer_Tick(object sender, EventArgs e)
{ {
Process[] processes = Process.GetProcessesByName("ScpDriver"); Process[] processes = Process.GetProcessesByName("ViGEmBusInstaller");
if (processes.Length < 1) if (processes.Length < 1)
{ {
if (!File.Exists(exepath + "\\ScpDriver.log") && !waitForFile) if (Global.IsScpVBusInstalled())
{ {
waitForFile = true;
waitFileCheck = DateTime.UtcNow;
return;
}
if (waitForFile && waitFileCheck + TimeSpan.FromMinutes(2) < DateTime.UtcNow)
{
Process.Start(exepath + "\\Virtual Bus Driver");
File.Delete(exepath + "\\VBus.zip");
((NonFormTimer)sender).Stop();
this.BeginInvoke((Action)(() => { bnStep1.Text = Properties.Resources.InstallFailed; }), null);
return;
}
else if (waitForFile)
return;
string log = File.ReadAllText(exepath + "\\ScpDriver.log");
if (log.Contains("Install Succeeded"))
this.BeginInvoke((Action)(() => { bnStep1.Text = Properties.Resources.InstallComplete; })); this.BeginInvoke((Action)(() => { bnStep1.Text = Properties.Resources.InstallComplete; }));
}
else else
{ {
this.BeginInvoke((Action)(() => { bnStep1.Text = Properties.Resources.InstallFailed; })); this.BeginInvoke((Action)(() => { bnStep1.Text = Properties.Resources.InstallFailed; }), null);
Process.Start(exepath + "\\Virtual Bus Driver");
} }
try
{
File.Delete(exepath + "\\ScpDriver.exe");
File.Delete(exepath + "\\ScpDriver.log");
Directory.Delete(exepath + "\\System", true);
Directory.Delete(exepath + "\\DIFxAPI", true);
}
catch { }
File.Delete(exepath + "\\VBus.zip"); File.Delete(exepath + "\\ViGEmBusInstaller_DS4Win.zip");
((NonFormTimer)sender).Stop(); ((NonFormTimer)sender).Stop();
} }
} }

View File

@ -129,7 +129,7 @@
<value>1</value> <value>1</value>
</data> </data>
<data name="bnStep1.Text" xml:space="preserve"> <data name="bnStep1.Text" xml:space="preserve">
<value>Step 1: Install the ScpVBus Driver</value> <value>Step 1: Install the ViGEmBus Driver</value>
</data> </data>
<data name="&gt;&gt;bnStep1.Name" xml:space="preserve"> <data name="&gt;&gt;bnStep1.Name" xml:space="preserve">
<value>bnStep1</value> <value>bnStep1</value>