Skip to content

Commit

Permalink
Added HidHide installer to Welcome dialog window
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Apr 27, 2021
1 parent 40e26af commit 7d1984d
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 22 deletions.
57 changes: 35 additions & 22 deletions DS4Windows/DS4Forms/WelcomeDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DS4WinWPF.DS4Forms"
mc:Ignorable="d"
Title="Welcome to DS4Windows" Height="356.246" Width="418" MinWidth="418" MinHeight="440"
Title="Welcome to DS4Windows" Height="440" Width="418" MinWidth="500" MinHeight="500"
Style="{DynamicResource WindowStyle}">
<Window.Resources>
<Style TargetType="{x:Type Button}" x:Key="CommonMargin" BasedOn="{StaticResource {x:Type Button}}">
Expand All @@ -15,36 +15,49 @@
<Setter Property="Margin" Value="0,10,0,0" />
</Style>
</Window.Resources>
<DockPanel Margin="10,0">
<Button x:Name="vigemInstallBtn" Content="Step 1: Install ViGEmBus Driver" Style="{StaticResource CommonMargin}" DockPanel.Dock="Top" Click="VigemInstallBtn_Click" />
<TextBlock TextAlignment="Center" DockPanel.Dock="Top" TextWrapping="Wrap">
<TextBlock.Text>
If this window reappears after installing, you may need to reboot your PC.
</TextBlock.Text>
</TextBlock>
<Button x:Name="step2Btn" Content="Step 2: If on Windows 7, Install 360 Driver" Style="{StaticResource CommonMargin}" DockPanel.Dock="Top"
<ScrollViewer>
<DockPanel Margin="10,10,10,10" LastChildFill="False">
<Button x:Name="vigemInstallBtn" Content="Step 1: Install ViGEmBus Driver" Style="{StaticResource CommonMargin}" DockPanel.Dock="Top" Click="VigemInstallBtn_Click" />
<TextBlock TextAlignment="Center" DockPanel.Dock="Top" TextWrapping="Wrap">
<TextBlock.Text>
If this window reappears after installing, you may need to reboot your PC.
</TextBlock.Text>
</TextBlock>
<Button x:Name="step2Btn" Content="Step 2: If on Windows 7, Install 360 Driver" Style="{StaticResource CommonMargin}" DockPanel.Dock="Top"
Click="Step2Btn_Click" />
<TextBlock TextAlignment="Center" DockPanel.Dock="Top">
<TextBlock.Text>
If you've used a 360 controller on this PC, you can skip this step.
</TextBlock.Text>
</TextBlock>
<TextBlock TextWrapping="Wrap" TextAlignment="Center" Style="{StaticResource CommonMarginTxt}" DockPanel.Dock="Top">
<TextBlock TextAlignment="Center" DockPanel.Dock="Top">
<TextBlock.Text>
If you've used a 360 controller on this PC, you can skip this step.
</TextBlock.Text>
</TextBlock>
<TextBlock TextWrapping="Wrap" TextAlignment="Center" Style="{StaticResource CommonMarginTxt}" DockPanel.Dock="Top">
Step 3: Connecting the DualShock 4 controller.<LineBreak />
To setup wired/USB:<LineBreak />
Simply plug a micro-USB into your PC and DualShock 4.<LineBreak />
<LineBreak />
To setup Bluetooth (optional):
Hold the PS Button and Share for 3 seconds. The lightbar will begin to double flash.
</TextBlock>
<DockPanel Margin="0,10" DockPanel.Dock="Top">
<Button x:Name="finishedBtn" Content="Finished" HorizontalAlignment="Center" Padding="10,1" Style="{StaticResource CommonMargin}" Click="FinishedBtn_Click" DockPanel.Dock="Bottom" />
<TextBlock TextAlignment="Center" TextWrapping="Wrap" Style="{StaticResource CommonMarginTxt}" DockPanel.Dock="Bottom">
</TextBlock>
<DockPanel Margin="0,10" DockPanel.Dock="Top">
<TextBlock TextAlignment="Center" TextWrapping="Wrap" Style="{StaticResource CommonMarginTxt}" DockPanel.Dock="Bottom">
Once flashing go to your <Hyperlink x:Name="bluetoothSetLink" Click="BluetoothSetLink_Click" Foreground="{DynamicResource AccentColor}">Bluetooth Settings</Hyperlink> and
connect to "Wireless Controller". If asked, enter pair code 0000.
Once paired, you're ready. Have fun!
</TextBlock>
<Image Source="/DS4Windows;component/Resources/Pairmode.png" Height="80" DockPanel.Dock="Top" />
</TextBlock>
<Image Source="/DS4Windows;component/Resources/Pairmode.png" Height="80" DockPanel.Dock="Top" />
</DockPanel>

