From d73d7fa30e2ff65cb4dea3343080e807430d4e8a Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sat, 7 Aug 2021 16:39:10 +0200 Subject: [PATCH] Load config file, if found, on first use Former-commit-id: e363440118e3f92bcdd3a37e1c5aa239d93a2f63 --- FFMpegCore/FFMpegCore.csproj | 2 +- FFMpegCore/GlobalFFOptions.cs | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index 5f7b969..daf7901 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -26,7 +26,7 @@ Always - + diff --git a/FFMpegCore/GlobalFFOptions.cs b/FFMpegCore/GlobalFFOptions.cs index 358787a..37340cc 100644 --- a/FFMpegCore/GlobalFFOptions.cs +++ b/FFMpegCore/GlobalFFOptions.cs @@ -8,27 +8,20 @@ namespace FFMpegCore public static class GlobalFFOptions { private static readonly string ConfigFile = "ffmpeg.config.json"; + private static FFOptions? _current; - public static FFOptions Current { get; private set; } - static GlobalFFOptions() + public static FFOptions Current { - if (File.Exists(ConfigFile)) - { - Current = JsonSerializer.Deserialize(File.ReadAllText(ConfigFile))!; - } - else - { - Current = new FFOptions(); - } + get { return _current ??= LoadFFOptions(); } } - + public static void Configure(Action optionsAction) { optionsAction?.Invoke(Current); } public static void Configure(FFOptions ffOptions) { - Current = ffOptions ?? throw new ArgumentNullException(nameof(ffOptions)); + _current = ffOptions ?? throw new ArgumentNullException(nameof(ffOptions)); } @@ -48,5 +41,17 @@ private static string GetFFBinaryPath(string name, FFOptions ffOptions) return Path.Combine(ffOptions.BinaryFolder, ffName); } + + private static FFOptions LoadFFOptions() + { + if (File.Exists(ConfigFile)) + { + return JsonSerializer.Deserialize(File.ReadAllText(ConfigFile))!; + } + else + { + return new FFOptions(); + } + } } }