Skip to content

Commit

Permalink
Add an option to restore default settings in the Control Center app.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbucchia committed Apr 23, 2023
1 parent ffc112f commit 97e8b5a
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 40 deletions.
2 changes: 2 additions & 0 deletions companion/ExperimentalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ private void LoadSettings()
disableFramePipelining.Checked = (int)key.GetValue("quirk_disable_frame_pipelining", 0) == 1 ? true : false;
alwaysUseFrameIdZero.Checked = (int)key.GetValue("quirk_always_use_frame_id_zero", 0) == 1 ? true : false;
forceDisableParallelProjection.Checked = (int)key.GetValue("force_parallel_projection_state", 1) == 0 ? true : false;

// DO NOT FORGET TO ADD TO restoreDefaults_Click()!
}
catch (Exception)
{
Expand Down
32 changes: 23 additions & 9 deletions companion/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 78 additions & 31 deletions companion/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,37 +153,7 @@ public MainForm()
}

// Read the PimaxXR configuration.
try
{
key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(RegPrefix);

// Must match the defaults in the runtime!
recenterMode.Checked = (int)key.GetValue("recenter_on_startup", 1) == 1 ? true : false;
swapGripAimPoses.Checked = (int)key.GetValue("swap_grip_aim_poses", 0) == 1 ? true : false;
controllerEmulation.SelectedIndex = (int)key.GetValue("force_interaction_profile", 0);
joystickDeadzone.Value = (int)key.GetValue("joystick_deadzone", 2);
guardian.Checked = (int)key.GetValue("guardian", 1) == 1 ? true : false;
guardianRadius.Value = (int)key.GetValue("guardian_radius", 1600) / 10;
guardianThreshold.Value = (int)key.GetValue("guardian_threshold", 1100) / 10;
mirrorMode.Checked = (int)key.GetValue("mirror_window", 0) == 1 ? true : false;
enableTelemetry.Checked = (int)key.GetValue("enable_telemetry", 0) == 1 ? true : false;
}
catch (Exception)
{
MessageBox.Show(this, "Failed to write to registry. Please make sure the app is running elevated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (key != null)
{
key.Close();
}
}

RefreshEnabledState();
joystickDeadzone_Scroll(null, null);
guardianRadius_Scroll(null, null);
guardianThreshold_Scroll(null, null);
LoadSettings();

ResumeLayout();

Expand Down Expand Up @@ -322,6 +292,52 @@ public static void WriteSetting(string name, int value)
}
}

private void LoadSettings()
{
loading = true;
SuspendLayout();

Microsoft.Win32.RegistryKey key = null;

try
{
key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(RegPrefix);

// Must match the defaults in the runtime!
recenterMode.Checked = (int)key.GetValue("recenter_on_startup", 1) == 1 ? true : false;
swapGripAimPoses.Checked = (int)key.GetValue("swap_grip_aim_poses", 0) == 1 ? true : false;
controllerEmulation.SelectedIndex = (int)key.GetValue("force_interaction_profile", 0);
joystickDeadzone.Value = (int)key.GetValue("joystick_deadzone", 2);
guardian.Checked = (int)key.GetValue("guardian", 1) == 1 ? true : false;
guardianRadius.Value = (int)key.GetValue("guardian_radius", 1600) / 10;
guardianThreshold.Value = (int)key.GetValue("guardian_threshold", 1100) / 10;
mirrorMode.Checked = (int)key.GetValue("mirror_window", 0) == 1 ? true : false;
enableTelemetry.Checked = (int)key.GetValue("enable_telemetry", 0) == 1 ? true : false;

// DO NOT FORGET TO ADD TO restoreDefaults_Click()!
}
catch (Exception)
{
MessageBox.Show(this, "Failed to write to registry. Please make sure the app is running elevated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (key != null)
{
key.Close();
}
}

RefreshEnabledState();
joystickDeadzone_Scroll(null, null);
guardianRadius_Scroll(null, null);
guardianThreshold_Scroll(null, null);

ResumeLayout();

loading = false;
}

private void RefreshEnabledState()
{
runtimeStatusLabel.Enabled = recenterMode.Enabled = recenterLabel.Enabled = swapGripAimPoses.Enabled = controllerEmulation.Enabled = controllerEmulationLabel.Enabled =
Expand Down Expand Up @@ -459,6 +475,37 @@ private void enableTelemetry_CheckedChanged(object sender, EventArgs e)
WriteSetting("enable_telemetry", enableTelemetry.Checked ? 1 : 0);
}

private void restoreDefaults_Click(object sender, EventArgs e)
{
Microsoft.Win32.RegistryKey key = null;

try
{
key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(MainForm.RegPrefix);

key.DeleteValue("recenter_on_startup", false);
key.DeleteValue("swap_grip_aim_poses", false);
key.DeleteValue("force_interaction_profile", false);
key.DeleteValue("joystick_deadzone", false);
key.DeleteValue("guardian", false);
key.DeleteValue("guardian_radius", false);
key.DeleteValue("guardian_threshold", false);
key.DeleteValue("mirror_window", false);
}
catch (Exception)
{
}
finally
{
if (key != null)
{
key.Close();
}
}

LoadSettings();
}

private void openLogs_Click(object sender, EventArgs e)
{
var processInfo = new ProcessStartInfo();
Expand Down

0 comments on commit 97e8b5a

Please sign in to comment.