2024-08-07 19:41:42 -05:00
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using LANCommander.Launcher.Services.Extensions;
|
|
|
|
|
|
using LANCommander.Launcher.Services;
|
2024-09-18 20:40:41 -05:00
|
|
|
|
using System.Runtime.InteropServices;
|
2025-11-23 20:54:56 -06:00
|
|
|
|
using LANCommander.Launcher.Data;
|
2025-10-05 23:45:55 -05:00
|
|
|
|
using LANCommander.SDK.Extensions;
|
2025-11-23 20:54:56 -06:00
|
|
|
|
using LANCommander.SDK.Services;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-09-18 20:40:41 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using Serilog;
|
2024-09-25 20:33:06 -05:00
|
|
|
|
using Serilog.Core;
|
|
|
|
|
|
using Serilog.Extensions.Logging;
|
2025-06-15 20:01:17 +02:00
|
|
|
|
using Serilog.Events;
|
2025-11-23 20:54:56 -06:00
|
|
|
|
using YamlDotNet.Serialization;
|
2024-09-18 20:40:41 -05:00
|
|
|
|
|
2025-06-15 20:01:17 +02:00
|
|
|
|
// Map the Microsoft.Extensions.Logging.LogLevel to Serilog.LogEventLevel.
|
|
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
using var logger = new LoggerConfiguration()
|
2025-06-15 20:01:17 +02:00
|
|
|
|
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
|
|
|
|
|
|
.MinimumLevel.Override("Microsoft.AspNetCore.Components", LogEventLevel.Warning)
|
|
|
|
|
|
.MinimumLevel.Override("AntDesign", LogEventLevel.Warning)
|
2024-09-18 20:40:41 -05:00
|
|
|
|
.Enrich.WithProperty("Application", typeof(Program).Assembly.GetName().Name)
|
|
|
|
|
|
.WriteTo.Console()
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
.WriteTo.Seq("http://localhost:5341")
|
|
|
|
|
|
#endif
|
|
|
|
|
|
.CreateLogger();
|
2024-08-07 19:41:42 -05:00
|
|
|
|
|
|
|
|
|
|
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
|
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
builder.Services.AddLogging(loggingBuilder =>
|
|
|
|
|
|
{
|
|
|
|
|
|
loggingBuilder.ClearProviders();
|
|
|
|
|
|
loggingBuilder.AddSerilog(logger);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-05 23:45:55 -05:00
|
|
|
|
builder.Services.AddLANCommanderClient<LANCommander.SDK.Models.Settings>();
|
2025-11-23 20:54:56 -06:00
|
|
|
|
builder.Services.AddLANCommanderLauncher(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
});
|
2024-08-07 19:41:42 -05:00
|
|
|
|
|
|
|
|
|
|
using IHost host = builder.Build();
|
|
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
host.Services.InitializeLANCommander();
|
|
|
|
|
|
|
2025-11-23 20:54:56 -06:00
|
|
|
|
using (var scope = host.Services.CreateScope())
|
|
|
|
|
|
{
|
|
|
|
|
|
var connectionClient = scope.ServiceProvider.GetRequiredService<IConnectionClient>();
|
|
|
|
|
|
var settingsProvider = scope.ServiceProvider.GetRequiredService<SettingsProvider<LANCommander.Launcher.Settings.Settings>>();
|
|
|
|
|
|
var databaseContext = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
|
|
|
|
|
|
var commandLineService = scope.ServiceProvider.GetRequiredService<CommandLineService>();
|
|
|
|
|
|
|
|
|
|
|
|
if (!await connectionClient.PingAsync())
|
|
|
|
|
|
await connectionClient.EnableOfflineModeAsync();
|
2024-08-07 19:41:42 -05:00
|
|
|
|
|
2025-11-23 20:54:56 -06:00
|
|
|
|
if (settingsProvider.CurrentValue.Games.InstallDirectories.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
|
settingsProvider.Update(s =>
|
|
|
|
|
|
{
|
|
|
|
|
|
s.Games.InstallDirectories = [Path.Combine(Path.GetPathRoot(AppContext.BaseDirectory) ?? "C:", "Games")];
|
|
|
|
|
|
});
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
|
settingsProvider.Update(s =>
|
|
|
|
|
|
{
|
|
|
|
|
|
s.Games.InstallDirectories = [Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Games")];
|
|
|
|
|
|
});
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
|
|
|
settingsProvider.Update(s =>
|
|
|
|
|
|
{
|
|
|
|
|
|
s.Games.InstallDirectories = [Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Games")];
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-08-07 19:41:42 -05:00
|
|
|
|
|
2025-11-23 20:54:56 -06:00
|
|
|
|
await databaseContext.Database.MigrateAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await commandLineService.ParseCommandLineAsync(args);
|
|
|
|
|
|
}
|
2025-06-15 20:01:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Maps Microsoft.Extensions.Logging.LogLevel to Serilog.Events.LogEventLevel.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
static LogEventLevel MapLogLevel(LogLevel level)
|
|
|
|
|
|
{
|
|
|
|
|
|
return level switch
|
|
|
|
|
|
{
|
|
|
|
|
|
LogLevel.Trace => LogEventLevel.Verbose,
|
|
|
|
|
|
LogLevel.Debug => LogEventLevel.Debug,
|
|
|
|
|
|
LogLevel.Information => LogEventLevel.Information,
|
|
|
|
|
|
LogLevel.Warning => LogEventLevel.Warning,
|
|
|
|
|
|
LogLevel.Error => LogEventLevel.Error,
|
|
|
|
|
|
LogLevel.Critical => LogEventLevel.Fatal,
|
|
|
|
|
|
// LogLevel.None indicates logging should be disabled.
|
|
|
|
|
|
// Serilog does not have a direct "Off" level so you might choose to
|
|
|
|
|
|
// either bypass logging configuration or set it high enough to ignore messages.
|
|
|
|
|
|
LogLevel.None => LogEventLevel.Fatal,
|
|
|
|
|
|
_ => LogEventLevel.Information
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|