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. 4
      StabilityMatrix.Core/Services/ISettingsManager.cs
  2. 15
      StabilityMatrix.Core/Services/SettingsManager.cs

4
StabilityMatrix.Core/Services/ISettingsManager.cs

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

15
StabilityMatrix.Core/Services/SettingsManager.cs

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

Loading…
Cancel
Save