2022-06-01 21:45:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2023-11-19 22:15:12 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2022-06-01 21:45:55 +00:00
|
|
|
|
using Avalonia;
|
2021-10-08 13:16:51 +00:00
|
|
|
|
using Avalonia.ReactiveUI;
|
2022-06-01 21:45:55 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-11-19 22:15:12 +00:00
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Configuration;
|
2022-06-01 21:45:55 +00:00
|
|
|
|
using Wabbajack.Downloaders.Http;
|
|
|
|
|
using Wabbajack.DTOs;
|
|
|
|
|
using Wabbajack.DTOs.JsonConverters;
|
|
|
|
|
using Wabbajack.DTOs.Logins;
|
|
|
|
|
using Wabbajack.Launcher.ViewModels;
|
|
|
|
|
using Wabbajack.Networking.Http;
|
|
|
|
|
using Wabbajack.Networking.Http.Interfaces;
|
|
|
|
|
using Wabbajack.Networking.NexusApi;
|
|
|
|
|
using Wabbajack.Paths;
|
2023-11-19 22:15:12 +00:00
|
|
|
|
using Wabbajack.Paths.IO;
|
2022-06-01 21:45:55 +00:00
|
|
|
|
using Wabbajack.RateLimiter;
|
2023-11-19 22:15:12 +00:00
|
|
|
|
using Wabbajack.Services.OSIntegrated;
|
2022-10-01 13:02:47 +00:00
|
|
|
|
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
2021-10-08 13:16:51 +00:00
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
|
namespace Wabbajack.Launcher;
|
|
|
|
|
|
|
|
|
|
// To Build : dotnet publish -r win-x64 -c Release -p:PublishReadyToRun=true --self-contained -o c:\tmp\publish -p:PublishSingleFile=true -p:DebugType=embedded -p:IncludeAllContentForSelfExtract=true
|
|
|
|
|
internal class Program
|
2021-10-08 13:16:51 +00:00
|
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
|
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
|
|
|
|
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
|
|
|
|
// yet and stuff might break.
|
|
|
|
|
public static void Main(string[] args)
|
2021-10-08 13:16:51 +00:00
|
|
|
|
{
|
2022-06-01 21:45:55 +00:00
|
|
|
|
var host = Host.CreateDefaultBuilder(Array.Empty<string>())
|
|
|
|
|
.ConfigureLogging(c => { c.ClearProviders(); })
|
|
|
|
|
.ConfigureServices((host, services) =>
|
|
|
|
|
{
|
|
|
|
|
services.AddNexusApi();
|
|
|
|
|
services.AddDTOConverters();
|
|
|
|
|
services.AddDTOSerializer();
|
2023-11-19 22:15:12 +00:00
|
|
|
|
|
|
|
|
|
services.AddSingleton(s => new Services.OSIntegrated.Configuration
|
|
|
|
|
{
|
|
|
|
|
EncryptedDataLocation = KnownFolders.WabbajackAppLocal.Combine("encrypted"),
|
|
|
|
|
ModListsDownloadLocation = KnownFolders.EntryPoint.Combine("downloaded_mod_lists"),
|
|
|
|
|
SavedSettingsLocation = KnownFolders.WabbajackAppLocal.Combine("saved_settings"),
|
|
|
|
|
LogLocation = KnownFolders.LauncherAwarePath.Combine("logs"),
|
|
|
|
|
ImageCacheLocation = KnownFolders.WabbajackAppLocal.Combine("image_cache")
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<SettingsManager>();
|
|
|
|
|
services.AddSingleton<ResourceSettingsManager>();
|
|
|
|
|
services.AddSingleton<MainSettings>(s => GetAppSettings(s, MainSettings.SettingsFileName));
|
|
|
|
|
|
2022-06-01 21:45:55 +00:00
|
|
|
|
services.AddSingleton<MainWindowViewModel>();
|
|
|
|
|
services.AddSingleton<HttpClient>();
|
2024-05-25 15:38:31 +00:00
|
|
|
|
services.AddSingleton<ITokenProvider<NexusOAuthState>, NexusApiTokenProvider>();
|
2022-06-01 21:45:55 +00:00
|
|
|
|
services.AddSingleton<HttpDownloader>();
|
|
|
|
|
services.AddAllSingleton<IResource, IResource<HttpClient>>(s => new Resource<HttpClient>("Web Requests", 4));
|
|
|
|
|
services.AddAllSingleton<IHttpDownloader, SingleThreadedDownloader>();
|
|
|
|
|
|
|
|
|
|
var version =
|
|
|
|
|
$"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Patch}{ThisAssembly.Git.SemVer.DashLabel}";
|
|
|
|
|
services.AddSingleton(s => new ApplicationInfo
|
|
|
|
|
{
|
|
|
|
|
ApplicationSlug = "Wabbajack",
|
|
|
|
|
ApplicationName = Environment.ProcessPath?.ToAbsolutePath().FileName.ToString() ?? "Wabbajack",
|
|
|
|
|
ApplicationSha = ThisAssembly.Git.Sha,
|
|
|
|
|
Platform = RuntimeInformation.ProcessArchitecture.ToString(),
|
|
|
|
|
OperatingSystemDescription = RuntimeInformation.OSDescription,
|
|
|
|
|
RuntimeIdentifier = RuntimeInformation.RuntimeIdentifier,
|
|
|
|
|
OSVersion = Environment.OSVersion.VersionString,
|
|
|
|
|
Version = version
|
|
|
|
|
});
|
|
|
|
|
}).Build();
|
|
|
|
|
Services = host.Services;
|
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
|
BuildAvaloniaApp()
|
2021-10-08 13:16:51 +00:00
|
|
|
|
.StartWithClassicDesktopLifetime(args);
|
2021-10-23 16:51:17 +00:00
|
|
|
|
}
|
2023-11-19 22:15:12 +00:00
|
|
|
|
|
|
|
|
|
private static MainSettings GetAppSettings(IServiceProvider provider, string name)
|
|
|
|
|
{
|
|
|
|
|
var settingsManager = provider.GetRequiredService<SettingsManager>();
|
|
|
|
|
var settings = Task.Run(() => settingsManager.Load<MainSettings>(name)).Result;
|
|
|
|
|
if (settings.Upgrade())
|
|
|
|
|
{
|
|
|
|
|
settingsManager.Save(MainSettings.SettingsFileName, settings).FireAndForget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 21:45:55 +00:00
|
|
|
|
public static IServiceProvider Services { get; set; }
|
2021-10-08 13:16:51 +00:00
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
|
// Avalonia configuration, don't remove; also used by visual designer.
|
|
|
|
|
public static AppBuilder BuildAvaloniaApp()
|
|
|
|
|
{
|
|
|
|
|
return AppBuilder.Configure<App>()
|
|
|
|
|
.UsePlatformDetect()
|
|
|
|
|
.LogToTrace()
|
|
|
|
|
.UseReactiveUI();
|
2021-10-08 13:16:51 +00:00
|
|
|
|
}
|
2021-10-23 16:51:17 +00:00
|
|
|
|
}
|