2025-08-21 18:16:21 -05:00
|
|
|
|
using LANCommander.Launcher.Services;
|
2024-06-05 01:21:31 -05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-06-12 23:20:31 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-09-11 00:24:34 -05:00
|
|
|
|
using Serilog;
|
2025-06-15 20:01:17 +02:00
|
|
|
|
using Serilog.Events;
|
2024-06-11 02:05:15 -05:00
|
|
|
|
using System.Runtime.InteropServices;
|
2025-11-06 20:15:05 -06:00
|
|
|
|
using LANCommander.Launcher.Data;
|
2025-10-25 22:00:50 -05:00
|
|
|
|
using LANCommander.Launcher.Enums;
|
2025-09-29 19:49:09 -05:00
|
|
|
|
using LANCommander.Launcher.Models;
|
2025-10-02 19:41:47 -05:00
|
|
|
|
using LANCommander.SDK.Services;
|
2025-11-06 20:15:05 -06:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-05-09 20:44:40 -05:00
|
|
|
|
|
2024-08-04 17:53:19 -05:00
|
|
|
|
namespace LANCommander.Launcher
|
2024-05-09 20:44:40 -05:00
|
|
|
|
{
|
2024-06-05 01:21:31 -05:00
|
|
|
|
class Program
|
2024-05-09 20:44:40 -05:00
|
|
|
|
{
|
2024-06-05 01:21:31 -05:00
|
|
|
|
[STAThread]
|
2024-08-07 01:20:31 -05:00
|
|
|
|
static void Main(string[] args)
|
2024-05-09 20:44:40 -05:00
|
|
|
|
{
|
2025-06-15 20:01:17 +02:00
|
|
|
|
// Map the Microsoft.Extensions.Logging.LogLevel to Serilog.LogEventLevel.
|
2025-09-29 19:49:09 -05:00
|
|
|
|
var serilogLogLevel = MapLogLevel(LogLevel.Debug);
|
2025-06-15 20:01:17 +02:00
|
|
|
|
|
2024-09-11 00:24:34 -05:00
|
|
|
|
using var Logger = new LoggerConfiguration()
|
2025-06-15 20:01:17 +02:00
|
|
|
|
.MinimumLevel.Is(serilogLogLevel)
|
|
|
|
|
|
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
|
|
|
|
|
|
.MinimumLevel.Override("Microsoft.AspNetCore.Components", LogEventLevel.Warning)
|
|
|
|
|
|
.MinimumLevel.Override("AntDesign", LogEventLevel.Warning)
|
2024-09-11 02:05:24 -05:00
|
|
|
|
.Enrich.WithProperty("Application", typeof(Program).Assembly.GetName().Name)
|
2025-09-29 19:49:09 -05:00
|
|
|
|
//.WriteTo.File(Path.Combine(settings.Debug.LoggingPath, "log-.txt"), rollingInterval: settings.Debug.LoggingArchivePeriod)
|
2024-09-11 02:05:24 -05:00
|
|
|
|
#if DEBUG
|
|
|
|
|
|
.WriteTo.Seq("http://localhost:5341")
|
|
|
|
|
|
#endif
|
2024-09-11 00:24:34 -05:00
|
|
|
|
.CreateLogger();
|
2025-09-29 19:49:09 -05:00
|
|
|
|
|
|
|
|
|
|
Logger?.Information("Starting launcher | Version: {Version}", UpdateService.GetCurrentVersion());
|
2024-07-28 17:41:43 -05:00
|
|
|
|
|
2025-10-25 22:00:50 -05:00
|
|
|
|
WindowService.CreateWindow<UI.App_Main>(new WindowOptions
|
2024-06-05 01:21:31 -05:00
|
|
|
|
{
|
2025-10-25 22:00:50 -05:00
|
|
|
|
Title = "LANCommander",
|
|
|
|
|
|
Type = WindowType.Main
|
2025-11-03 23:24:47 -06:00
|
|
|
|
}, null, async (app) =>
|
|
|
|
|
|
{
|
2025-11-09 14:30:31 -06:00
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
|
|
|
|
{
|
|
|
|
|
|
var connectionClient = scope.ServiceProvider.GetService<IConnectionClient>();
|
2025-11-23 20:53:45 -06:00
|
|
|
|
var settingsProvider = scope.ServiceProvider.GetService<SettingsProvider<Settings.Settings>>();
|
2025-11-09 14:30:31 -06:00
|
|
|
|
var databaseContext = scope.ServiceProvider.GetService<DatabaseContext>();
|
2025-11-03 23:24:47 -06:00
|
|
|
|
|
2025-11-09 14:30:31 -06:00
|
|
|
|
if (!(await connectionClient.PingAsync()))
|
|
|
|
|
|
await connectionClient.EnableOfflineModeAsync();
|
2025-11-06 20:15:05 -06:00
|
|
|
|
|
2025-11-09 14:30:31 -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")];
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-11-06 20:15:05 -06:00
|
|
|
|
|
2025-11-09 14:30:31 -06:00
|
|
|
|
await databaseContext.Database.MigrateAsync();
|
|
|
|
|
|
}
|
2025-11-03 23:24:47 -06:00
|
|
|
|
}, args);
|
2024-08-06 18:24:44 -05:00
|
|
|
|
}
|
2024-09-17 19:48:23 -05:00
|
|
|
|
|
2025-06-15 20:01:17 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Maps Microsoft.Extensions.Logging.LogLevel to Serilog.Events.LogEventLevel.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private 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
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2024-05-09 20:44:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|