mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Create configuration project and performance settings
This commit is contained in:
parent
77f6b8c9cb
commit
7350b632f7
29
Wabbajack.Configuration/MainSettings.cs
Normal file
29
Wabbajack.Configuration/MainSettings.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Wabbajack.Configuration;
|
||||
|
||||
public class MainSettings
|
||||
{
|
||||
private const int SettingsVersion = 1;
|
||||
|
||||
[JsonInclude]
|
||||
private int CurrentSettingsVersion { get; set; }
|
||||
|
||||
public PerformanceSettings PerformanceSettings { get; set; } = new();
|
||||
|
||||
public bool Upgrade()
|
||||
{
|
||||
if (CurrentSettingsVersion == SettingsVersion)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CurrentSettingsVersion < 1)
|
||||
{
|
||||
PerformanceSettings.MaximumMemoryPerDownloadThreadMb = -1;
|
||||
}
|
||||
|
||||
CurrentSettingsVersion = SettingsVersion;
|
||||
return true;
|
||||
}
|
||||
}
|
6
Wabbajack.Configuration/PerformanceSettings.cs
Normal file
6
Wabbajack.Configuration/PerformanceSettings.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace Wabbajack.Configuration;
|
||||
|
||||
public class PerformanceSettings
|
||||
{
|
||||
public int MaximumMemoryPerDownloadThreadMb { get; set; }
|
||||
}
|
9
Wabbajack.Configuration/Wabbajack.Configuration.csproj
Normal file
9
Wabbajack.Configuration/Wabbajack.Configuration.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -13,6 +13,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wabbajack.Configuration\Wabbajack.Configuration.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Downloaders.Interfaces\Wabbajack.Downloaders.Interfaces.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Hashing.xxHash64\Wabbajack.Hashing.xxHash64.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Networking.Http.Interfaces\Wabbajack.Networking.Http.Interfaces.csproj" />
|
||||
|
@ -8,15 +8,15 @@ using Wabbajack.DTOs;
|
||||
using Wabbajack.DTOs.Logins;
|
||||
using Wabbajack.Networking.Http.Interfaces;
|
||||
using Wabbajack.Networking.NexusApi.DTOs;
|
||||
using Wabbajack.Networking.WabbajackClientApi;
|
||||
using Wabbajack.RateLimiter;
|
||||
using ClientConfiguration = Wabbajack.Networking.WabbajackClientApi.Configuration;
|
||||
|
||||
namespace Wabbajack.Networking.NexusApi;
|
||||
|
||||
public class ProxiedNexusApi : NexusApi
|
||||
{
|
||||
private readonly ITokenProvider<WabbajackApiState> _apiState;
|
||||
private readonly Configuration _wabbajackClientConfiguration;
|
||||
private readonly ClientConfiguration _wabbajackClientConfiguration;
|
||||
|
||||
public HashSet<string> ProxiedEndpoints = new()
|
||||
{
|
||||
@ -28,7 +28,7 @@ public class ProxiedNexusApi : NexusApi
|
||||
public ProxiedNexusApi(ITokenProvider<NexusApiState> apiKey, ILogger<ProxiedNexusApi> logger, HttpClient client,
|
||||
IResource<HttpClient> limiter,
|
||||
ApplicationInfo appInfo, JsonSerializerOptions jsonOptions, ITokenProvider<WabbajackApiState> apiState,
|
||||
Configuration wabbajackClientConfiguration)
|
||||
ClientConfiguration wabbajackClientConfiguration)
|
||||
: base(apiKey, logger, client, limiter, appInfo, jsonOptions)
|
||||
{
|
||||
_apiState = apiState;
|
||||
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wabbajack.Compiler;
|
||||
using Wabbajack.Configuration;
|
||||
using Wabbajack.Downloaders;
|
||||
using Wabbajack.Downloaders.GameFile;
|
||||
using Wabbajack.Downloaders.VerificationCache;
|
||||
@ -79,24 +80,36 @@ public static class ServiceExtensions
|
||||
? new BinaryPatchCache(s.GetRequiredService<ILogger<BinaryPatchCache>>(), s.GetService<TemporaryFileManager>()!.CreateFolder().Path)
|
||||
: new BinaryPatchCache(s.GetRequiredService<ILogger<BinaryPatchCache>>(),KnownFolders.WabbajackAppLocal.Combine("PatchCache")));
|
||||
|
||||
|
||||
|
||||
service.AddSingleton<IVerificationCache>(s =>
|
||||
{
|
||||
var dtos = s.GetRequiredService<DTOSerializer>();
|
||||
return options.UseLocalCache
|
||||
? new VerificationCache(s.GetRequiredService<ILogger<VerificationCache>>(),
|
||||
s.GetService<TemporaryFileManager>()!.CreateFile().Path,
|
||||
s.GetService<TemporaryFileManager>()!.CreateFile().Path,
|
||||
TimeSpan.FromDays(1),
|
||||
dtos)
|
||||
: new VerificationCache(s.GetRequiredService<ILogger<VerificationCache>>(),
|
||||
KnownFolders.WabbajackAppLocal.Combine("VerificationCacheV2.sqlite"),
|
||||
KnownFolders.WabbajackAppLocal.Combine("VerificationCacheV2.sqlite"),
|
||||
TimeSpan.FromDays(1),
|
||||
dtos);
|
||||
});
|
||||
|
||||
service.AddSingleton(new ParallelOptions {MaxDegreeOfParallelism = Environment.ProcessorCount});
|
||||
|
||||
Func<Task<(int MaxTasks, long MaxThroughput)>> GetSettings(IServiceProvider provider, string name)
|
||||
MainSettings GetAppSettings(IServiceProvider provider, string name)
|
||||
{
|
||||
var settingsManager = provider.GetService<SettingsManager>();
|
||||
var settings = settingsManager!.Load<MainSettings>(name).Result;
|
||||
if (settings.Upgrade())
|
||||
{
|
||||
settingsManager.Save("app_settings", settings).Wait();
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
Func<Task<(int MaxTasks, long MaxThroughput)>> GetResourceSettings(IServiceProvider provider, string name)
|
||||
{
|
||||
return async () =>
|
||||
{
|
||||
@ -104,9 +117,9 @@ public static class ServiceExtensions
|
||||
return ((int) s.MaxTasks, s.MaxThroughput);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Settings
|
||||
|
||||
|
||||
service.AddSingleton(s => new Configuration
|
||||
{
|
||||
EncryptedDataLocation = KnownFolders.WabbajackAppLocal.Combine("encrypted"),
|
||||
@ -118,26 +131,27 @@ public static class ServiceExtensions
|
||||
|
||||
service.AddSingleton<SettingsManager>();
|
||||
service.AddSingleton<ResourceSettingsManager>();
|
||||
|
||||
service.AddSingleton<MainSettings>(s => GetAppSettings(s, "app_settings"));
|
||||
|
||||
// Resources
|
||||
|
||||
service.AddAllSingleton<IResource, IResource<DownloadDispatcher>>(s =>
|
||||
new Resource<DownloadDispatcher>("Downloads", GetSettings(s, "Downloads"), s.GetRequiredService<CancellationToken>()));
|
||||
new Resource<DownloadDispatcher>("Downloads", GetResourceSettings(s, "Downloads"), s.GetRequiredService<CancellationToken>()));
|
||||
|
||||
service.AddAllSingleton<IResource, IResource<HttpClient>>(s => new Resource<HttpClient>("Web Requests", GetSettings(s, "Web Requests"), s.GetRequiredService<CancellationToken>()));
|
||||
service.AddAllSingleton<IResource, IResource<Context>>(s => new Resource<Context>("VFS", GetSettings(s, "VFS"), s.GetRequiredService<CancellationToken>()));
|
||||
service.AddAllSingleton<IResource, IResource<HttpClient>>(s => new Resource<HttpClient>("Web Requests", GetResourceSettings(s, "Web Requests"), s.GetRequiredService<CancellationToken>()));
|
||||
service.AddAllSingleton<IResource, IResource<Context>>(s => new Resource<Context>("VFS", GetResourceSettings(s, "VFS"), s.GetRequiredService<CancellationToken>()));
|
||||
service.AddAllSingleton<IResource, IResource<FileHashCache>>(s =>
|
||||
new Resource<FileHashCache>("File Hashing", GetSettings(s, "File Hashing"), s.GetRequiredService<CancellationToken>()));
|
||||
new Resource<FileHashCache>("File Hashing", GetResourceSettings(s, "File Hashing"), s.GetRequiredService<CancellationToken>()));
|
||||
service.AddAllSingleton<IResource, IResource<Client>>(s =>
|
||||
new Resource<Client>("Wabbajack Client", GetSettings(s, "Wabbajack Client"), s.GetRequiredService<CancellationToken>()));
|
||||
new Resource<Client>("Wabbajack Client", GetResourceSettings(s, "Wabbajack Client"), s.GetRequiredService<CancellationToken>()));
|
||||
service.AddAllSingleton<IResource, IResource<FileExtractor.FileExtractor>>(s =>
|
||||
new Resource<FileExtractor.FileExtractor>("File Extractor", GetSettings(s, "File Extractor"), s.GetRequiredService<CancellationToken>()));
|
||||
new Resource<FileExtractor.FileExtractor>("File Extractor", GetResourceSettings(s, "File Extractor"), s.GetRequiredService<CancellationToken>()));
|
||||
|
||||
service.AddAllSingleton<IResource, IResource<ACompiler>>(s =>
|
||||
new Resource<ACompiler>("Compiler", GetSettings(s, "Compiler"), s.GetRequiredService<CancellationToken>()));
|
||||
new Resource<ACompiler>("Compiler", GetResourceSettings(s, "Compiler"), s.GetRequiredService<CancellationToken>()));
|
||||
|
||||
service.AddAllSingleton<IResource, IResource<IInstaller>>(s =>
|
||||
new Resource<IInstaller>("Installer", GetSettings(s, "Installer"), s.GetRequiredService<CancellationToken>()));
|
||||
new Resource<IInstaller>("Installer", GetResourceSettings(s, "Installer"), s.GetRequiredService<CancellationToken>()));
|
||||
|
||||
service.AddAllSingleton<IResource, IResource<IUserInterventionHandler>>(s =>
|
||||
new Resource<IUserInterventionHandler>("User Intervention", 1, token: s.GetRequiredService<CancellationToken>()));
|
||||
@ -154,7 +168,7 @@ public static class ServiceExtensions
|
||||
service.AddAllSingleton<IHttpDownloader, SingleThreadedDownloader>();
|
||||
|
||||
service.AddSteam();
|
||||
|
||||
|
||||
service.AddSingleton<Client>();
|
||||
service.AddSingleton<WriteOnlyClient>();
|
||||
service.AddBethesdaNet();
|
||||
@ -186,11 +200,11 @@ public static class ServiceExtensions
|
||||
service.AddAllSingleton<IGameLocator, StubbedGameLocator>();
|
||||
else
|
||||
service.AddAllSingleton<IGameLocator, GameLocator>();
|
||||
|
||||
|
||||
// ImageLoader
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
service.AddSingleton<IImageLoader, TexConvImageLoader>();
|
||||
else
|
||||
else
|
||||
service.AddSingleton<IImageLoader, CrossPlatformImageLoader>();
|
||||
|
||||
// Installer/Compiler Configuration
|
||||
@ -214,9 +228,9 @@ public static class ServiceExtensions
|
||||
OSVersion = Environment.OSVersion.VersionString,
|
||||
Version = version
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
@ -224,7 +238,7 @@ public static class ServiceExtensions
|
||||
{
|
||||
// Get directories first and cache them, this freezes the directories were looking at
|
||||
// so any new ones don't show up in the middle of our deletes.
|
||||
|
||||
|
||||
var dirs = path.EnumerateDirectories().ToList();
|
||||
var processIds = Process.GetProcesses().Select(p => p.Id).ToHashSet();
|
||||
foreach (var dir in dirs)
|
||||
@ -232,7 +246,7 @@ public static class ServiceExtensions
|
||||
var name = dir.FileName.ToString().Split("_");
|
||||
if (!int.TryParse(name[0], out var processId)) continue;
|
||||
if (processIds.Contains(processId)) continue;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
dir.DeleteDirectory();
|
||||
@ -242,7 +256,7 @@ public static class ServiceExtensions
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class OSIntegratedOptions
|
||||
|
@ -147,6 +147,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.CLI.Builder", "Wa
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Downloaders.VerificationCache", "Wabbajack.Downloaders.VerificationCache\Wabbajack.Downloaders.VerificationCache.csproj", "{D9560C73-4E58-4463-9DB9-D06491E0E1C8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Configuration", "Wabbajack.Configuration\Wabbajack.Configuration.csproj", "{E7CDACA6-D3FF-4CF6-8EF8-05FCD27F6FBE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -401,6 +403,10 @@ Global
|
||||
{D9560C73-4E58-4463-9DB9-D06491E0E1C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D9560C73-4E58-4463-9DB9-D06491E0E1C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D9560C73-4E58-4463-9DB9-D06491E0E1C8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E7CDACA6-D3FF-4CF6-8EF8-05FCD27F6FBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E7CDACA6-D3FF-4CF6-8EF8-05FCD27F6FBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E7CDACA6-D3FF-4CF6-8EF8-05FCD27F6FBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E7CDACA6-D3FF-4CF6-8EF8-05FCD27F6FBE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user