Skip to content

Commit

Permalink
Merge pull request #1747 from MoshiMoshi0/feature/razer-chroma-update
Browse files Browse the repository at this point in the history
Update Razer Chroma support
  • Loading branch information
simon-wh authored Oct 16, 2019
2 parents a54c633 + 040c0f3 commit 7b4a05f
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 125 deletions.
1 change: 1 addition & 0 deletions Project-Aurora/Project-Aurora/Project-Aurora.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,7 @@
<Compile Include="Utils\KeyUtils.cs" />
<Compile Include="Utils\MemoryReader.cs" />
<Compile Include="Utils\MemoryUtils.cs" />
<Compile Include="Utils\RazerChromaUtils.cs" />
<Compile Include="Utils\RunningProcessMonitor.cs" />
<Compile Include="Utils\SteamUtils.cs" />
<Compile Include="Utils\ThreadPriorityChanger.cs" />
Expand Down
Binary file modified Project-Aurora/Project-Aurora/RazerSdkWrapper.dll
Binary file not shown.
9 changes: 5 additions & 4 deletions Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,14 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Label Grid.Row="0" Grid.Column="0" Content="Supported Version:" Margin="5 0 5 0" Padding="0" VerticalAlignment="Center"/>
<Label Grid.Row="0" Grid.Column="1" Content="3.5.6" Padding="0" Margin="5 0 5 0" VerticalAlignment="Center"/>
<Button x:Name="razer_wrapper_install_button" Grid.Row="0" Grid.Column="2" Content="Install" Width="120" Margin="5 0 5 0" VerticalAlignment="Center" HorizontalAlignment="Left" Click="razer_wrapper_install_button_Click"/>
<Label Grid.Row="0" Grid.Column="0" Content="Supported Versions:" Margin="5 0 5 0" Padding="0" VerticalAlignment="Center"/>
<Label x:Name="razer_wrapper_supported_versions_label" Grid.Row="0" Grid.Column="1" Padding="0" Margin="5 0 5 0" VerticalAlignment="Center"/>
<Button x:Name="razer_wrapper_install_button" Grid.Row="0" Grid.Column="2" Content="Install" Width="75" Margin="5 0 5 0" VerticalAlignment="Center" HorizontalAlignment="Left" Click="razer_wrapper_install_button_Click"/>
<Button x:Name="razer_wrapper_uninstall_button" Grid.Row="0" Grid.Column="2" Content="Uninstall" Width="75" Margin="5 0 5 0" VerticalAlignment="Center" HorizontalAlignment="Right" Click="razer_wrapper_uninstall_button_Click"/>

<Label Grid.Row="1" Grid.Column="0" Content="Installed Version:" Margin="5 0 5 0" Padding="0" VerticalAlignment="Center"/>
<Label x:Name="razer_wrapper_installed_version_label" Grid.Row="1" Grid.Column="1" Margin="5 0 5 0" Padding="0" VerticalAlignment="Center"/>
Expand Down
219 changes: 98 additions & 121 deletions Project-Aurora/Project-Aurora/Settings/Control_Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Net;
using RazerSdkWrapper.Data;
using System.Windows.Threading;
using Aurora.Utils;

