forked from sim0n00ps/OF-DL
Move OS and system environment checks to a helper class
This commit is contained in:
parent
3b8e575a21
commit
4d3ae0e19a
@ -29,7 +29,7 @@ most important change points.
|
||||
entities, and mapping helpers.
|
||||
- `OF DL.Core/Widevine/` implements Widevine CDM handling and key derivation.
|
||||
- `OF DL.Core/Helpers/`, `OF DL.Core/Utils/`, `OF DL.Core/Crypto/`, `OF DL.Core/Enumerations/` contain shared core
|
||||
logic.
|
||||
logic. `OF DL.Core/Helpers/EnvironmentHelper.cs` centralizes environment checks (Docker and Windows).
|
||||
- `docs/` and `mkdocs.yml` define the documentation site.
|
||||
- `site/` is generated MkDocs output and should not be edited by hand.
|
||||
- `docker/` contains container entrypoint and supervisor configuration.
|
||||
@ -239,6 +239,7 @@ cookies/user-agent. Output is written to `{filename}_source.mp4`, then moved and
|
||||
- `OF DL.Core/Widevine/` for CDM key generation and license parsing.
|
||||
- `OF DL.Core/Models/Config/Config.cs` and `OF DL.Core/Services/ConfigService.cs` for config shape and parsing.
|
||||
- `OF DL.Core/Services/AuthService.cs` for user-facing authentication behavior and browser login flow.
|
||||
- `OF DL.Core/Helpers/EnvironmentHelper.cs` for shared Docker/Windows runtime checks.
|
||||
- `docs/` for public documentation; update docs whenever user-facing behavior or configuration changes.
|
||||
|
||||
## Documentation updates for common changes:
|
||||
|
||||
14
OF DL.Core/Helpers/EnvironmentHelper.cs
Normal file
14
OF DL.Core/Helpers/EnvironmentHelper.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace OF_DL.Helpers;
|
||||
|
||||
public static class EnvironmentHelper
|
||||
{
|
||||
private const string DockerEnvironmentVariableName = "OFDL_DOCKER";
|
||||
|
||||
public static bool IsRunningInDocker()
|
||||
{
|
||||
string? dockerValue = Environment.GetEnvironmentVariable(DockerEnvironmentVariableName);
|
||||
return string.Equals(dockerValue, "true", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static bool IsRunningOnWindows() => OperatingSystem.IsWindows();
|
||||
}
|
||||
@ -2,6 +2,7 @@ using System.Text.RegularExpressions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Playwright;
|
||||
using Newtonsoft.Json;
|
||||
using OF_DL.Helpers;
|
||||
using OF_DL.Models;
|
||||
using Serilog;
|
||||
using UserEntities = OF_DL.Models.Entities.Users;
|
||||
@ -79,7 +80,7 @@ public class AuthService(IServiceProvider serviceProvider) : IAuthService
|
||||
|
||||
try
|
||||
{
|
||||
bool runningInDocker = Environment.GetEnvironmentVariable("OFDL_DOCKER") != null;
|
||||
bool runningInDocker = EnvironmentHelper.IsRunningInDocker();
|
||||
await SetupBrowser(runningInDocker);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@ -412,14 +412,14 @@ public class DownloadService(
|
||||
{
|
||||
string firstFullPath = Path.GetFullPath(firstPath);
|
||||
string secondFullPath = Path.GetFullPath(secondPath);
|
||||
StringComparison comparison = OperatingSystem.IsWindows()
|
||||
StringComparison comparison = EnvironmentHelper.IsRunningOnWindows()
|
||||
? StringComparison.OrdinalIgnoreCase
|
||||
: StringComparison.Ordinal;
|
||||
return string.Equals(firstFullPath, secondFullPath, comparison);
|
||||
}
|
||||
catch
|
||||
{
|
||||
StringComparison comparison = OperatingSystem.IsWindows()
|
||||
StringComparison comparison = EnvironmentHelper.IsRunningOnWindows()
|
||||
? StringComparison.OrdinalIgnoreCase
|
||||
: StringComparison.Ordinal;
|
||||
return string.Equals(firstPath, secondPath, comparison);
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json;
|
||||
using OF_DL.Helpers;
|
||||
using OF_DL.Models;
|
||||
@ -24,9 +23,9 @@ public class StartupService(IConfigService configService, IAuthService authServi
|
||||
// OS validation
|
||||
OperatingSystem os = Environment.OSVersion;
|
||||
result.OsVersionString = os.VersionString;
|
||||
Log.Debug($"Operating system information: {os.VersionString}");
|
||||
Log.Debug("Operating system information: {OsVersionString}", os.VersionString);
|
||||
|
||||
if (os.Platform == PlatformID.Win32NT && os.Version.Major < 10)
|
||||
if (EnvironmentHelper.IsRunningOnWindows() && os.Version.Major < 10)
|
||||
{
|
||||
result.IsWindowsVersionValid = false;
|
||||
Log.Error("Windows version prior to 10.x: {0}", os.VersionString);
|
||||
@ -40,7 +39,7 @@ public class StartupService(IConfigService configService, IAuthService authServi
|
||||
if (result is { FfmpegFound: true, FfmpegPath: not null })
|
||||
{
|
||||
// Escape backslashes for Windows
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
|
||||
if (EnvironmentHelper.IsRunningOnWindows() &&
|
||||
result.FfmpegPath.Contains(@":\") &&
|
||||
!result.FfmpegPath.Contains(@":\\"))
|
||||
{
|
||||
@ -55,7 +54,7 @@ public class StartupService(IConfigService configService, IAuthService authServi
|
||||
if (result is { FfprobeFound: true, FfprobePath: not null })
|
||||
{
|
||||
// Escape backslashes for Windows
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
|
||||
if (EnvironmentHelper.IsRunningOnWindows() &&
|
||||
result.FfprobePath.Contains(@":\") &&
|
||||
!result.FfprobePath.Contains(@":\\"))
|
||||
{
|
||||
@ -211,7 +210,7 @@ public class StartupService(IConfigService configService, IAuthService authServi
|
||||
string? ffmpegDirectory = Path.GetDirectoryName(result.FfmpegPath);
|
||||
if (!string.IsNullOrEmpty(ffmpegDirectory))
|
||||
{
|
||||
string ffprobeFileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
string ffprobeFileName = EnvironmentHelper.IsRunningOnWindows()
|
||||
? "ffprobe.exe"
|
||||
: "ffprobe";
|
||||
string inferredFfprobePath = Path.Combine(ffmpegDirectory, ffprobeFileName);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using Avalonia;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OF_DL.Helpers;
|
||||
using OF_DL.Services;
|
||||
using Serilog;
|
||||
|
||||
@ -21,11 +22,11 @@ public static class Program
|
||||
|
||||
Log.Information("Starting OF DL GUI");
|
||||
|
||||
// Check if running in Docker and print message
|
||||
string? ofdlDocker = Environment.GetEnvironmentVariable("OFDL_DOCKER");
|
||||
if (string.Equals(ofdlDocker, "true", StringComparison.OrdinalIgnoreCase))
|
||||
// Check if running in Docker and print a message
|
||||
if (EnvironmentHelper.IsRunningInDocker())
|
||||
{
|
||||
Console.WriteLine("In your web browser, navigate to the port forwarded from your docker container. For instance, if your docker run command included \"-p 8080:8080\", open your web browser to \"http://localhost:8080\".");
|
||||
Console.WriteLine(
|
||||
"In your web browser, navigate to the port forwarded from your docker container. For instance, if your docker run command included \"-p 8080:8080\", open your web browser to \"http://localhost:8080\".");
|
||||
}
|
||||
|
||||
BuildAvaloniaApp()
|
||||
|
||||
@ -3,6 +3,7 @@ using System.Diagnostics;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform;
|
||||
using OF_DL.Helpers;
|
||||
|
||||
namespace OF_DL.Gui.Views;
|
||||
|
||||
@ -65,11 +66,8 @@ public partial class FaqWindow : Window
|
||||
{
|
||||
Entries.Clear();
|
||||
|
||||
bool isDocker = string.Equals(
|
||||
Environment.GetEnvironmentVariable("OFDL_DOCKER"),
|
||||
"true",
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
bool isWindows = OperatingSystem.IsWindows();
|
||||
bool isDocker = EnvironmentHelper.IsRunningInDocker();
|
||||
bool isWindows = EnvironmentHelper.IsRunningOnWindows();
|
||||
|
||||
Entries.Add(new FaqEntry(
|
||||
"Why are some users missing from the users list?",
|
||||
|
||||
@ -7,6 +7,7 @@ using Avalonia.Platform;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.VisualTree;
|
||||
using Avalonia.Threading;
|
||||
using OF_DL.Helpers;
|
||||
using OF_DL.Gui.ViewModels;
|
||||
|
||||
namespace OF_DL.Gui.Views;
|
||||
@ -28,8 +29,7 @@ public partial class MainWindow : Window
|
||||
Icon = new WindowIcon(AssetLoader.Open(new Uri("avares://OF DL.Gui/Assets/icon.ico")));
|
||||
|
||||
// Start maximized if running in Docker
|
||||
string? ofdlDocker = Environment.GetEnvironmentVariable("OFDL_DOCKER");
|
||||
if (string.Equals(ofdlDocker, "true", StringComparison.OrdinalIgnoreCase))
|
||||
if (EnvironmentHelper.IsRunningInDocker())
|
||||
{
|
||||
WindowState = WindowState.Maximized;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using OF_DL.CLI;
|
||||
using OF_DL.Models;
|
||||
using OF_DL.Enumerations;
|
||||
using OF_DL.Helpers;
|
||||
using OF_DL.Models.Config;
|
||||
using OF_DL.Models.Downloads;
|
||||
using OF_DL.Models.Entities.Users;
|
||||
@ -17,14 +18,13 @@ public class Program(IServiceProvider serviceProvider)
|
||||
private async Task LoadAuthFromBrowser()
|
||||
{
|
||||
IAuthService authService = serviceProvider.GetRequiredService<IAuthService>();
|
||||
bool runningInDocker = Environment.GetEnvironmentVariable("OFDL_DOCKER") != null;
|
||||
|
||||
// Show the initial message
|
||||
AnsiConsole.MarkupLine("[yellow]Downloading dependencies. Please wait ...[/]");
|
||||
|
||||
// Show instructions based on the environment
|
||||
await Task.Delay(5000);
|
||||
if (runningInDocker)
|
||||
if (EnvironmentHelper.IsRunningInDocker())
|
||||
{
|
||||
AnsiConsole.MarkupLine(
|
||||
"[yellow]In your web browser, navigate to the port forwarded from your docker container.[/]");
|
||||
@ -846,8 +846,8 @@ public class Program(IServiceProvider serviceProvider)
|
||||
private static void DisplayStartupResult(StartupResult result)
|
||||
{
|
||||
// OS
|
||||
if (result.IsWindowsVersionValid && result.OsVersionString != null &&
|
||||
Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
if (result is { IsWindowsVersionValid: true, OsVersionString: not null } &&
|
||||
EnvironmentHelper.IsRunningOnWindows())
|
||||
{
|
||||
AnsiConsole.Markup("[green]Valid version of Windows found.\n[/]");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user