2024-05-20 19:42:31 -05:00
|
|
|
|
using LANCommander.Client.Data;
|
|
|
|
|
|
using LANCommander.Client.Services;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-06-05 01:21:31 -05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Photino.Blazor;
|
|
|
|
|
|
using Photino.Blazor.CustomWindow.Extensions;
|
2024-05-09 20:44:40 -05:00
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.Client
|
|
|
|
|
|
{
|
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]
|
|
|
|
|
|
static void Main(string[] args)
|
2024-05-09 20:44:40 -05:00
|
|
|
|
{
|
|
|
|
|
|
var settings = SettingService.GetSettings();
|
2024-06-05 01:21:31 -05:00
|
|
|
|
var builder = PhotinoBlazorAppBuilder.CreateDefault(args);
|
2024-05-09 20:44:40 -05:00
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
builder.RootComponents.Add<App>("app");
|
2024-05-21 20:51:09 -05:00
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
builder.Services.AddLogging();
|
|
|
|
|
|
builder.Services.AddCustomWindow();
|
2024-05-09 20:44:40 -05:00
|
|
|
|
builder.Services.AddAntDesign();
|
2024-06-05 01:21:31 -05:00
|
|
|
|
builder.Services.AddDbContext<DbContext, DatabaseContext>();
|
2024-05-09 20:44:40 -05:00
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
#region Register Client
|
2024-05-09 20:44:40 -05:00
|
|
|
|
var client = new SDK.Client(settings.Authentication.ServerAddress, settings.Games.DefaultInstallDirectory);
|
|
|
|
|
|
|
|
|
|
|
|
client.UseToken(new SDK.Models.AuthToken
|
|
|
|
|
|
{
|
|
|
|
|
|
AccessToken = settings.Authentication.AccessToken,
|
|
|
|
|
|
RefreshToken = settings.Authentication.RefreshToken,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
builder.Services.AddSingleton(client);
|
2024-06-05 01:21:31 -05:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Register Services
|
2024-05-23 18:38:13 -05:00
|
|
|
|
builder.Services.AddScoped<CollectionService>();
|
|
|
|
|
|
builder.Services.AddScoped<CompanyService>();
|
|
|
|
|
|
builder.Services.AddScoped<EngineService>();
|
|
|
|
|
|
builder.Services.AddScoped<GameService>();
|
|
|
|
|
|
builder.Services.AddScoped<GenreService>();
|
|
|
|
|
|
builder.Services.AddScoped<MultiplayerModeService>();
|
|
|
|
|
|
builder.Services.AddScoped<TagService>();
|
2024-05-28 00:24:29 -05:00
|
|
|
|
builder.Services.AddScoped<MediaService>();
|
2024-06-03 19:08:50 -05:00
|
|
|
|
builder.Services.AddScoped<ProfileService>();
|
2024-06-02 23:01:37 -05:00
|
|
|
|
builder.Services.AddScoped<PlaySessionService>();
|
2024-05-23 18:38:13 -05:00
|
|
|
|
builder.Services.AddScoped<RedistributableService>();
|
2024-05-29 19:25:41 -05:00
|
|
|
|
builder.Services.AddScoped<SaveService>();
|
2024-05-28 00:24:29 -05:00
|
|
|
|
builder.Services.AddScoped<ImportService>();
|
2024-05-23 18:38:13 -05:00
|
|
|
|
builder.Services.AddScoped<LibraryService>();
|
2024-05-25 15:40:31 -05:00
|
|
|
|
builder.Services.AddScoped<DownloadService>();
|
2024-06-05 01:21:31 -05:00
|
|
|
|
#endregion
|
2024-05-09 20:44:40 -05:00
|
|
|
|
|
2024-05-21 20:51:09 -05:00
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
app.MainWindow
|
|
|
|
|
|
.SetTitle("LANCommander")
|
|
|
|
|
|
.SetUseOsDefaultLocation(true)
|
|
|
|
|
|
.SetChromeless(true)
|
|
|
|
|
|
.SetResizable(true);
|
|
|
|
|
|
|
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
app.MainWindow.ShowMessage("Fatal exception", error.ExceptionObject.ToString());
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#region Scaffold Required Directories
|
2024-05-31 23:49:45 -05:00
|
|
|
|
string[] requiredDirectories = new string[]
|
|
|
|
|
|
{
|
|
|
|
|
|
"Backups",
|
|
|
|
|
|
"Media"
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var directory in requiredDirectories)
|
|
|
|
|
|
{
|
|
|
|
|
|
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, directory);
|
|
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
|
}
|
2024-06-05 01:21:31 -05:00
|
|
|
|
#endregion
|
2024-05-31 23:49:45 -05:00
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
#region Migrate Database
|
2024-05-21 20:51:09 -05:00
|
|
|
|
using var scope = app.Services.CreateScope();
|
|
|
|
|
|
|
|
|
|
|
|
using var db = scope.ServiceProvider.GetService<DatabaseContext>();
|
|
|
|
|
|
|
|
|
|
|
|
if (db.Database.GetPendingMigrations().Any())
|
|
|
|
|
|
{
|
2024-05-23 19:14:51 -05:00
|
|
|
|
var backupPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Backups");
|
|
|
|
|
|
var dataSource = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LANCommander.db");
|
|
|
|
|
|
var backupName = Path.Combine(backupPath, $"LANCommander.db.{DateTime.Now.ToString("dd-MM-yyyy-HH.mm.ss.bak")}");
|
|
|
|
|
|
|
2024-05-21 20:51:09 -05:00
|
|
|
|
if (File.Exists(dataSource))
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Copy(dataSource, backupName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.Database.Migrate();
|
|
|
|
|
|
}
|
2024-06-05 01:21:31 -05:00
|
|
|
|
#endregion
|
2024-05-21 20:51:09 -05:00
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
|
app.Run();
|
2024-05-09 20:44:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|