Browse Source

Add optional `ignoreMissingLibraryDir` flag to SettingsManager.Transaction

pull/55/head
Ionite 1 year ago
parent
commit
baff62d326
No known key found for this signature in database
  1. 2
      StabilityMatrix.Core/Services/ISettingsManager.cs
  2. 15
      StabilityMatrix.Core/Services/SettingsManager.cs

2
StabilityMatrix.Core/Services/ISettingsManager.cs

@ -20,7 +20,7 @@ public interface ISettingsManager
SettingsTransaction BeginTransaction();
/// <inheritdoc />
void Transaction(Action<Settings> func);
void Transaction(Action<Settings> func, bool ignoreMissingLibraryDir = false);
/// <inheritdoc />
void Transaction<TValue>(Expression<Func<Settings, TValue>> expression, TValue value);

15
StabilityMatrix.Core/Services/SettingsManager.cs

@ -58,12 +58,25 @@ public class SettingsManager : ISettingsManager
/// <inheritdoc />
public SettingsTransaction BeginTransaction()
{
if (!IsLibraryDirSet)
{
throw new InvalidOperationException("LibraryDir not set when BeginTransaction was called");
}
return new SettingsTransaction(this, SaveSettingsAsync);
}
/// <inheritdoc />
public void Transaction(Action<Settings> func)
public void Transaction(Action<Settings> func, bool ignoreMissingLibraryDir = false)
{
if (!IsLibraryDirSet)
{
if (ignoreMissingLibraryDir)
{
func(Settings);
return;
}
throw new InvalidOperationException("LibraryDir not set when Transaction was called");
}
using var transaction = BeginTransaction();
func(transaction.Settings);
transaction.Dispose();

Loading…
Cancel
Save