mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Load config file, if found, on first use
This commit is contained in:
parent
0efaf686f3
commit
e363440118
2 changed files with 18 additions and 13 deletions
|
@ -26,7 +26,7 @@
|
||||||
<Content Include="FFMPEG\bin\**\*">
|
<Content Include="FFMPEG\bin\**\*">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<None Include="..\README.md" Pack="true" PackagePath="\"/>
|
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -8,27 +8,20 @@ namespace FFMpegCore
|
||||||
public static class GlobalFFOptions
|
public static class GlobalFFOptions
|
||||||
{
|
{
|
||||||
private static readonly string ConfigFile = "ffmpeg.config.json";
|
private static readonly string ConfigFile = "ffmpeg.config.json";
|
||||||
|
private static FFOptions? _current;
|
||||||
|
|
||||||
public static FFOptions Current { get; private set; }
|
public static FFOptions Current
|
||||||
static GlobalFFOptions()
|
|
||||||
{
|
{
|
||||||
if (File.Exists(ConfigFile))
|
get { return _current ??= LoadFFOptions(); }
|
||||||
{
|
|
||||||
Current = JsonSerializer.Deserialize<FFOptions>(File.ReadAllText(ConfigFile))!;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Current = new FFOptions();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Configure(Action<FFOptions> optionsAction)
|
public static void Configure(Action<FFOptions> optionsAction)
|
||||||
{
|
{
|
||||||
optionsAction?.Invoke(Current);
|
optionsAction?.Invoke(Current);
|
||||||
}
|
}
|
||||||
public static void Configure(FFOptions ffOptions)
|
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);
|
return Path.Combine(ffOptions.BinaryFolder, ffName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static FFOptions LoadFFOptions()
|
||||||
|
{
|
||||||
|
if (File.Exists(ConfigFile))
|
||||||
|
{
|
||||||
|
return JsonSerializer.Deserialize<FFOptions>(File.ReadAllText(ConfigFile))!;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new FFOptions();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue