mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-02-04 11:11:33 -05:00
- Add `LIBATION_FILES_DIR` environment variable to specify LibationFiles directory instead of appsettings.json - OptionsBase supports overriding setting - Added `EphemeralSettings` which are loaded from Settings.json once and can be modified with the `--override` command parameter - Added `get-setting` command - Prints (editable) settings and their values. Prints specified settings, or all settings if none specified - `--listEnumValues` option will list all names for a speficied enum-type settings. If no setting names are specified, prints all enum values for all enum settings. - Prints in a text-based table or bare with `-b` switch - Added `get-license` command which requests a content license and prints it as a json to stdout - Improved `liberate` command - Added `-force` option to force liberation without validation. - Added support to download with a license file supplied to stdin - Improve startup performance when downloading explicit ASIN(s) - Fix long-standing bug where cover art was not being downloading
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using FileManager;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
#nullable enable
|
|
namespace LibationFileManager;
|
|
|
|
internal class EphemeralDictionary : IJsonBackedDictionary
|
|
{
|
|
private JObject JsonObject { get; }
|
|
|
|
public EphemeralDictionary()
|
|
{
|
|
JsonObject = new();
|
|
}
|
|
public EphemeralDictionary(JObject dataStore)
|
|
{
|
|
JsonObject = dataStore;
|
|
}
|
|
|
|
public bool Exists(string propertyName)
|
|
=> JsonObject.ContainsKey(propertyName);
|
|
public string? GetString(string propertyName, string? defaultValue = null)
|
|
=> JsonObject[propertyName]?.Value<string>() ?? defaultValue;
|
|
public T? GetNonString<T>(string propertyName, T? defaultValue = default)
|
|
=> GetObject(propertyName) is object obj ? IJsonBackedDictionary.UpCast<T>(obj) : defaultValue;
|
|
public object? GetObject(string propertyName)
|
|
=> JsonObject[propertyName]?.Value<object>();
|
|
public void SetString(string propertyName, string? newValue)
|
|
=> JsonObject[propertyName] = newValue;
|
|
public void SetNonString(string propertyName, object? newValue)
|
|
=> JsonObject[propertyName] = newValue is null ? null : JToken.FromObject(newValue);
|
|
public bool RemoveProperty(string propertyName)
|
|
=> JsonObject.Remove(propertyName);
|
|
public string? GetStringFromJsonPath(string jsonPath)
|
|
=> JsonObject.SelectToken(jsonPath)?.Value<string>();
|
|
public bool SetWithJsonPath(string jsonPath, string propertyName, string? newValue, bool suppressLogging = false)
|
|
{
|
|
if (JsonObject.SelectToken(jsonPath) is JToken token && token?[propertyName] is not null)
|
|
{
|
|
token[propertyName] = newValue;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
} |