-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
ProfileDriverSettingsViewModel.cs
169 lines (135 loc) · 4.5 KB
/
ProfileDriverSettingsViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Windows.Threading;
using Microsoft.Win32;
using Nefarius.BthPS3.Shared;
namespace BthPS3CfgUI;
[SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class ProfileDriverSettingsViewModel : INotifyPropertyChanged
{
private readonly RegistryKey _bthPs3ServiceParameters;
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
private readonly DispatcherTimer _dispatcherTimer;
public ProfileDriverSettingsViewModel()
{
_bthPs3ServiceParameters =
Registry.LocalMachine.OpenSubKey(
"SYSTEM\\CurrentControlSet\\Services\\BthPS3\\Parameters", true);
if (_bthPs3ServiceParameters == null)
{
throw new Exception("BthPS3 registry path not found. Are the drivers installed?");
}
if (BluetoothHelper.IsBluetoothRadioAvailable)
{
//
// Periodically refresh patch state value
//
_dispatcherTimer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 1) };
_dispatcherTimer.Tick += DispatcherTimerOnTick;
_dispatcherTimer.Start();
}
}
public InvertableBool IsBluetoothRadioAvailable => BluetoothHelper.IsBluetoothRadioAvailable;
#region PSM patch
public bool IsPSMPatchEnabled
{
get => FilterDriver.IsFilterEnabled;
set => FilterDriver.IsFilterEnabled = value;
}
#endregion
public event PropertyChangedEventHandler PropertyChanged;
private void DispatcherTimerOnTick(object sender, EventArgs e)
{
//
// Force UI to re-evaluate patch status value
//
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsPSMPatchEnabled"));
}
private void SetBool(string valueName, bool value)
{
_bthPs3ServiceParameters.SetValue(valueName, value ? 1 : 0, RegistryValueKind.DWord);
}
private bool GetBool(string valueName, bool defaultValue)
{
return int.Parse(_bthPs3ServiceParameters.GetValue(valueName, defaultValue ? 1 : 0).ToString()) > 0;
}
private void SetUInt(string valueName, uint value)
{
_bthPs3ServiceParameters.SetValue(valueName, value, RegistryValueKind.DWord);
}
private uint GetUInt(string valueName, uint defaultValue)
{
return uint.Parse(_bthPs3ServiceParameters.GetValue(valueName, defaultValue).ToString());
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#region Profile Driver
public bool IsSIXAXISSupported
{
get => GetBool("IsSIXAXISSupported", true);
set => SetBool("IsSIXAXISSupported", value);
}
public bool IsNAVIGATIONSupported
{
get => GetBool("IsNAVIGATIONSupported", true);
set => SetBool("IsNAVIGATIONSupported", value);
}
public bool IsMOTIONSupported
{
get => GetBool("IsMOTIONSupported", false);
set => SetBool("IsMOTIONSupported", value);
}
public bool IsWIRELESSSupported
{
get => GetBool("IsWIRELESSSupported", false);
set => SetBool("IsWIRELESSSupported", value);
}
public bool AutoEnableFilter
{
get => GetBool("AutoEnableFilter", true);
set => SetBool("AutoEnableFilter", value);
}
public uint AutoEnableFilterDelay
{
get => GetUInt("AutoEnableFilterDelay", 10);
set => SetUInt("AutoEnableFilterDelay", value);
}
public bool AutoDisableFilter
{
get => GetBool("AutoDisableFilter", true);
set => SetBool("AutoDisableFilter", value);
}
#endregion
#region Danger Zone
public bool RawPDO
{
get => GetBool("RawPDO", true);
set => SetBool("RawPDO", value);
}
public bool HidePDO
{
get => GetBool("HidePDO", false);
set => SetBool("HidePDO", value);
}
public bool AdminOnlyPDO
{
get => GetBool("AdminOnlyPDO", false);
set => SetBool("AdminOnlyPDO", value);
}
public bool ExclusivePDO
{
get => GetBool("ExclusivePDO", true);
set => SetBool("ExclusivePDO", value);
}
public uint ChildIdleTimeout
{
get => GetUInt("ChildIdleTimeout", 10000);
set => SetUInt("ChildIdleTimeout", value);
}
#endregion
}