using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Wabbajack.Common; using Wabbajack.Compiler; using Wabbajack.Downloaders; using Wabbajack.DTOs; using Wabbajack.DTOs.Logins; using Wabbajack.Installer; using Wabbajack.Networking.Discord; using Wabbajack.Networking.Http; using Wabbajack.Networking.Http.Interfaces; using Wabbajack.Networking.NexusApi; using Wabbajack.Networking.WabbajackClientApi; using Wabbajack.Paths; using Wabbajack.Paths.IO; using Wabbajack.RateLimiter; using Wabbajack.Services.OSIntegrated.TokenProviders; using Wabbajack.VFS; using ApplicationInfo = Wabbajack.DTOs.ApplicationInfo; namespace Wabbajack.Services.OSIntegrated { public static class ServiceExtensions { public class OSIntegratedOptions { public bool UseLocalCache { get; set; } = false; public bool UseStubbedGameFolders { get; set; } = false; } /// /// Adds variants of services that integrate into global OS services. These are not testing /// variants or services that require Environment variables. These are the "full fat" services. /// /// public static IServiceCollection AddOSIntegrated(this IServiceCollection service, Action? cfn = null) { var options = new OSIntegratedOptions(); cfn?.Invoke(options); service.AddTransient(s => new TemporaryFileManager(KnownFolders.EntryPoint.Combine("temp", Guid.NewGuid().ToString()))); service.AddSingleton(s => options.UseLocalCache ? new FileHashCache(s.GetService()!.CreateFile().Path) : new FileHashCache(KnownFolders.AppDataLocal.Combine("Wabbajack", "GlobalHashCache.sqlite"))); service.AddSingleton(s => options.UseLocalCache ? new VFSCache(s.GetService()!.CreateFile().Path) : new VFSCache(KnownFolders.EntryPoint.Combine("GlobalVFSCache3.sqlite"))); service.AddSingleton(s => options.UseLocalCache ? new BinaryPatchCache(s.GetService()!.CreateFile().Path) : new BinaryPatchCache(KnownFolders.EntryPoint.Combine("patchCache.sqlite"))); service.AddSingleton(new ParallelOptions {MaxDegreeOfParallelism = Environment.ProcessorCount}); service.AddAllSingleton>(s => new Resource(12)); service.AddAllSingleton>(s => new Resource(12)); service.AddAllSingleton>(s => new Resource(12)); service.AddSingleton(); service.AddScoped(); service.AddSingleton(); // Networking service.AddSingleton(); service.AddAllSingleton(); service.AddSingleton(); service.AddSingleton(); service.AddSingleton(); // Token Providers service.AddAllSingleton, NexusApiTokenProvider>(); service.AddAllSingleton, EncryptedJsonTokenProvider, LoversLabTokenProvider>(); service.AddAllSingleton, EncryptedJsonTokenProvider, VectorPlexusTokenProvider>(); service.AddAllSingleton, WabbajackApiTokenProvider>(); service .AddAllSingleton>, EncryptedJsonTokenProvider>, DiscordTokenProvider>(); service.AddAllSingleton(); service.AddDownloadDispatcher(); if (options.UseStubbedGameFolders) { service.AddAllSingleton(); } else { service.AddAllSingleton(); } // Installer/Compiler Configuration service.AddScoped(); service.AddScoped(); service.AddScoped(); service.AddScoped(); // Application Info var version = $"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Patch}{ThisAssembly.Git.SemVer.DashLabel}"; service.AddSingleton(s => new ApplicationInfo { ApplicationSlug = "Wabbajack", ApplicationName = Environment.ProcessPath?.ToAbsolutePath().FileName.ToString() ?? "Wabbajack", ApplicationSha = ThisAssembly.Git.Sha, Platform = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString(), OperatingSystemDescription = System.Runtime.InteropServices.RuntimeInformation.OSDescription, RuntimeIdentifier = System.Runtime.InteropServices.RuntimeInformation.RuntimeIdentifier, OSVersion = Environment.OSVersion.VersionString, Version = version }); return service; } } }