Skip to content

Commit e83baf4

Browse files
committed
WIP: Update IStorageBackend.cs and JsonStorageBackend.cs to support key scopes.
1 parent 8c1d520 commit e83baf4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/NexusMods.Backend/Settings/JsonStorageBackend.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ private static AbsolutePath GetConfigsFolderPath(IFileSystem fileSystem)
4646
return fileSystem.GetKnownPath(baseKnownPath).Combine(baseDirectoryName);
4747
}
4848

49-
private AbsolutePath GetConfigPath<T>()
49+
private AbsolutePath GetConfigPath<T>(string? key)
5050
{
5151
var typeName = typeof(T).FullName ?? typeof(T).Name;
52-
var fileName = $"{typeName}.json";
52+
var fileName = string.IsNullOrWhiteSpace(key) ? $"{typeName}.json" : $"{typeName}_{key}.json";
5353
return _configDirectory.Combine(fileName);
5454
}
5555

@@ -80,17 +80,17 @@ private void Serialize<T>(Stream stream ,T value) where T : class
8080
}
8181

8282
/// <inheritdoc/>
83-
public void Save<T>(T value) where T : class, ISettings, new()
83+
public void Save<T>(T value, string? key) where T : class, ISettings, new()
8484
{
85-
var configPath = GetConfigPath<T>();
85+
var configPath = GetConfigPath<T>(key);
8686
using var stream = configPath.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.None);
8787
Serialize(stream, value);
8888
}
8989

9090
/// <inheritdoc/>
91-
public T? Load<T>() where T : class, ISettings, new()
91+
public T? Load<T>(string? key) where T : class, ISettings, new()
9292
{
93-
var configPath = GetConfigPath<T>();
93+
var configPath = GetConfigPath<T>(key);
9494
if (!configPath.FileExists) return null;
9595

9696
using var stream = configPath.Open(FileMode.Open, FileAccess.Read, FileShare.Read);

src/NexusMods.Sdk/Settings/Backend/IStorageBackend.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IStorageBackend : IBaseStorageBackend, IDisposable
1212
/// <summary>
1313
/// Saves the given settings object to the storage backend synchronously.
1414
/// </summary>
15-
void Save<T>(T value) where T : class, ISettings, new();
15+
void Save<T>(T value, string? key) where T : class, ISettings, new();
1616

1717
/// <summary>
1818
/// Loads the given settings type from the storage backend synchronously.
@@ -21,5 +21,5 @@ public interface IStorageBackend : IBaseStorageBackend, IDisposable
2121
/// Either the loaded value or <c>null</c> if the loading failed
2222
/// or the storage backend doesn't contain this value.
2323
/// </returns>
24-
T? Load<T>() where T : class, ISettings, new();
24+
T? Load<T>(string? key) where T : class, ISettings, new();
2525
}

0 commit comments

Comments
 (0)