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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Wabbajack.Configuration\Wabbajack.Configuration.csproj" />
|
||||||
<ProjectReference Include="..\Wabbajack.Downloaders.Interfaces\Wabbajack.Downloaders.Interfaces.csproj" />
|
<ProjectReference Include="..\Wabbajack.Downloaders.Interfaces\Wabbajack.Downloaders.Interfaces.csproj" />
|
||||||
<ProjectReference Include="..\Wabbajack.Hashing.xxHash64\Wabbajack.Hashing.xxHash64.csproj" />
|
<ProjectReference Include="..\Wabbajack.Hashing.xxHash64\Wabbajack.Hashing.xxHash64.csproj" />
|
||||||
<ProjectReference Include="..\Wabbajack.Networking.Http.Interfaces\Wabbajack.Networking.Http.Interfaces.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.DTOs.Logins;
|
||||||
using Wabbajack.Networking.Http.Interfaces;
|
using Wabbajack.Networking.Http.Interfaces;
|
||||||
using Wabbajack.Networking.NexusApi.DTOs;
|
using Wabbajack.Networking.NexusApi.DTOs;
|
||||||
using Wabbajack.Networking.WabbajackClientApi;
|
|
||||||
using Wabbajack.RateLimiter;
|
using Wabbajack.RateLimiter;
|
||||||
|
using ClientConfiguration = Wabbajack.Networking.WabbajackClientApi.Configuration;
|
||||||
|
|
||||||
namespace Wabbajack.Networking.NexusApi;
|
namespace Wabbajack.Networking.NexusApi;
|
||||||
|
|
||||||
public class ProxiedNexusApi : NexusApi
|
public class ProxiedNexusApi : NexusApi
|
||||||
{
|
{
|
||||||
private readonly ITokenProvider<WabbajackApiState> _apiState;
|
private readonly ITokenProvider<WabbajackApiState> _apiState;
|
||||||
private readonly Configuration _wabbajackClientConfiguration;
|
private readonly ClientConfiguration _wabbajackClientConfiguration;
|
||||||
|
|
||||||
public HashSet<string> ProxiedEndpoints = new()
|
public HashSet<string> ProxiedEndpoints = new()
|
||||||
{
|
{
|
||||||
@ -28,7 +28,7 @@ public class ProxiedNexusApi : NexusApi
|
|||||||
public ProxiedNexusApi(ITokenProvider<NexusApiState> apiKey, ILogger<ProxiedNexusApi> logger, HttpClient client,
|
public ProxiedNexusApi(ITokenProvider<NexusApiState> apiKey, ILogger<ProxiedNexusApi> logger, HttpClient client,
|
||||||
IResource<HttpClient> limiter,
|
IResource<HttpClient> limiter,
|
||||||
ApplicationInfo appInfo, JsonSerializerOptions jsonOptions, ITokenProvider<WabbajackApiState> apiState,
|
ApplicationInfo appInfo, JsonSerializerOptions jsonOptions, ITokenProvider<WabbajackApiState> apiState,
|
||||||
Configuration wabbajackClientConfiguration)
|
ClientConfiguration wabbajackClientConfiguration)
|
||||||
: base(apiKey, logger, client, limiter, appInfo, jsonOptions)
|
: base(apiKey, logger, client, limiter, appInfo, jsonOptions)
|
||||||
{
|
{
|
||||||
_apiState = apiState;
|
_apiState = apiState;
|
||||||
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Wabbajack.Compiler;
|
using Wabbajack.Compiler;
|
||||||
|
using Wabbajack.Configuration;
|
||||||
using Wabbajack.Downloaders;
|
using Wabbajack.Downloaders;
|
||||||
using Wabbajack.Downloaders.GameFile;
|
using Wabbajack.Downloaders.GameFile;
|
||||||
using Wabbajack.Downloaders.VerificationCache;
|
using Wabbajack.Downloaders.VerificationCache;
|
||||||
@ -96,7 +97,19 @@ public static class ServiceExtensions
|
|||||||
|
|
||||||
service.AddSingleton(new ParallelOptions {MaxDegreeOfParallelism = Environment.ProcessorCount});
|
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 () =>
|
return async () =>
|
||||||
{
|
{
|
||||||
@ -118,26 +131,27 @@ public static class ServiceExtensions
|
|||||||
|
|
||||||
service.AddSingleton<SettingsManager>();
|
service.AddSingleton<SettingsManager>();
|
||||||
service.AddSingleton<ResourceSettingsManager>();
|
service.AddSingleton<ResourceSettingsManager>();
|
||||||
|
service.AddSingleton<MainSettings>(s => GetAppSettings(s, "app_settings"));
|
||||||
|
|
||||||
// Resources
|
// Resources
|
||||||
|
|
||||||
service.AddAllSingleton<IResource, IResource<DownloadDispatcher>>(s =>
|
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<HttpClient>>(s => new Resource<HttpClient>("Web Requests", GetResourceSettings(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<Context>>(s => new Resource<Context>("VFS", GetResourceSettings(s, "VFS"), s.GetRequiredService<CancellationToken>()));
|
||||||
service.AddAllSingleton<IResource, IResource<FileHashCache>>(s =>
|
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 =>
|
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 =>
|
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 =>
|
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 =>
|
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 =>
|
service.AddAllSingleton<IResource, IResource<IUserInterventionHandler>>(s =>
|
||||||
new Resource<IUserInterventionHandler>("User Intervention", 1, token: s.GetRequiredService<CancellationToken>()));
|
new Resource<IUserInterventionHandler>("User Intervention", 1, token: s.GetRequiredService<CancellationToken>()));
|
||||||
|
@ -147,6 +147,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.CLI.Builder", "Wa
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Downloaders.VerificationCache", "Wabbajack.Downloaders.VerificationCache\Wabbajack.Downloaders.VerificationCache.csproj", "{D9560C73-4E58-4463-9DB9-D06491E0E1C8}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Downloaders.VerificationCache", "Wabbajack.Downloaders.VerificationCache\Wabbajack.Downloaders.VerificationCache.csproj", "{D9560C73-4E58-4463-9DB9-D06491E0E1C8}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Configuration", "Wabbajack.Configuration\Wabbajack.Configuration.csproj", "{E7CDACA6-D3FF-4CF6-8EF8-05FCD27F6FBE}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{D9560C73-4E58-4463-9DB9-D06491E0E1C8}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
Loading…
Reference in New Issue
Block a user