namespace Aurora.Settings
{
Expand Down Expand Up @@ -136,7 +137,8 @@ public Control_Settings()
var rzSdkEnabled = RzHelper.IsSdkEnabled();

this.razer_wrapper_installed_version_label.Content = rzVersion.ToString();
if (!RzHelper.IsSdkVersionSupported(rzVersion))
this.razer_wrapper_supported_versions_label.Content = $"{RzHelper.MinimumSupportedVersion}-{RzHelper.MaximumSupportedVersion}";
if (rzVersion < RzHelper.MaximumSupportedVersion)
{
this.razer_wrapper_installed_version_label.Foreground = new SolidColorBrush(Colors.PaleVioletRed);
this.razer_wrapper_install_button.Visibility = Visibility.Visible;
Expand All @@ -147,6 +149,9 @@ public Control_Settings()
this.razer_wrapper_install_button.Visibility = Visibility.Hidden;
}

if (rzVersion == new RzSdkVersion())
this.razer_wrapper_uninstall_button.Visibility = Visibility.Hidden;

this.razer_wrapper_enabled_label.Content = rzSdkEnabled ? "Enabled" : "Disabled";
this.razer_wrapper_enabled_label.Foreground = rzSdkEnabled ? new SolidColorBrush(Colors.LightGreen) : new SolidColorBrush(Colors.PaleVioletRed);

Expand All @@ -158,7 +163,7 @@ public Control_Settings()
{
var appList = Global.razerManager.GetDataProvider<RzAppListDataProvider>();
appList.Update();
this.razer_wrapper_current_application_label.Content = $"{appList.CurrentAppExecutable} [{appList.CurrentAppPid}]";
this.razer_wrapper_current_application_label.Content = $"{appList.CurrentAppExecutable ?? "None"} [{appList.CurrentAppPid}]";
}

Global.razerManager.DataUpdated += (s, _) =>
Expand Down Expand Up @@ -746,150 +751,122 @@ private void start_silently_enabled_Checked(object sender, RoutedEventArgs e)

private void razer_wrapper_install_button_Click(object sender, RoutedEventArgs e)
{
razer_wrapper_install_button.IsEnabled = false;

#region Razer SDK Installer/Uninstaller helpers
Task<int> UninstallAsync()
void HandleExceptions(AggregateException ae)
{
return System.Threading.Tasks.Task.Run(() =>
{
if (RzHelper.IsSdkVersionSupported(RzHelper.GetSdkVersion()))
return 0;
ShowMessageBox(ae.ToString(), "Exception!", MessageBoxImage.Error);
ae.Handle(ex => {
Global.logger.Error(ex.ToString());
return true;
});
}

using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
{
var key = hklm.OpenSubKey(@"Software\Razer Chroma SDK");
var path = (string)key?.GetValue("UninstallPath", null);
var filename = (string)key?.GetValue("UninstallFilename", null);
void SetButtonContent(string s)
=> Application.Current.Dispatcher.Invoke(() => razer_wrapper_install_button.Content = s);

if (path == null || filename == null)
return 0;
void ShowMessageBox(string message, string title, MessageBoxImage image = MessageBoxImage.Exclamation)
=> Application.Current.Dispatcher.Invoke(() => System.Windows.MessageBox.Show(message, title, MessageBoxButton.OK, image));

try
{
var processInfo = new ProcessStartInfo
{
FileName = filename,
WorkingDirectory = path,
Arguments = $"/S _?={path}",
ErrorDialog = true
};
var process = Process.Start(processInfo);
process.WaitForExit(120000);
return process.ExitCode;
}
catch (Exception ex)
{
throw new OperationCanceledException("Razer SDK Uninstallation failed!", ex);
}
}
});
}
razer_wrapper_install_button.IsEnabled = false;
razer_wrapper_uninstall_button.IsEnabled = false;

Task<string> DownloadAsync()
System.Threading.Tasks.Task.Run(async () =>
{
return System.Threading.Tasks.Task.Run(() =>
SetButtonContent("Uninstalling");
var uninstallSuccess = await RazerChromaUtils.UninstallAsync()
.ContinueWith(t =>
{
var url = "http://cdn.razersynapse.com/156092369797u1UA8NRazerChromaBroadcasterSetup_v3.4.0630.061913.exe";
try
if (t.Exception != null)
{
using (var client = new WebClient())
{
var path = Path.ChangeExtension(Path.GetTempFileName(), ".exe");
client.DownloadFile(url, path);
return path;
}
HandleExceptions(t.Exception);
return false;
}
catch (Exception ex)
else if (t.Result == (int)RazerChromaInstallerExitCode.RestartRequired)
{
throw new OperationCanceledException("Razer SDK Downloading failed!", ex);
ShowMessageBox("The uninstaller requested system restart!\nPlease reboot your pc and re-run the installation.", "Restart required!");
return false;
}
});
}
Task<int> InstallAsync(string installerPath)
{
return System.Threading.Tasks.Task.Run(() =>
return true;
})
.ConfigureAwait(false);
if (!uninstallSuccess)
return;
SetButtonContent("Downloading");
var downloadPath = await RazerChromaUtils.DownloadAsync()
.ContinueWith(t =>
{
try
{
var processInfo = new ProcessStartInfo
{
FileName = Path.GetFileName(installerPath),
WorkingDirectory = Path.GetDirectoryName(installerPath),
Arguments = "/S",
ErrorDialog = true
};
var process = Process.Start(processInfo);
process.WaitForExit(120000);
return process.ExitCode;
}
catch (Exception ex)
if (t.Exception != null)
{
throw new OperationCanceledException("Razer SDK Installation failed!", ex);
HandleExceptions(t.Exception);
return null;
}
});
}
#endregion
bool HandleErrorLevel(int errorlevel)
{
switch (errorlevel)
{
case 3010:
{
Application.Current.Dispatcher.Invoke(() => Xceed.Wpf.Toolkit.MessageBox.Show("Razer SDK requested system restart!\nPlease reboot your pc and re-run the installation.",
"Restart required!", MessageBoxButton.OK, MessageBoxImage.Exclamation));
return false;
}
}
return t.Result;
})
.ConfigureAwait(false);
return true;
}
if (downloadPath == null)
return;
void SetState(string name)
=> Application.Current.Dispatcher.Invoke(() => razer_wrapper_install_button.Content = name);
SetButtonContent("Installing");
await RazerChromaUtils.InstallAsync(downloadPath)
.ContinueWith(t =>
{
if (t.Exception != null)
HandleExceptions(t.Exception);
else if (t.Result == (int)RazerChromaInstallerExitCode.RestartRequired)
ShowMessageBox("The installer requested system restart!\nPlease reboot your pc.", "Restart required!");
else
{
SetButtonContent("Done!");
ShowMessageBox("Installation successful!\nPlease restart aurora for changes to take effect.", "Restart required!");
}
})
.ConfigureAwait(false);
});
}

