Put driver installation and system restore point creation steps in a setup form#107
Conversation
replaces the InitForm and moves its logic into Program.cs
|
System restore point creation requires elevation, so this just won't work without moving that functionality into a separate elevated executable. Seems a bit too much, so I think it's best to just drop that part for now. @luttje thoughts? |
|
Nice job cleaning this up! As for the restore point: Perhaps instead of needing an elevated process to create the restore point, we can add a button to open |
|
That's a great idea. Yep, will do. |
…he restore point system dialog, allowing the user to create the restore point themselves
|
Alright, that's done. |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the application startup flow by introducing a SetupForm that handles driver installation and system restore point creation, replacing the previous InitForm approach. The new design presents users with a dialog when the SCP Virtual Bus driver isn't installed, allowing them to create a system restore point before installation.
- Introduced
SetupFormto guide users through driver installation with an option to create a system restore point - Removed
InitFormand consolidated initialization logic intoProgram.cswith improved state management - Added
ScpBusExtensions.IsDriverInstalled()to check driver status at startup
Reviewed Changes
Copilot reviewed 7 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| SetupForm.cs / SetupForm.Designer.cs / SetupForm.resx | New setup dialog for driver installation with system restore point option |
| Program.cs | Refactored initialization flow with driver detection and conditional form display |
| ScpBusExtensions.cs | New utility method to check if the SCP driver is installed |
| InitForm.cs / InitForm.Designer.cs | Removed legacy initialization form |
| Properties/Resources.resx / Resources.Designer.cs | Added arrow_down icon resource for the install button |
| Key2Joy.Gui.csproj | Added System.Management package dependency |
| Graphics/Icons/arrow_down.png | New icon asset for the install button |
Files not reviewed (3)
- Key2Joy.Gui/InitForm.Designer.cs: Language not supported
- Key2Joy.Gui/Properties/Resources.Designer.cs: Language not supported
- Key2Joy.Gui/SetupForm.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| catch | ||
| { | ||
| MessageBox.Show("Failed to initialize the virtual gamepad driver. Please ensure that the SCP Virtual Bus Driver is correctly installed.", "Key2Joy", MessageBoxButtons.OK, MessageBoxIcon.Error); | ||
| return; |
There was a problem hiding this comment.
Incomplete error handling: When the gamepad driver initialization fails, the error message is shown but the application doesn't exit gracefully. After returning from this method, ActiveForm will be null (since it hasn't been set due to the early return), which could cause issues in the main application loop at line 50-52. Consider calling Application.Exit() or setting ActiveForm to a safe state before returning.
| return; | |
| Application.Exit(); |
| catch (Win32Exception) | ||
| { |
There was a problem hiding this comment.
Silent error handling: Catching Win32Exception and simply returning without any user feedback is problematic. If the driver installation fails (e.g., user cancels the UAC prompt or the installation encounters an error), the user is left in the SetupForm with no indication of what happened. Consider showing an appropriate message to the user explaining the failure or cancellation.
| catch (Win32Exception) | |
| { | |
| catch (Win32Exception ex) | |
| { | |
| MessageBox.Show( | |
| "Driver installation failed.\n\n" + ex.Message, | |
| "Installation Error", | |
| MessageBoxButtons.OK, | |
| MessageBoxIcon.Error | |
| ); |
|
|
||
| private void btnCreateSystemRestorePoint_Click(object sender, EventArgs e) | ||
| { | ||
| Process.Start("SystemPropertiesProtection.exe"); |
There was a problem hiding this comment.
Missing error handling: Process.Start can throw various exceptions (e.g., Win32Exception, FileNotFoundException) if the system restore point executable cannot be found or fails to launch. Consider wrapping this call in a try-catch block and providing user feedback if it fails.
| Process.Start("SystemPropertiesProtection.exe"); | |
| try | |
| { | |
| Process.Start("SystemPropertiesProtection.exe"); | |
| } | |
| catch (Win32Exception ex) | |
| { | |
| MessageBox.Show( | |
| "Failed to launch System Restore Point tool.\n\n" + ex.Message, | |
| "Error", | |
| MessageBoxButtons.OK, | |
| MessageBoxIcon.Error | |
| ); | |
| } | |
| catch (System.IO.FileNotFoundException ex) | |
| { | |
| MessageBox.Show( | |
| "System Restore Point tool not found.\n\n" + ex.Message, | |
| "Error", | |
| MessageBoxButtons.OK, | |
| MessageBoxIcon.Error | |
| ); | |
| } | |
| catch (Exception ex) | |
| { | |
| MessageBox.Show( | |
| "An unexpected error occurred while launching System Restore Point tool.\n\n" + ex.Message, | |
| "Error", | |
| MessageBoxButtons.OK, | |
| MessageBoxIcon.Error | |
| ); | |
| } |
| extension(ScpBus scpBus) | ||
| { | ||
| /// <summary> | ||
| /// Checks if the necessary driver for simulated gamepads is installed. | ||
| /// </summary> | ||
| /// <returns> | ||
| /// True if the driver is installed; otherwise, false. | ||
| /// </returns> | ||
| public static bool IsDriverInstalled() | ||
| { | ||
| try | ||
| { | ||
| var bus = new ScpBus(); | ||
| bus.Dispose(); | ||
| return true; | ||
| } | ||
| catch (IOException) | ||
| { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
Invalid C# syntax: The extension(ScpBus scpBus) syntax is not valid C#. This appears to be attempting to use extension methods, but the correct syntax should be to declare IsDriverInstalled() as a static method directly in the static class without the extension(ScpBus scpBus) wrapper. Simply remove lines 12 and 33, and unindent the method body.
| extension(ScpBus scpBus) | |
| { | |
| /// <summary> | |
| /// Checks if the necessary driver for simulated gamepads is installed. | |
| /// </summary> | |
| /// <returns> | |
| /// True if the driver is installed; otherwise, false. | |
| /// </returns> | |
| public static bool IsDriverInstalled() | |
| { | |
| try | |
| { | |
| var bus = new ScpBus(); | |
| bus.Dispose(); | |
| return true; | |
| } | |
| catch (IOException) | |
| { | |
| return false; | |
| } | |
| } | |
| /// <summary> | |
| /// Checks if the necessary driver for simulated gamepads is installed. | |
| /// </summary> | |
| /// <returns> | |
| /// True if the driver is installed; otherwise, false. | |
| /// </returns> | |
| public static bool IsDriverInstalled() | |
| { | |
| try | |
| { | |
| var bus = new ScpBus(); | |
| bus.Dispose(); | |
| return true; | |
| } | |
| catch (IOException) | |
| { | |
| return false; | |
| } |
| /// <summary> | ||
| /// Required designer variable. | ||
| /// </summary> | ||
| private System.ComponentModel.IContainer components = null; |
There was a problem hiding this comment.
Field 'components' can be 'readonly'.
| private System.ComponentModel.IContainer components = null; | |
| private readonly System.ComponentModel.IContainer components = null; |
| catch | ||
| { | ||
| MessageBox.Show("Failed to initialize the virtual gamepad driver. Please ensure that the SCP Virtual Bus Driver is correctly installed.", "Key2Joy", MessageBoxButtons.OK, MessageBoxIcon.Error); |
There was a problem hiding this comment.
Generic catch clause.
| catch | |
| { | |
| MessageBox.Show("Failed to initialize the virtual gamepad driver. Please ensure that the SCP Virtual Bus Driver is correctly installed.", "Key2Joy", MessageBoxButtons.OK, MessageBoxIcon.Error); | |
| catch (Exception ex) | |
| { | |
| MessageBox.Show( | |
| "Failed to initialize the virtual gamepad driver. Please ensure that the SCP Virtual Bus Driver is correctly installed.\n\nError: " + ex.Message, | |
| "Key2Joy", | |
| MessageBoxButtons.OK, | |
| MessageBoxIcon.Error | |
| ); |
…ions.IsDriverInstalled` in `Program.cs` this is a dependency leak and architecturally unclean, but we have bigger problems than this lol
Awesome! I have time to test this tomorrow morning. Will review then. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Driver installation and system restore point creation is now bundled in this dialog, which pops up at startup when the driver isn't installed.
The
InitFormhas been removed and replaced by more clever state management inProgram