<StackPanel x:Name="step4HidHidePanel" DockPanel.Dock="Top" Margin="0,8,0,0">
<Button x:Name="hidHideInstallBtn" Content="(Optional) Step 4: Install HidHide Driver" Click="HidHideInstall_Click" />
<TextBlock TextWrapping="Wrap" TextAlignment="Center" Margin="0, 10, 0, 0">
<TextBlock.Text>
Use HidHide to configure and hide the input controller from other apps running on your system.
Some games require only one controller to be present or double input will cause problems in game.
</TextBlock.Text>
</TextBlock>
</StackPanel>

<Button x:Name="finishedBtn" Content="Finished" HorizontalAlignment="Center" Padding="10,1" Style="{StaticResource CommonMargin}" Click="FinishedBtn_Click" DockPanel.Dock="Bottom" />
</DockPanel>
</DockPanel>
</ScrollViewer>
</Window>
130 changes: 130 additions & 0 deletions DS4Windows/DS4Forms/WelcomeDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ public partial class WelcomeDialog : Window
private const string InstallerDLX86 =
"https://github.com/ViGEm/ViGEmBus/releases/download/setup-v1.17.333/ViGEmBusSetup_x86.msi";

private const string InstallerHidHideX64 = "https://github.com/ViGEm/HidHide/releases/download/v1.0.30.0/HidHideMSI.msi";

private const string InstFileName1_16 = "ViGEmBus_Setup_1.16.116.exe";
private const string InstFileNameX64 = "ViGEmBusSetup_x64.msi";
private const string InstFileNameX86 = "ViGEmBusSetup_x86.msi";
private string tempInstFileName;

private const string InstHidHideFileNameX64 = "HidHideMSI.msi";

// Default to latest known ViGEmBus installer
private string installDL = InstallerDLX64;
private string installFileName = InstFileNameX64;
Expand Down Expand Up @@ -62,6 +66,19 @@ public WelcomeDialog(bool loadConfig = false)
{
step2Btn.IsEnabled = false;
}

// HidHide only works on Windows 10 x64
if (!IsHidHideControlCompatible())
{
step4HidHidePanel.IsEnabled = false;
}
}

private bool IsHidHideControlCompatible()
{
// HidHide only works on Windows 10 x64
return DS4Windows.Global.IsWin10OrGreater() &&
Environment.Is64BitOperatingSystem;
}

private void FinishedBtn_Click(object sender, RoutedEventArgs e)
Expand All @@ -82,6 +99,7 @@ private void VigemInstallBtn_Click(object sender, RoutedEventArgs e)
}

vigemInstallBtn.IsEnabled = false;
step4HidHidePanel.IsEnabled = false;
ViGEmDownloadLaunch();

