@@ -19,44 +19,6 @@ namespace GPUPrefSwitcher
19
19
/// </summary>
20
20
public class PreferencesXML
21
21
{
22
- /*
23
- public class ThreadSafeXmlDoc
24
- {
25
- //private XmlDocument xmlDocument = new XmlDocument();
26
- private SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1);
27
- private XmlDocument xmlDocument = new();
28
-
29
- public void Load(string path)
30
- {
31
- SemaphoreSlim.Wait();
32
- try
33
- {
34
- xmlDocument.Load(path);
35
- }
36
- finally { SemaphoreSlim.Release(); }
37
- }
38
-
39
- public void Save(string path)
40
- {
41
- SemaphoreSlim.Wait();
42
- try
43
- {
44
- xmlDocument.Save(path);
45
- }
46
- finally { SemaphoreSlim.Release(); }
47
- }
48
-
49
- public XmlNodeList GetElementsByTagName(string tagName)
50
- {
51
- SemaphoreSlim.Wait();
52
- try
53
- {
54
- return xmlDocument.GetElementsByTagName(tagName);
55
- }
56
- finally { SemaphoreSlim.Release() ; }
57
- }
58
- }
59
- */
60
22
61
23
62
24
public static readonly string XML_PREFERENCES_PATH = Program . SavedDataPath + "Preferences.xml" ;
@@ -160,80 +122,69 @@ internal void ReloadXML()
160
122
/// <returns>A readonly list of AppEntries; you must call the modify or save functions to actually change these in the XML document.</returns>
161
123
internal List < AppEntry > GetAppEntries ( )
162
124
{
125
+ xmlDocument . Load ( XML_PREFERENCES_PATH ) ; //performance hog?
163
126
164
- //try
165
- //{
166
- //semaphoreSlim.Wait();
167
-
168
- xmlDocument . Load ( XML_PREFERENCES_PATH ) ; //performance hog?
127
+ XmlNodeList xmlAppEntries = xmlDocument . GetElementsByTagName ( XML_APP_ENTRY ) ;
169
128
170
- XmlNodeList xmlAppEntries = xmlDocument . GetElementsByTagName ( XML_APP_ENTRY ) ;
129
+ List < AppEntry > appEntries = new List < AppEntry > ( ) ;
171
130
172
- List < AppEntry > appEntries = new List < AppEntry > ( ) ;
131
+ foreach ( XmlNode xmlAppEntry in xmlAppEntries )
132
+ {
173
133
174
- foreach ( XmlNode xmlAppEntry in xmlAppEntries )
134
+ string appPath ;
135
+ bool enableSwitcher ;
136
+ int gpuPrefOnBattery ;
137
+ int gpuPrefPluggedIn ;
138
+ bool enableFileSwapper ;
139
+ string runOnBatteryPath ;
140
+ string runPluggedInPath ;
141
+ bool seenInRegistry ;
142
+
143
+ appPath = xmlAppEntry . SelectSingleNode ( XML_APP_PATH ) . InnerText ;
144
+ //Debug.WriteLine(appPath);
145
+ XmlNode xmlGpuPreference = xmlAppEntry . SelectSingleNode ( XML_GPU_PREFERENCE ) ;
146
+ enableSwitcher = bool . Parse ( xmlGpuPreference . Attributes [ XML_ATTR_ENABLESWITCHER ] . Value ) ;
147
+ gpuPrefOnBattery = int . Parse ( xmlGpuPreference . SelectSingleNode ( XML_ON_BATTERY ) . InnerText ) ;
148
+ gpuPrefPluggedIn = int . Parse ( xmlGpuPreference . SelectSingleNode ( XML_PLUGGED_IN ) . InnerText ) ;
149
+ enableFileSwapper = bool . Parse ( xmlGpuPreference . Attributes [ XML_ATTR_ENABLEFILESWAPPER ] . Value ) ;
150
+ runOnBatteryPath = xmlGpuPreference . SelectSingleNode ( XML_RUN_ON_BATTERY_PATH ) . InnerText ;
151
+ runPluggedInPath = xmlGpuPreference . SelectSingleNode ( XML_RUN_PLUGGED_IN_PATH ) . InnerText ;
152
+ seenInRegistry = bool . Parse ( xmlAppEntry . SelectSingleNode ( XML_SEEN_IN_REGISTRY ) . InnerText ) ;
153
+
154
+ string [ ] swapPaths = GetAppEntryFileSwapperPaths ( xmlAppEntry ) ;
155
+
156
+ bool pendingAddToRegistry = false ;
157
+ if ( xmlAppEntry . SelectSingleNode ( XML_PENDING_ADD ) != null )
175
158
{
159
+ pendingAddToRegistry = true ;
160
+ }
176
161
177
- string appPath ;
178
- bool enableSwitcher ;
179
- int gpuPrefOnBattery ;
180
- int gpuPrefPluggedIn ;
181
- bool enableFileSwapper ;
182
- string runOnBatteryPath ;
183
- string runPluggedInPath ;
184
- bool seenInRegistry ;
185
-
186
- appPath = xmlAppEntry . SelectSingleNode ( XML_APP_PATH ) . InnerText ;
187
- //Debug.WriteLine(appPath);
188
- XmlNode xmlGpuPreference = xmlAppEntry . SelectSingleNode ( XML_GPU_PREFERENCE ) ;
189
- enableSwitcher = bool . Parse ( xmlGpuPreference . Attributes [ XML_ATTR_ENABLESWITCHER ] . Value ) ;
190
- gpuPrefOnBattery = int . Parse ( xmlGpuPreference . SelectSingleNode ( XML_ON_BATTERY ) . InnerText ) ;
191
- gpuPrefPluggedIn = int . Parse ( xmlGpuPreference . SelectSingleNode ( XML_PLUGGED_IN ) . InnerText ) ;
192
- enableFileSwapper = bool . Parse ( xmlGpuPreference . Attributes [ XML_ATTR_ENABLEFILESWAPPER ] . Value ) ;
193
- runOnBatteryPath = xmlGpuPreference . SelectSingleNode ( XML_RUN_ON_BATTERY_PATH ) . InnerText ;
194
- runPluggedInPath = xmlGpuPreference . SelectSingleNode ( XML_RUN_PLUGGED_IN_PATH ) . InnerText ;
195
- seenInRegistry = bool . Parse ( xmlAppEntry . SelectSingleNode ( XML_SEEN_IN_REGISTRY ) . InnerText ) ;
196
-
197
- string [ ] swapPaths = GetAppEntryFileSwapperPaths ( xmlAppEntry ) ;
198
-
199
- bool pendingAddToRegistry = false ;
200
- if ( xmlAppEntry . SelectSingleNode ( XML_PENDING_ADD ) != null )
201
- {
202
- pendingAddToRegistry = true ;
203
- }
204
-
205
- string [ ] fileSwapPathStatus = new string [ swapPaths . Length ] ;
206
- XmlNodeList swapPathNodes = GetAppEntryFileSwapperXmlNodes ( xmlAppEntry ) ;
207
- for ( int i = 0 ; i < swapPaths . Length ; i ++ )
208
- {
209
- string state = swapPathNodes [ i ] . Attributes [ "state" ] . Value ;
210
- fileSwapPathStatus [ i ] = state ;
211
- }
212
-
213
- appEntries . Add (
214
- new AppEntry ( )
215
- {
216
- AppPath = appPath ,
217
- EnableSwitcher = enableSwitcher ,
218
- GPUPrefOnBattery = gpuPrefOnBattery ,
219
- GPUPrefPluggedIn = gpuPrefPluggedIn ,
220
- EnableFileSwapper = enableFileSwapper ,
221
- FileSwapperPaths = swapPaths ,
222
- SwapperStates = PowerLineStatusConversions . StringArrToPowerLineStatusArr ( fileSwapPathStatus ) ,
223
- PendingAddToRegistry = pendingAddToRegistry ,
224
- RunOnBatteryPath = runOnBatteryPath ,
225
- RunPluggedInPath = runPluggedInPath ,
226
- SeenInRegistry = seenInRegistry ,
227
- }
228
- ) ;
162
+ string [ ] fileSwapPathStatus = new string [ swapPaths . Length ] ;
163
+ XmlNodeList swapPathNodes = GetAppEntryFileSwapperXmlNodes ( xmlAppEntry ) ;
164
+ for ( int i = 0 ; i < swapPaths . Length ; i ++ )
165
+ {
166
+ string state = swapPathNodes [ i ] . Attributes [ "state" ] . Value ;
167
+ fileSwapPathStatus [ i ] = state ;
229
168
}
230
- return appEntries ;
231
- /*
232
- } finally
233
- {
234
- semaphoreSlim.Release();
169
+
170
+ appEntries . Add (
171
+ new AppEntry ( )
172
+ {
173
+ AppPath = appPath ,
174
+ EnableSwitcher = enableSwitcher ,
175
+ GPUPrefOnBattery = gpuPrefOnBattery ,
176
+ GPUPrefPluggedIn = gpuPrefPluggedIn ,
177
+ EnableFileSwapper = enableFileSwapper ,
178
+ FileSwapperPaths = swapPaths ,
179
+ SwapperStates = PowerLineStatusConversions . StringArrToPowerLineStatusArr ( fileSwapPathStatus ) ,
180
+ PendingAddToRegistry = pendingAddToRegistry ,
181
+ RunOnBatteryPath = runOnBatteryPath ,
182
+ RunPluggedInPath = runPluggedInPath ,
183
+ SeenInRegistry = seenInRegistry ,
184
+ }
185
+ ) ;
235
186
}
236
- */
187
+ return appEntries ;
237
188
238
189
}
239
190
0 commit comments