System.Threading.Tasks.Task.Run(async () =>
private void razer_wrapper_uninstall_button_Click(object sender, RoutedEventArgs e)
{
void HandleExceptions(AggregateException ae)
{
try
{
SetState("Uninstalling");
var errorlevel = await UninstallAsync();
if (!HandleErrorLevel(errorlevel))
return false;
ShowMessageBox(ae.ToString(), "Exception!", MessageBoxImage.Error);
ae.Handle(ex => {
Global.logger.Error(ex.ToString());
return true;
});
}

SetState("Downloading");
var path = await DownloadAsync();
void SetButtonContent(string s)
=> Application.Current.Dispatcher.Invoke(() => razer_wrapper_uninstall_button.Content = s);

void ShowMessageBox(string message, string title, MessageBoxImage image = MessageBoxImage.Exclamation)
=> Application.Current.Dispatcher.Invoke(() => System.Windows.MessageBox.Show(message, title, MessageBoxButton.OK, image));

SetState("Installing");
errorlevel = await InstallAsync(path);
if (!HandleErrorLevel(errorlevel))
return false;
}
catch (OperationCanceledException ex)
{
Application.Current.Dispatcher.Invoke(() => Xceed.Wpf.Toolkit.MessageBox.Show($"{ex.Message}:\n{ex.InnerException.ToString()}",
"Exception!", MessageBoxButton.OK, MessageBoxImage.Error));
return false;
}
razer_wrapper_install_button.IsEnabled = false;
razer_wrapper_uninstall_button.IsEnabled = false;

return true;
}).ContinueWith(t =>
System.Threading.Tasks.Task.Run(async () =>
{
if (t.Result)
{
SetState("Success!");
Application.Current.Dispatcher.Invoke(() => Xceed.Wpf.Toolkit.MessageBox.Show("Installation successful!\nPlease restart Aurora for changes to take effect.",
"Success!", MessageBoxButton.OK, MessageBoxImage.Information));
}
else
SetButtonContent("Uninstalling");
await RazerChromaUtils.UninstallAsync()
.ContinueWith(t =>
{
SetState("Failure!");
}
if (t.Exception != null)
HandleExceptions(t.Exception);
else if (t.Result == (int)RazerChromaInstallerExitCode.RestartRequired)
ShowMessageBox("The uninstaller requested system restart!\nPlease reboot your pc.", "Restart required!");
else if (t.Result == (int)RazerChromaInstallerExitCode.InvalidState)
ShowMessageBox("There is nothing to install!", "Invalid State!");
else
{
SetButtonContent("Done!");
ShowMessageBox("Uninstallation successful!\nPlease restart aurora for changes to take effect.", "Restart required!");
}
})
.ConfigureAwait(false);
});
}

Expand Down
Loading

0 comments on commit 7b4a05f

Please sign in to comment.