Skip to content

Put driver installation and system restore point creation steps in a setup form#107

Merged
Aurumaker72 merged 9 commits intomainfrom
94-put-driver-installation-and-system-restore-point-creation-steps-in-a-setup-wizard
Nov 17, 2025
Merged

Put driver installation and system restore point creation steps in a setup form#107
Aurumaker72 merged 9 commits intomainfrom
94-put-driver-installation-and-system-restore-point-creation-steps-in-a-setup-wizard

Conversation

@Aurumaker72
Copy link
Collaborator

@Aurumaker72 Aurumaker72 commented Nov 16, 2025

Driver installation and system restore point creation is now bundled in this dialog, which pops up at startup when the driver isn't installed.

image

The InitForm has been removed and replaced by more clever state management in Program

replaces the InitForm and moves its logic into Program.cs
@Aurumaker72 Aurumaker72 added the enhancement New feature or request label Nov 16, 2025
@Aurumaker72
Copy link
Collaborator Author

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?

@luttje
Copy link
Collaborator

luttje commented Nov 16, 2025

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 SystemPropertiesProtection.exe for the user. That brings them straight to where they can create it themselves.

@Aurumaker72
Copy link
Collaborator Author

That's a great idea. Yep, will do.

…he restore point system dialog, allowing the user to create the restore point themselves
@Aurumaker72
Copy link
Collaborator Author

Alright, that's done.

@Aurumaker72 Aurumaker72 marked this pull request as ready for review November 16, 2025 19:32
Copilot AI review requested due to automatic review settings November 16, 2025 19:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SetupForm to guide users through driver installation with an option to create a system restore point
  • Removed InitForm and consolidated initialization logic into Program.cs with 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;
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return;
Application.Exit();

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +24
catch (Win32Exception)
{
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
catch (Win32Exception)
{
catch (Win32Exception ex)
{
MessageBox.Show(
"Driver installation failed.\n\n" + ex.Message,
"Installation Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);

Copilot uses AI. Check for mistakes.

private void btnCreateSystemRestorePoint_Click(object sender, EventArgs e)
{
Process.Start("SystemPropertiesProtection.exe");
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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
);
}

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +32
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;
}
}
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;
}

Copilot uses AI. Check for mistakes.
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field 'components' can be 'readonly'.

Suggested change
private System.ComponentModel.IContainer components = null;
private readonly System.ComponentModel.IContainer components = null;

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +82
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);
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generic catch clause.

Suggested change
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
);

Copilot uses AI. Check for mistakes.
…ions.IsDriverInstalled` in `Program.cs`

this is a dependency leak and architecturally unclean, but we have bigger problems than this lol
@luttje
Copy link
Collaborator

luttje commented Nov 16, 2025

Alright, that's done.

Awesome!

I have time to test this tomorrow morning. Will review then.

@Aurumaker72 Aurumaker72 requested a review from luttje November 16, 2025 19:52
Aurumaker72 and others added 3 commits November 16, 2025 20:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Aurumaker72 Aurumaker72 merged commit ac3bfa6 into main Nov 17, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

3 participants