2024-08-06 18:24:44 -05:00
|
|
|
|
using CommandLine;
|
|
|
|
|
|
using CommandLine.Text;
|
|
|
|
|
|
using Emzi0767.NtfsDataStreams;
|
2024-08-04 17:53:19 -05:00
|
|
|
|
using LANCommander.Launcher.Data;
|
2024-08-06 18:24:44 -05:00
|
|
|
|
using LANCommander.Launcher.Models;
|
2024-08-04 17:53:19 -05:00
|
|
|
|
using LANCommander.Launcher.Services;
|
2024-08-07 18:48:13 -05:00
|
|
|
|
using LANCommander.Launcher.Services.Extensions;
|
2024-10-06 17:11:35 -05:00
|
|
|
|
using LANCommander.SDK;
|
2024-05-20 19:42:31 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
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-06-05 01:21:31 -05:00
|
|
|
|
using Photino.Blazor;
|
|
|
|
|
|
using Photino.Blazor.CustomWindow.Extensions;
|
2024-06-11 02:05:15 -05:00
|
|
|
|
using Photino.NET;
|
2024-09-11 00:24:34 -05:00
|
|
|
|
using Serilog;
|
2025-06-15 20:01:17 +02:00
|
|
|
|
using Serilog.Events;
|
2024-09-25 20:27:23 -05:00
|
|
|
|
using Serilog.Extensions.Logging;
|
2024-09-18 20:40:41 -05:00
|
|
|
|
using System;
|
2024-06-11 02:05:15 -05:00
|
|
|
|
using System.Diagnostics;
|
2024-07-28 18:32:45 -05:00
|
|
|
|
using System.IO;
|
2024-08-06 18:24:44 -05:00
|
|
|
|
using System.Management.Automation.Language;
|
2024-07-08 17:46:58 -05:00
|
|
|
|
using System.Reflection;
|
2024-06-11 02:05:15 -05:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
using System.Text;
|
2024-06-08 02:58:18 -05:00
|
|
|
|
using System.Web;
|
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
|
|
|
|
{
|
2024-09-11 00:24:34 -05:00
|
|
|
|
var settings = SettingService.GetSettings();
|
|
|
|
|
|
|
2025-06-15 20:01:17 +02:00
|
|
|
|
// Map the Microsoft.Extensions.Logging.LogLevel to Serilog.LogEventLevel.
|
|
|
|
|
|
var serilogLogLevel = MapLogLevel(settings.Debug.LoggingLevel);
|
|
|
|
|
|
|
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)
|
2024-09-11 00:24:34 -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();
|
|
|
|
|
|
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
var localizationService = new LocalizationService();
|
|
|
|
|
|
Logger?.Information(localizationService.GetString("StartingUpLauncher", UpdateService.GetCurrentVersion()));
|
|
|
|
|
|
Logger?.Debug(localizationService.GetString("LoadingSettingsFromFile"));
|
2024-07-28 17:41:43 -05:00
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
var builder = PhotinoBlazorAppBuilder.CreateDefault(args);
|
2024-05-09 20:44:40 -05:00
|
|
|
|
|
2024-07-16 00:18:41 -05:00
|
|
|
|
#region Configure Logging
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
Logger?.Debug(localizationService.GetString("ConfiguringLogging"));
|
2024-07-28 17:41:43 -05:00
|
|
|
|
|
2024-06-12 23:20:31 -05:00
|
|
|
|
builder.Services.AddLogging(loggingBuilder =>
|
|
|
|
|
|
{
|
|
|
|
|
|
loggingBuilder.ClearProviders();
|
|
|
|
|
|
loggingBuilder.SetMinimumLevel(settings.Debug.LoggingLevel);
|
2024-09-11 00:24:34 -05:00
|
|
|
|
loggingBuilder.AddSerilog(Logger);
|
2024-06-12 23:20:31 -05:00
|
|
|
|
});
|
2024-07-16 00:18:41 -05:00
|
|
|
|
#endregion
|
2025-08-06 19:37:11 -05:00
|
|
|
|
|
2024-08-06 18:24:44 -05:00
|
|
|
|
builder.RootComponents.Add<App>("app");
|
2024-06-05 01:21:31 -05:00
|
|
|
|
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
Logger?.Debug(localizationService.GetString("RegisteringServices"));
|
2024-07-28 17:41:43 -05:00
|
|
|
|
|
2025-08-06 19:37:11 -05:00
|
|
|
|
#region Aspire
|
|
|
|
|
|
builder.Services.AddServiceDiscovery();
|
|
|
|
|
|
builder.Services.ConfigureHttpClientDefaults(http =>
|
|
|
|
|
|
{
|
|
|
|
|
|
http.AddStandardResilienceHandler();
|
|
|
|
|
|
http.AddServiceDiscovery();
|
|
|
|
|
|
});
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-08-06 18:24:44 -05:00
|
|
|
|
builder.Services.AddCustomWindow();
|
|
|
|
|
|
builder.Services.AddAntDesign();
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
builder.Services.AddSingleton<LocalizationService>();
|
2024-09-25 20:27:23 -05:00
|
|
|
|
builder.Services.AddLANCommander(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
options.ServerAddress = settings.Authentication.ServerAddress;
|
|
|
|
|
|
options.Logger = new SerilogLoggerFactory(Logger).CreateLogger<SDK.Client>();
|
|
|
|
|
|
});
|
2024-05-09 20:44:40 -05:00
|
|
|
|
|
2024-07-28 17:41:43 -05:00
|
|
|
|
#region Build Application
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
Logger?.Debug(localizationService.GetString("BuildingApplication"));
|
2024-07-28 17:41:43 -05:00
|
|
|
|
|
2024-05-21 20:51:09 -05:00
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
app.MainWindow
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
.SetTitle(localizationService.GetString("AppTitle"))
|
2024-06-05 01:21:31 -05:00
|
|
|
|
.SetChromeless(true)
|
2024-06-08 02:58:18 -05:00
|
|
|
|
.RegisterCustomSchemeHandler("media", (object sender, string scheme, string url, out string contentType) =>
|
|
|
|
|
|
{
|
2024-10-06 17:11:35 -05:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var uri = new Uri(url);
|
|
|
|
|
|
|
|
|
|
|
|
var query = HttpUtility.ParseQueryString(uri.Query);
|
|
|
|
|
|
|
|
|
|
|
|
var id = query["id"];
|
|
|
|
|
|
var fileId = query["fileId"];
|
|
|
|
|
|
var crc32 = query["crc32"];
|
|
|
|
|
|
var mime = query["mime"];
|
|
|
|
|
|
|
|
|
|
|
|
contentType = mime;
|
2024-06-08 02:58:18 -05:00
|
|
|
|
|
2024-10-06 17:11:35 -05:00
|
|
|
|
var filePath = Path.Combine(MediaService.GetStoragePath(), $"{fileId}-{crc32}");
|
2024-06-08 02:58:18 -05:00
|
|
|
|
|
2024-10-06 17:11:35 -05:00
|
|
|
|
if (File.Exists(filePath))
|
|
|
|
|
|
return new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
else
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
Logger?.Warning(ex, localizationService.GetString("ImageNotFoundLocally"));
|
2024-10-06 17:11:35 -05:00
|
|
|
|
|
|
|
|
|
|
contentType = "";
|
|
|
|
|
|
}
|
2024-06-08 02:58:18 -05:00
|
|
|
|
|
2024-10-06 17:11:35 -05:00
|
|
|
|
return null;
|
2024-06-11 02:05:15 -05:00
|
|
|
|
})
|
|
|
|
|
|
.RegisterWebMessageReceivedHandler(async (object sender, string message) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (message)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "import":
|
2024-06-28 19:24:50 -05:00
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
|
|
|
|
{
|
|
|
|
|
|
var importService = scope.ServiceProvider.GetService<ImportService>();
|
|
|
|
|
|
|
|
|
|
|
|
var window = (PhotinoWindow)sender;
|
|
|
|
|
|
|
|
|
|
|
|
await importService.ImportAsync();
|
2024-06-11 02:05:15 -05:00
|
|
|
|
|
2024-06-28 19:24:50 -05:00
|
|
|
|
window.SendWebMessage("importComplete");
|
|
|
|
|
|
}
|
2024-06-11 02:05:15 -05:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2024-06-08 02:58:18 -05:00
|
|
|
|
});
|
2024-07-28 17:41:43 -05:00
|
|
|
|
#endregion
|
2024-06-05 01:21:31 -05:00
|
|
|
|
|
2024-09-17 19:48:23 -05:00
|
|
|
|
#region Restore Window Positioning
|
|
|
|
|
|
if (settings.Window.Maximized)
|
|
|
|
|
|
app.MainWindow.SetMaximized(true);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (settings.Window.Width != 0 && settings.Window.Height != 0)
|
2025-02-04 18:39:29 -06:00
|
|
|
|
{
|
2024-09-17 19:48:23 -05:00
|
|
|
|
app.MainWindow.SetSize(settings.Window.Width, settings.Window.Height);
|
2025-02-04 18:39:29 -06:00
|
|
|
|
app.MainWindow.SetLocation(new System.Drawing.Point(settings.Window.X, settings.Window.Y));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
app.MainWindow.SetSize(1024, 768);
|
|
|
|
|
|
app.MainWindow.Center();
|
|
|
|
|
|
}
|
2024-09-17 19:48:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
|
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
app.MainWindow.ShowMessage(localizationService.GetString("FatalException"), error.ExceptionObject.ToString());
|
2024-06-05 01:21:31 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
app.Services.InitializeLANCommander();
|
2024-05-21 20:51:09 -05:00
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
if (args.Length > 0)
|
2024-07-08 17:46:58 -05:00
|
|
|
|
{
|
2024-09-18 20:40:41 -05:00
|
|
|
|
using (var scope = app.Services.CreateScope())
|
2024-07-28 17:41:43 -05:00
|
|
|
|
{
|
2024-09-18 20:40:41 -05:00
|
|
|
|
var commandLineService = scope.ServiceProvider.GetService<CommandLineService>();
|
2024-07-28 18:32:45 -05:00
|
|
|
|
|
2024-09-18 20:40:41 -05:00
|
|
|
|
Task.Run(async () => await commandLineService.ParseCommandLineAsync(args)).GetAwaiter().GetResult();
|
2024-07-30 01:09:58 -05:00
|
|
|
|
}
|
2024-08-06 18:24:44 -05:00
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.LaunchCount++;
|
|
|
|
|
|
|
|
|
|
|
|
SettingService.SaveSettings(settings);
|
2024-07-28 18:32:45 -05:00
|
|
|
|
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
Logger?.Debug(localizationService.GetString("StartingApplication"));
|
2024-07-28 18:32:45 -05:00
|
|
|
|
|
2024-09-17 19:48:23 -05:00
|
|
|
|
app.MainWindow.WindowClosing += MainWindow_WindowClosing;
|
|
|
|
|
|
|
2024-08-06 18:24:44 -05:00
|
|
|
|
app.Run();
|
2024-07-08 17:46:58 -05:00
|
|
|
|
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
|
Logger?.Debug(localizationService.GetString("ClosingApplication"));
|
2024-08-06 18:24:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-17 19:48:23 -05:00
|
|
|
|
|
|
|
|
|
|
private static bool MainWindow_WindowClosing(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var window = sender as PhotinoWindow;
|
|
|
|
|
|
|
|
|
|
|
|
var settings = SettingService.GetSettings();
|
|
|
|
|
|
|
|
|
|
|
|
settings.Window.Maximized = window.Maximized;
|
|
|
|
|
|
settings.Window.Width = window.Width;
|
|
|
|
|
|
settings.Window.Height = window.Height;
|
|
|
|
|
|
settings.Window.X = window.Left;
|
|
|
|
|
|
settings.Window.Y = window.Top;
|
|
|
|
|
|
|
|
|
|
|
|
SettingService.SaveSettings(settings);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|