Separate OF DL and OF DL GUI projects

This commit is contained in:
whimsical-c4lic0 2026-02-13 15:17:22 -06:00
parent 712f11dc4b
commit 5af26156c7
4 changed files with 36 additions and 48 deletions

View File

@ -1,13 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>OF_DL.Gui</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<ApplicationIcon>Icon\download.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Content Include="Icon\download.ico"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OF DL.Core\OF DL.Core.csproj"/>
</ItemGroup>
@ -19,10 +25,25 @@
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.3"/>
<PackageReference Include="PuppeteerSharp" Version="20.2.6"/>
<PackageReference Include="Serilog" Version="4.3.1"/>
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0"/>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.10"/>
</ItemGroup>
<ItemGroup>
<None Update="auth.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="config.conf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="rules.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,12 +1,23 @@
using Avalonia;
using Microsoft.Extensions.DependencyInjection;
using OF_DL.Services;
using Serilog;
namespace OF_DL.Gui;
public static class GuiLauncher
public static class Program
{
public static void Run(string[] args)
public static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
ServiceCollection services = new();
services.AddSingleton<ILoggingService, LoggingService>();
ServiceProvider tempProvider = services.BuildServiceProvider();
ILoggingService loggingService = tempProvider.GetRequiredService<ILoggingService>();
Log.Information("Starting OF DL GUI");
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
private static AppBuilder BuildAvaloniaApp() =>

View File

@ -15,7 +15,6 @@
<ItemGroup>
<ProjectReference Include="..\OF DL.Core\OF DL.Core.csproj"/>
<ProjectReference Include="..\OF DL.Gui\OF DL.Gui.csproj"/>
</ItemGroup>
<ItemGroup>

View File

@ -1,7 +1,6 @@
using System.Text.RegularExpressions;
using Microsoft.Extensions.DependencyInjection;
using OF_DL.CLI;
using OF_DL.Gui;
using OF_DL.Models;
using OF_DL.Enumerations;
using OF_DL.Models.Config;
@ -15,9 +14,6 @@ namespace OF_DL;
public class Program(IServiceProvider serviceProvider)
{
private const string CliFlag = "--cli";
private const string NonInteractiveFlag = "--non-interactive";
private async Task LoadAuthFromBrowser()
{
IAuthService authService = serviceProvider.GetRequiredService<IAuthService>();
@ -69,58 +65,19 @@ public class Program(IServiceProvider serviceProvider)
await authService.SaveToFileAsync();
}
[STAThread]
public static async Task Main(string[] args)
{
bool runCli = await ShouldRunCliModeAsync(args);
string[] cleanArgs = args.Where(a => !a.Equals(CliFlag, StringComparison.OrdinalIgnoreCase)).ToArray();
if (!runCli)
{
GuiLauncher.Run(cleanArgs);
return;
}
AnsiConsole.Write(new FigletText("Welcome to OF-DL").Color(Color.Red));
AnsiConsole.Markup("Documentation: [link]https://docs.ofdl.tools/[/]\n");
AnsiConsole.Markup("Discord server: [link]https://discord.com/invite/6bUW8EJ53j[/]\n\n");
ServiceCollection services = await ConfigureServices(cleanArgs);
ServiceCollection services = await ConfigureServices(args);
ServiceProvider serviceProvider = services.BuildServiceProvider();
// Get the Program instance and run
Program program = serviceProvider.GetRequiredService<Program>();
await program.RunAsync();
}
private static async Task<bool> ShouldRunCliModeAsync(string[] args)
{
if (args.Any(a => a.Equals(CliFlag, StringComparison.OrdinalIgnoreCase)))
{
return true;
}
if (args.Any(a => a.Equals(NonInteractiveFlag, StringComparison.OrdinalIgnoreCase)))
{
return true;
}
ServiceCollection services = new();
services.AddSingleton<ILoggingService, LoggingService>();
services.AddSingleton<IConfigService, ConfigService>();
await using ServiceProvider provider = services.BuildServiceProvider();
IConfigService configService = provider.GetRequiredService<IConfigService>();
bool loaded = await configService.LoadConfigurationAsync(args);
if (!loaded)
{
return false;
}
return configService.IsCliNonInteractive || configService.CurrentConfig.NonInteractiveMode;
}
private static async Task<ServiceCollection> ConfigureServices(string[] args)
{
// Set up dependency injection with LoggingService and ConfigService