/*WebClient wb = new WebClient();
Expand Down Expand Up @@ -141,6 +159,7 @@ private async void ViGEmDownloadLaunch()
{
vigemInstallBtn.Content = Properties.Resources.InstallFailed;
vigemInstallBtn.IsEnabled = true;
step4HidHidePanel.IsEnabled = IsHidHideControlCompatible();
}
}

Expand All @@ -158,6 +177,7 @@ private void ViGEmInstallTimer_Tick(object sender, System.Timers.ElapsedEventArg
{
vigemInstallBtn.Content = Properties.Resources.InstallComplete;
vigemInstallBtn.IsEnabled = true;
step4HidHidePanel.IsEnabled = IsHidHideControlCompatible();
}));
}
else
Expand All @@ -166,6 +186,7 @@ private void ViGEmInstallTimer_Tick(object sender, System.Timers.ElapsedEventArg
{
vigemInstallBtn.Content = Properties.Resources.InstallFailed;
vigemInstallBtn.IsEnabled = true;
step4HidHidePanel.IsEnabled = IsHidHideControlCompatible();
}), null);
}

Expand All @@ -189,5 +210,114 @@ private void BluetoothSetLink_Click(object sender, RoutedEventArgs e)
{
Process.Start("control", "bthprops.cpl");
}

private void HidHideInstall_Click(object sender, RoutedEventArgs e)
{
if (File.Exists(DS4Windows.Global.exedirpath + $"\\{InstHidHideFileNameX64}"))
{
File.Delete(DS4Windows.Global.exedirpath + $"\\{InstHidHideFileNameX64}");
}

string tempInstHidFileName = DS4Windows.Global.exedirpath + $"\\{InstHidHideFileNameX64}.tmp";
if (File.Exists(tempInstHidFileName))
{
File.Delete(tempInstHidFileName);
}

vigemInstallBtn.IsEnabled = false;
step4HidHidePanel.IsEnabled = false;
HidHideDownloadLaunch();
}

private async void HidHideDownloadLaunch()
{
Progress<ICopyProgress> progress = new Progress<ICopyProgress>(x => // Please see "Notes on IProgress<T>"
{
// This is your progress event!
// It will fire on every buffer fill so don't do anything expensive.
// Writing to the console IS expensive, so don't do the following in practice...
hidHideInstallBtn.Content = Properties.Resources.Downloading.Replace("*number*%",
x.PercentComplete.ToString("P"));
//Console.WriteLine(x.PercentComplete.ToString("P"));
});

string tempInstHidFileName = DS4Windows.Global.exedirpath + $"\\{InstHidHideFileNameX64}.tmp";
string filename = DS4Windows.Global.exedirpath + $"\\{InstHidHideFileNameX64}";
bool success = false;
using (var downloadStream = new FileStream(tempInstHidFileName, FileMode.CreateNew))
{
HttpResponseMessage response = await App.requestClient.GetAsync(InstallerHidHideX64,
downloadStream, progress);
success = response.IsSuccessStatusCode;
}

if (success)
{
File.Move(tempInstHidFileName, filename);
}
success = false; // Reset for later check

if (File.Exists(DS4Windows.Global.exedirpath + $"\\{InstHidHideFileNameX64}"))
{
//vigemInstallBtn.Content = Properties.Resources.OpeningInstaller;
ProcessStartInfo startInfo = new ProcessStartInfo(DS4Windows.Global.exedirpath + $"\\{InstHidHideFileNameX64}");
startInfo.UseShellExecute = true; // Needed to run program as admin
monitorProc = Process.Start(startInfo);
hidHideInstallBtn.Content = Properties.Resources.Installing;
success = true;
}

if (success)
{
hidHideInstallBtn.IsEnabled = false;

monitorTimer = new NonFormTimer();
monitorTimer.Elapsed += HidHideInstallTimer_Elapsed;
monitorTimer.Start();
}
else
{
hidHideInstallBtn.Content = Properties.Resources.InstallFailed;
step4HidHidePanel.IsEnabled = IsHidHideControlCompatible();
vigemInstallBtn.IsEnabled = true;
}
}

private void HidHideInstallTimer_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
((NonFormTimer)sender).Stop();
bool finished = false;
if (monitorProc != null && monitorProc.HasExited)
{
if (DS4Windows.Global.IsHidHideInstalled())
{
Dispatcher.BeginInvoke((Action)(() =>
{
hidHideInstallBtn.Content = Properties.Resources.InstallComplete;
step4HidHidePanel.IsEnabled = true;
vigemInstallBtn.IsEnabled = true;
}));
}
else
{
Dispatcher.BeginInvoke((Action)(() =>
{
hidHideInstallBtn.Content = Properties.Resources.InstallFailed;
step4HidHidePanel.IsEnabled = true;
vigemInstallBtn.IsEnabled = true;
}), null);
}

File.Delete(DS4Windows.Global.exedirpath + $"\\{InstHidHideFileNameX64}");
((NonFormTimer)sender).Stop();
finished = true;
}

if (!finished)
{
((NonFormTimer)sender).Start();
}
}
}
}

0 comments on commit 7d1984d

Please sign in to comment.