Skip to content

Commit 5a484fd

Browse files
committed
commit before switching to a BlockingCollection solution
1 parent f327038 commit 5a484fd

File tree

4 files changed

+11
-43
lines changed

4 files changed

+11
-43
lines changed

GPUPrefSwitcher/AppEntrySaveHandler.cs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Diagnostics;
45
using System.Linq;
@@ -15,27 +16,12 @@ public class AppEntrySaveHandler
1516
/// !!! This should always contain deep copies !!!
1617
/// </summary>
1718
private List<AppEntry> prevAppEntries;
18-
/*
19-
private List<AppEntry> prevAppEntries
20-
{
21-
get
22-
{
23-
return prevAppEntries_;
24-
}
25-
set
26-
{
27-
Logger.inst.Log("Set PrevAppEntries");
28-
prevAppEntries_ = value;
29-
}
30-
}
31-
private List<AppEntry> prevAppEntries_;
32-
*/
3319

3420
public IReadOnlyList<AppEntry> CurrentAppEntries
3521
{
3622
get
3723
{
38-
return currentAppEntries.AsReadOnly();
24+
return currentAppEntries;
3925
}
4026
}
4127
private List<AppEntry> currentAppEntries;
@@ -98,7 +84,7 @@ public AppEntrySaveHandler()
9884
//Logger.inst.Log(prevAppEntries.Single(x => x.AppPath == "F:\\SteamLibrary\\steamapps\\common\\Apex Legends\\r5apex.exe").ToString());
9985
}
10086

101-
public void ChangeAppEntryByPathAndSave(string path, AppEntry updatedAppEntry)
87+
public void ChangeAppEntryByPath(string path, AppEntry updatedAppEntry)
10288
{
10389
try
10490
{
@@ -124,24 +110,6 @@ public void ChangeAppEntryByPathAndSave(string path, AppEntry updatedAppEntry)
124110
}
125111
}
126112

127-
public int RemoveAll(Predicate<AppEntry> predicate)
128-
{
129-
return currentAppEntries.RemoveAll(predicate);
130-
}
131-
132-
public void AddAppEntryAndSave(AppEntry appEntry)
133-
{
134-
try
135-
{
136-
semaphoreSlim.Wait();
137-
138-
currentAppEntries.Add(appEntry);
139-
140-
SaveAppEntryChanges_Internal();
141-
142-
}
143-
finally { semaphoreSlim.Release(); }
144-
}
145113
/*
146114
* DECISION: Replacement or overwrite?
147115
* Per-Entry Replacement (SELECTED):

GPUPrefSwitcher/FileSwapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
260260

261261
Logger.inst.Log($"Saving SwapPath state for SwapPath {swapPath} for app {AppEntry.AppPath}");
262262
//await new Task(new Action( () => preferencesXML.ModifyAppEntryAndSave(AppEntry.AppPath, modified)));
263-
AppEntrySaveHandler.ChangeAppEntryByPathAndSave(AppEntry.AppPath, modified);
263+
AppEntrySaveHandler.ChangeAppEntryByPath(AppEntry.AppPath, modified);
264264
//AppEntrySaveHandler.SaveAppEntryChanges();
265265

266266
string s3 = $"Saved SwapPath state for SwapPath {swapPath} for app {AppEntry.AppPath}";
@@ -307,7 +307,7 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
307307
AppEntry modified = AppEntry; //struct copy
308308
modified.SwapperStates[swapPathIndex] = PowerLineStatus.Online;
309309

310-
AppEntrySaveHandler.ChangeAppEntryByPathAndSave(AppEntry.AppPath, modified);
310+
AppEntrySaveHandler.ChangeAppEntryByPath(AppEntry.AppPath, modified);
311311
//AppEntrySaveHandler.SaveAppEntryChanges();
312312
string s3 = $"Saved SwapPath state for SwapPath {swapPath} for app {AppEntry.AppPath}";
313313
Logger.inst.Log(s3);

GPUPrefSwitcher/Switcher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ private static void UpdateSeenInRegistryStatuses()
269269
if (regPathValues.Contains(appEntry.AppPath)){
270270
if (appEntry.SeenInRegistry == false)
271271
{
272-
appEntrySaveHandler.ChangeAppEntryByPathAndSave(appEntry.AppPath, appEntry with { SeenInRegistry = true });
272+
appEntrySaveHandler.ChangeAppEntryByPath(appEntry.AppPath, appEntry with { SeenInRegistry = true });
273273
}
274274
} else
275275
{
276-
appEntrySaveHandler.ChangeAppEntryByPathAndSave(appEntry.AppPath, appEntry with { SeenInRegistry = false });
276+
appEntrySaveHandler.ChangeAppEntryByPath(appEntry.AppPath, appEntry with { SeenInRegistry = false });
277277
}
278278
}
279279
//appEntrySaveHandler.SaveAppEntryChanges();
@@ -470,7 +470,7 @@ internal static void WriteXMLToRegistry(PowerLineStatus powerLineStatus)
470470

471471
AppEntry modifiedAppEntry = appEntry with { PendingAddToRegistry = false } ;
472472

473-
appEntrySaveHandler.ChangeAppEntryByPathAndSave(appEntry.AppPath, modifiedAppEntry);
473+
appEntrySaveHandler.ChangeAppEntryByPath(appEntry.AppPath, modifiedAppEntry);
474474
//appEntrySaveHandler.SaveAppEntryChanges();
475475
}
476476

GPUPrefSwitcherGUI/MainForm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private void dataGridView1_CellContentClick(object sender, DataGridViewCellEvent
227227
}
228228

229229
AppEntry updatedAppEntry = appEntryFromRow(e.RowIndex);
230-
appEntrySaver.ChangeAppEntryByPathAndSave(updatedAppEntry.AppPath, updatedAppEntry);
230+
appEntrySaver.ChangeAppEntryByPath(updatedAppEntry.AppPath, updatedAppEntry);
231231

232232
if (e.ColumnIndex == ConfigureCol)
233233
{
@@ -237,7 +237,7 @@ private void dataGridView1_CellContentClick(object sender, DataGridViewCellEvent
237237
if (form.DialogResult == DialogResult.OK)
238238
{
239239
AppEntry returned = form.CurrentAppEntry;
240-
appEntrySaver.ChangeAppEntryByPathAndSave(updatedAppEntry.AppPath, returned);
240+
appEntrySaver.ChangeAppEntryByPath(updatedAppEntry.AppPath, returned);
241241
UpdateGrid();
242242
}
243243

@@ -302,7 +302,7 @@ private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e
302302
//object updatedValue = dataGridView1[e.ColumnIndex, e.RowIndex].Value;
303303

304304
AppEntry updatedAppEntry = appEntryFromRow(e.RowIndex);
305-
appEntrySaver.ChangeAppEntryByPathAndSave(updatedAppEntry.AppPath, updatedAppEntry);
305+
appEntrySaver.ChangeAppEntryByPath(updatedAppEntry.AppPath, updatedAppEntry);
306306

307307
//this should come after replacing the AppEntry
308308
UpdateActionButtons();

0 commit comments

Comments
 (0)