Tons of warning fixes

This commit is contained in:
Halgari 2022-10-07 16:14:01 -06:00
parent 4e2f8b585d
commit 1511b69b4f
24 changed files with 114 additions and 88 deletions

View File

@ -74,7 +74,7 @@ public static class AsyncParallelExtensions
/// <typeparam name="TJob"></typeparam> /// <typeparam name="TJob"></typeparam>
/// <typeparam name="TOut"></typeparam> /// <typeparam name="TOut"></typeparam>
/// <returns></returns> /// <returns></returns>
public static async IAsyncEnumerable<TOut> PMapAllBatched<TIn, TJob, TOut>(this IEnumerable<TIn> coll, public static async IAsyncEnumerable<TOut> PMapAllBatchedAsync<TIn, TJob, TOut>(this IEnumerable<TIn> coll,
IResource<TJob> limiter, Func<TIn, Task<TOut>> mapFn) IResource<TJob> limiter, Func<TIn, Task<TOut>> mapFn)
{ {
var asList = coll.ToList(); var asList = coll.ToList();
@ -103,6 +103,47 @@ public static class AsyncParallelExtensions
} }
} }
/// <summary>
/// Faster version of PMapAll for when the function invocation will take a very small amount of time
/// batches all the inputs into N groups and executes them all on one task, where N is the number of
/// threads supported by the limiter
/// </summary>
/// <param name="coll"></param>
/// <param name="limiter"></param>
/// <param name="mapFn"></param>
/// <typeparam name="TIn"></typeparam>
/// <typeparam name="TJob"></typeparam>
/// <typeparam name="TOut"></typeparam>
/// <returns></returns>
public static async IAsyncEnumerable<TOut> PMapAllBatched<TIn, TJob, TOut>(this IEnumerable<TIn> coll,
IResource<TJob> limiter, Func<TIn, TOut> mapFn)
{
var asList = coll.ToList();
var tasks = new List<Task<List<TOut>>>();
tasks.AddRange(Enumerable.Range(0, limiter.MaxTasks).Select(i => Task.Run(async () =>
{
using var job = await limiter.Begin(limiter.Name, asList.Count / limiter.MaxTasks, CancellationToken.None);
var list = new List<TOut>();
for (var idx = i; idx < asList.Count; idx += limiter.MaxTasks)
{
job.ReportNoWait(1);
list.Add( mapFn(asList[idx]));
}
return list;
})));
foreach (var result in tasks)
{
foreach (var itm in (await result))
{
yield return itm;
}
}
}
/// <summary> /// <summary>
/// Faster version of PMapAll for when the function invocation will take a very small amount of time /// Faster version of PMapAll for when the function invocation will take a very small amount of time
/// batches all the inputs into N groups and executes them all on one task, where N is the number of /// batches all the inputs into N groups and executes them all on one task, where N is the number of

View File

@ -476,7 +476,7 @@ public abstract class ACompiler
NextStep("Compiling", "Generating Patches", toBuild.Length); NextStep("Compiling", "Generating Patches", toBuild.Length);
var allFiles = (await toBuild.PMapAllBatched(CompilerLimiter, async f => var allFiles = (await toBuild.PMapAllBatchedAsync(CompilerLimiter, async f =>
{ {
UpdateProgress(1); UpdateProgress(1);
return new[] return new[]
@ -504,7 +504,7 @@ public abstract class ACompiler
if (toBuild.Length == 0) return; if (toBuild.Length == 0) return;
NextStep("Compiling", "Generating Patch Files", toBuild.Length); NextStep("Compiling", "Generating Patch Files", toBuild.Length);
await toBuild.PMapAllBatched(CompilerLimiter, async patch => await toBuild.PMapAllBatchedAsync(CompilerLimiter, async patch =>
{ {
UpdateProgress(1); UpdateProgress(1);
await using var src = TempPath(patch.FromHash).Open(FileMode.Open, FileAccess.Read, FileShare.Read); await using var src = TempPath(patch.FromHash).Open(FileMode.Open, FileAccess.Read, FileShare.Read);

View File

@ -141,7 +141,7 @@ public class MO2Compiler : ACompiler
var stack = MakeStack(); var stack = MakeStack();
NextStep("Compiling", "Running Compilation Stack", AllFiles.Count); NextStep("Compiling", "Running Compilation Stack", AllFiles.Count);
var results = await AllFiles.PMapAllBatched(CompilerLimiter, f => var results = await AllFiles.PMapAllBatchedAsync(CompilerLimiter, f =>
{ {
UpdateProgress(1); UpdateProgress(1);
return RunStack(stack, f); return RunStack(stack, f);

View File

@ -5,9 +5,10 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Version>$(VERSION)</Version> <Version>$(VERSION)</Version>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression> <PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<NoWarn>CS8600</NoWarn> </PropertyGroup>
<NoWarn>CS8601</NoWarn>
<NoWarn>CS8618</NoWarn> <PropertyGroup>
<NoWarn>CS8600,CS8601,CS8618,CS8604</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Text; using System.Text;
using Wabbajack.Common; using Wabbajack.Common;
using Wabbajack.Paths; using Wabbajack.Paths;
#pragma warning disable SYSLIB0001
namespace Wabbajack.Compression.BSA; namespace Wabbajack.Compression.BSA;

View File

@ -20,10 +20,11 @@ public class Builder : IBuilder
_files = new (TES3File state, Stream data)[_state.FileCount]; _files = new (TES3File state, Stream data)[_state.FileCount];
} }
public async ValueTask AddFile(AFile state, Stream src, CancellationToken token) public ValueTask AddFile(AFile state, Stream src, CancellationToken token)
{ {
var tesState = (TES3File) state; var tesState = (TES3File) state;
_files[state.Index] = (tesState, src); _files[state.Index] = (tesState, src);
return ValueTask.CompletedTask;
} }
public async ValueTask Build(Stream file, CancellationToken token) public async ValueTask Build(Stream file, CancellationToken token)

View File

@ -110,10 +110,8 @@ public class ZipReader : IAsyncDisposable
public async Task<ExtractedEntry[]> GetFiles() public async Task<ExtractedEntry[]> GetFiles()
{ {
var (sigOffset, totalCentralDirectoryRecords, centralDirectoryOffset) = await ReadZip32EODR(0); var (sigOffset, totalCentralDirectoryRecords, centralDirectoryOffset) = await ReadZip32EODR(0);
var isZip64 = false;
if (centralDirectoryOffset == uint.MaxValue) if (centralDirectoryOffset == uint.MaxValue)
{ {
isZip64 = true;
(sigOffset, totalCentralDirectoryRecords, centralDirectoryOffset) = await ReadZip64EODR(sigOffset); (sigOffset, totalCentralDirectoryRecords, centralDirectoryOffset) = await ReadZip64EODR(sigOffset);
} }

View File

@ -47,7 +47,7 @@ public class BethesdaDownloader : ADownloader<DTOs.DownloadStates.Bethesda>, IUr
var hasher = new xxHashAlgorithm(0); var hasher = new xxHashAlgorithm(0);
Hash finalHash = default; Hash finalHash = default;
var aesKey = depot.ExInfoA.ToArray(); var aesKey = depot!.ExInfoA.ToArray();
var aesIV = depot.ExInfoB.Take(16).ToArray(); var aesIV = depot.ExInfoB.Take(16).ToArray();
await chunks.PMapAll(async chunk => await chunks.PMapAll(async chunk =>
@ -100,7 +100,7 @@ public class BethesdaDownloader : ADownloader<DTOs.DownloadStates.Bethesda>, IUr
public override async Task<bool> Prepare() public override async Task<bool> Prepare()
{ {
await _client.CDPAuth(CancellationToken.None); await _client.CdpAuth(CancellationToken.None);
return true; return true;
} }

View File

@ -99,9 +99,9 @@ public class DownloadDispatcher
return hash; return hash;
} }
public async Task<IDownloadState?> ResolveArchive(IReadOnlyDictionary<string, string> ini) public Task<IDownloadState?> ResolveArchive(IReadOnlyDictionary<string, string> ini)
{ {
return _downloaders.Select(downloader => downloader.Resolve(ini)).FirstOrDefault(result => result != null); return Task.FromResult(_downloaders.Select(downloader => downloader.Resolve(ini)).FirstOrDefault(result => result != null));
} }
public async Task<bool> Verify(Archive a, CancellationToken token) public async Task<bool> Verify(Archive a, CancellationToken token)
@ -265,7 +265,7 @@ public class DownloadDispatcher
return Downloader(archive).IsAllowed(allowList, archive.State); return Downloader(archive).IsAllowed(allowList, archive.State);
} }
public async Task<bool> IsAllowed(ModUpgradeRequest request, CancellationToken allowList) public Task<bool> IsAllowed(ModUpgradeRequest request, CancellationToken allowList)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -288,9 +288,9 @@ public class DownloadDispatcher
} }
} }
public async Task<IEnumerable<IDownloader>> AllDownloaders(IEnumerable<IDownloadState> downloadStates) public Task<IEnumerable<IDownloader>> AllDownloaders(IEnumerable<IDownloadState> downloadStates)
{ {
return downloadStates.Select(d => Downloader(new Archive {State = d})).Distinct(); return Task.FromResult(downloadStates.Select(d => Downloader(new Archive {State = d})).Distinct());
} }
public bool Matches(Archive archive, ServerAllowList mirrorAllowList) public bool Matches(Archive archive, ServerAllowList mirrorAllowList)

View File

@ -40,9 +40,9 @@ public class GoogleDriveDownloader : ADownloader<DTOs.DownloadStates.GoogleDrive
_downloader = downloader; _downloader = downloader;
} }
public override async Task<bool> Prepare() public override Task<bool> Prepare()
{ {
return true; return Task.FromResult(true);
} }
public override bool IsAllowed(ServerAllowList allowList, IDownloadState state) public override bool IsAllowed(ServerAllowList allowList, IDownloadState state)

View File

@ -68,9 +68,9 @@ public class HttpDownloader : ADownloader<DTOs.DownloadStates.Http>, IUrlDownloa
return null; return null;
} }
public override async Task<bool> Prepare() public override Task<bool> Prepare()
{ {
return true; return Task.FromResult(true);
} }
public override bool IsAllowed(ServerAllowList allowList, IDownloadState state) public override bool IsAllowed(ServerAllowList allowList, IDownloadState state)
@ -155,10 +155,10 @@ public class HttpDownloader : ADownloader<DTOs.DownloadStates.Http>, IUrlDownloa
return new[] {$"directURL={state.Url}"}; return new[] {$"directURL={state.Url}"};
} }
public async ValueTask<Stream> GetChunkedSeekableStream(Archive archive, CancellationToken token) public ValueTask<Stream> GetChunkedSeekableStream(Archive archive, CancellationToken token)
{ {
var state = archive.State as DTOs.DownloadStates.Http; var state = archive.State as DTOs.DownloadStates.Http;
return new ChunkedSeekableDownloader(this, archive, state!); return ValueTask.FromResult<Stream>(new ChunkedSeekableDownloader(this, archive, state!));
} }
public class ChunkedSeekableDownloader : AChunkedBufferingStream public class ChunkedSeekableDownloader : AChunkedBufferingStream

View File

@ -101,11 +101,11 @@ public class AIPS4OAuth2Downloader<TDownloader, TLogin, TState> : ADownloader<TS
if (useOAuth2) if (useOAuth2)
{ {
msg.Headers.Add("User-Agent", _appInfo.UserAgent); msg.Headers.Add("User-Agent", _appInfo.UserAgent);
msg.Headers.Add("Authorization", $"Bearer {loginData.ResultState.AccessToken}"); msg.Headers.Add("Authorization", $"Bearer {loginData!.ResultState.AccessToken}");
} }
else else
{ {
msg.AddCookies(loginData.Cookies) msg.AddCookies(loginData!.Cookies)
.AddChromeAgent(); .AddChromeAgent();
} }
@ -156,16 +156,16 @@ public class AIPS4OAuth2Downloader<TDownloader, TLogin, TState> : ADownloader<TS
{ {
var downloads = await GetDownloads(state.IPS4Mod, token); var downloads = await GetDownloads(state.IPS4Mod, token);
var fileEntry = downloads.Files.FirstOrDefault(f => f.Name == state.IPS4File); var fileEntry = downloads.Files.FirstOrDefault(f => f.Name == state.IPS4File);
var msg = new HttpRequestMessage(HttpMethod.Get, fileEntry.Url); var msg = new HttpRequestMessage(HttpMethod.Get, fileEntry!.Url);
msg.Version = new Version(2, 0); msg.Version = new Version(2, 0);
msg.Headers.Add("User-Agent", _appInfo.UserAgent); msg.Headers.Add("User-Agent", _appInfo.UserAgent);
return await _downloader.Download(msg, destination, job, token); return await _downloader.Download(msg, destination, job, token);
} }
} }
public override async Task<bool> Prepare() public override Task<bool> Prepare()
{ {
return _loginInfo.HaveToken(); return Task.FromResult(_loginInfo.HaveToken());
} }
public override bool IsAllowed(ServerAllowList allowList, IDownloadState state) public override bool IsAllowed(ServerAllowList allowList, IDownloadState state)

View File

@ -16,7 +16,6 @@ public class ManualDownloader : ADownloader<DTOs.DownloadStates.Manual>, IProxya
{ {
private readonly ILogger<ManualDownloader> _logger; private readonly ILogger<ManualDownloader> _logger;
private readonly IUserInterventionHandler _interventionHandler; private readonly IUserInterventionHandler _interventionHandler;
private readonly IResource<HttpClient> _limiter;
private readonly HttpClient _client; private readonly HttpClient _client;
public ManualDownloader(ILogger<ManualDownloader> logger, IUserInterventionHandler interventionHandler, HttpClient client) public ManualDownloader(ILogger<ManualDownloader> logger, IUserInterventionHandler interventionHandler, HttpClient client)
@ -59,9 +58,9 @@ public class ManualDownloader : ADownloader<DTOs.DownloadStates.Manual>, IProxya
} }
public override async Task<bool> Prepare() public override Task<bool> Prepare()
{ {
return true; return Task.FromResult(true);
} }
public override bool IsAllowed(ServerAllowList allowList, IDownloadState state) public override bool IsAllowed(ServerAllowList allowList, IDownloadState state)
@ -88,9 +87,9 @@ public class ManualDownloader : ADownloader<DTOs.DownloadStates.Manual>, IProxya
} }
public override Priority Priority { get; } = Priority.Lowest; public override Priority Priority { get; } = Priority.Lowest;
public override async Task<bool> Verify(Archive archive, DTOs.DownloadStates.Manual archiveState, IJob job, CancellationToken token) public override Task<bool> Verify(Archive archive, DTOs.DownloadStates.Manual archiveState, IJob job, CancellationToken token)
{ {
return true; return Task.FromResult(true);
} }
public override IEnumerable<string> MetaIni(Archive a, DTOs.DownloadStates.Manual state) public override IEnumerable<string> MetaIni(Archive a, DTOs.DownloadStates.Manual state)

View File

@ -113,7 +113,7 @@ public class MediaFireDownloader : ADownloader<DTOs.DownloadStates.MediaFire>, I
{ {
var bodyData = await result.Content.ReadAsStringAsync((CancellationToken) token); var bodyData = await result.Content.ReadAsStringAsync((CancellationToken) token);
if (job != null) if (job != null)
await job.Report((int) job.Size, (CancellationToken) token); await job.Report((int) (job.Size ?? 0), (CancellationToken) token);
var body = new HtmlDocument(); var body = new HtmlDocument();
body.LoadHtml(bodyData); body.LoadHtml(bodyData);
var node = body.DocumentNode.DescendantsAndSelf().FirstOrDefault(d => d.HasClass("input") && d.HasClass("popsok") && var node = body.DocumentNode.DescendantsAndSelf().FirstOrDefault(d => d.HasClass("input") && d.HasClass("popsok") &&

View File

@ -67,7 +67,7 @@ public class MegaDownloader : ADownloader<Mega>, IUrlDownloader, IProxyable
if (!_apiClient.IsLoggedIn) if (!_apiClient.IsLoggedIn)
await _apiClient.LoginAsync(); await _apiClient.LoginAsync();
await using var ins = await _apiClient.DownloadAsync(state.Url, cancellationToken: token); await using var ins = await _apiClient.DownloadAsync(state!.Url, cancellationToken: token);
return await fn(ins); return await fn(ins);
} }

View File

@ -20,7 +20,7 @@ using Wabbajack.RateLimiter;
namespace Wabbajack.Downloaders.ModDB; namespace Wabbajack.Downloaders.ModDB;
public class ModDBDownloader : ADownloader<DTOs.DownloadStates.ModDB>, IUrlDownloader, IProxyable public class ModDBDownloader : ADownloader<DTOs.DownloadStates.ModDB>, IProxyable
{ {
private readonly IHttpDownloader _downloader; private readonly IHttpDownloader _downloader;
private readonly HttpClient _httpClient; private readonly HttpClient _httpClient;
@ -98,8 +98,7 @@ public class ModDBDownloader : ADownloader<DTOs.DownloadStates.ModDB>, IUrlDownl
throw; throw;
} }
} }
_logger.LogError("All servers were invalid downloading from ModDB {Uri}", state.Url); throw new Exception($"All servers were invalid downloading from ModDB {state!.Url}");
return default;
} }
public override async Task<Hash> Download(Archive archive, DTOs.DownloadStates.ModDB state, public override async Task<Hash> Download(Archive archive, DTOs.DownloadStates.ModDB state,

View File

@ -33,7 +33,6 @@ public class WabbajackCDNDownloader : ADownloader<WabbajackCDN>, IUrlDownloader,
private readonly HttpClient _client; private readonly HttpClient _client;
private readonly DTOSerializer _dtos; private readonly DTOSerializer _dtos;
private readonly ILogger<WabbajackCDNDownloader> _logger; private readonly ILogger<WabbajackCDNDownloader> _logger;
private readonly ParallelOptions _parallelOptions;
private readonly IResource<HttpClient> _limiter; private readonly IResource<HttpClient> _limiter;
public WabbajackCDNDownloader(ILogger<WabbajackCDNDownloader> logger, HttpClient client, IResource<HttpClient> limiter, DTOSerializer dtos) public WabbajackCDNDownloader(ILogger<WabbajackCDNDownloader> logger, HttpClient client, IResource<HttpClient> limiter, DTOSerializer dtos)

View File

@ -152,10 +152,10 @@ public abstract class AInstaller<T>
return await fullPath.ReadAllBytesAsync(); return await fullPath.ReadAllBytesAsync();
} }
public async Task<Stream> InlinedFileStream(RelativePath inlinedFile) public Task<Stream> InlinedFileStream(RelativePath inlinedFile)
{ {
var fullPath = ExtractedModlistFolder.Path.Combine(inlinedFile); var fullPath = ExtractedModlistFolder.Path.Combine(inlinedFile);
return fullPath.Open(FileMode.Open, FileAccess.Read, FileShare.Read); return Task.FromResult(fullPath.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
} }
public static async Task<ModList> LoadFromFile(DTOSerializer serializer, AbsolutePath path) public static async Task<ModList> LoadFromFile(DTOSerializer serializer, AbsolutePath path)
@ -200,7 +200,7 @@ public abstract class AInstaller<T>
await _vfs.BackfillMissing(); await _vfs.BackfillMissing();
} }
public async Task BuildFolderStructure() public Task BuildFolderStructure()
{ {
NextStep(Consts.StepPreparing, "Building Folder Structure", 0); NextStep(Consts.StepPreparing, "Building Folder Structure", 0);
_logger.LogInformation("Building Folder Structure"); _logger.LogInformation("Building Folder Structure");
@ -209,6 +209,7 @@ public abstract class AInstaller<T>
.Select(d => _configuration.Install.Combine(d.To.Parent)) .Select(d => _configuration.Install.Combine(d.To.Parent))
.Distinct() .Distinct()
.Do(f => f.CreateDirectory()); .Do(f => f.CreateDirectory());
return Task.CompletedTask;
} }
public async Task InstallArchives(CancellationToken token) public async Task InstallArchives(CancellationToken token)
@ -406,7 +407,7 @@ public abstract class AInstaller<T>
.ToList(); .ToList();
_logger.LogInformation("Getting archive sizes"); _logger.LogInformation("Getting archive sizes");
var hashDict = (await allFiles.PMapAll(_limiter, async x => (x, x.Size())).ToList()) var hashDict = (await allFiles.PMapAllBatched(_limiter, x => (x, x.Size())).ToList())
.GroupBy(f => f.Item2) .GroupBy(f => f.Item2)
.ToDictionary(g => g.Key, g => g.Select(v => v.x)); .ToDictionary(g => g.Key, g => g.Select(v => v.x));
@ -485,7 +486,7 @@ public abstract class AInstaller<T>
NextStep(Consts.StepPreparing, "Looking for files to delete", 0); NextStep(Consts.StepPreparing, "Looking for files to delete", 0);
await _configuration.Install.EnumerateFiles() await _configuration.Install.EnumerateFiles()
.PMapAllBatched(_limiter, async f => .PMapAllBatched(_limiter, f =>
{ {
var relativeTo = f.RelativeTo(_configuration.Install); var relativeTo = f.RelativeTo(_configuration.Install);
if (indexed.ContainsKey(relativeTo) || f.InFolder(_configuration.Downloads)) if (indexed.ContainsKey(relativeTo) || f.InFolder(_configuration.Downloads))
@ -541,7 +542,7 @@ public abstract class AInstaller<T>
var existingfiles = _configuration.Install.EnumerateFiles().ToHashSet(); var existingfiles = _configuration.Install.EnumerateFiles().ToHashSet();
NextStep(Consts.StepPreparing, "Looking for unmodified files", 0); NextStep(Consts.StepPreparing, "Looking for unmodified files", 0);
await indexed.Values.PMapAllBatched(_limiter, async d => await indexed.Values.PMapAllBatchedAsync(_limiter, async d =>
{ {
// Bit backwards, but we want to return null for // Bit backwards, but we want to return null for
// all files we *want* installed. We return the files // all files we *want* installed. We return the files

View File

@ -154,10 +154,10 @@ public class StandardInstaller : AInstaller<StandardInstaller>
return true; return true;
} }
private async Task RemapMO2File() private Task RemapMO2File()
{ {
var iniFile = _configuration.Install.Combine("ModOrganizer.ini"); var iniFile = _configuration.Install.Combine("ModOrganizer.ini");
if (!iniFile.FileExists()) return; if (!iniFile.FileExists()) return Task.CompletedTask;
_logger.LogInformation("Remapping ModOrganizer.ini"); _logger.LogInformation("Remapping ModOrganizer.ini");
@ -165,6 +165,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
var settings = iniData["Settings"]; var settings = iniData["Settings"];
settings["download_directory"] = _configuration.Downloads.ToString().Replace("\\", "/"); settings["download_directory"] = _configuration.Downloads.ToString().Replace("\\", "/");
iniData.SaveIniFile(iniFile); iniData.SaveIniFile(iniFile);
return Task.CompletedTask;
} }
private void CreateOutputMods() private void CreateOutputMods()
@ -361,7 +362,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
if (data.Sections["Display"]["iSize W"] != null && data.Sections["Display"]["iSize H"] != null) if (data.Sections["Display"]["iSize W"] != null && data.Sections["Display"]["iSize H"] != null)
{ {
data.Sections["Display"]["iSize W"] = data.Sections["Display"]["iSize W"] =
_configuration.SystemParameters.ScreenWidth.ToString(CultureInfo.CurrentCulture); _configuration.SystemParameters!.ScreenWidth.ToString(CultureInfo.CurrentCulture);
data.Sections["Display"]["iSize H"] = data.Sections["Display"]["iSize H"] =
_configuration.SystemParameters.ScreenHeight.ToString(CultureInfo.CurrentCulture); _configuration.SystemParameters.ScreenHeight.ToString(CultureInfo.CurrentCulture);
modified = true; modified = true;
@ -371,7 +372,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
if (data.Sections["MEMORY"]["VideoMemorySizeMb"] != null) if (data.Sections["MEMORY"]["VideoMemorySizeMb"] != null)
{ {
data.Sections["MEMORY"]["VideoMemorySizeMb"] = data.Sections["MEMORY"]["VideoMemorySizeMb"] =
_configuration.SystemParameters.EnbLEVRAMSize.ToString(CultureInfo.CurrentCulture); _configuration.SystemParameters!.EnbLEVRAMSize.ToString(CultureInfo.CurrentCulture);
modified = true; modified = true;
} }
@ -397,7 +398,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
if (data.Sections["Render"]["Resolution"] != null) if (data.Sections["Render"]["Resolution"] != null)
{ {
data.Sections["Render"]["Resolution"] = data.Sections["Render"]["Resolution"] =
$"{_configuration.SystemParameters.ScreenWidth.ToString(CultureInfo.CurrentCulture)}x{_configuration.SystemParameters.ScreenHeight.ToString(CultureInfo.CurrentCulture)}"; $"{_configuration.SystemParameters!.ScreenWidth.ToString(CultureInfo.CurrentCulture)}x{_configuration.SystemParameters.ScreenHeight.ToString(CultureInfo.CurrentCulture)}";
modified = true; modified = true;
} }
@ -464,7 +465,7 @@ public class StandardInstaller : AInstaller<StandardInstaller>
.ToList(); .ToList();
NextStep("Installing", "Generating ZEdit Merges", patches.Count); NextStep("Installing", "Generating ZEdit Merges", patches.Count);
await patches.PMapAllBatched(_limiter, async m => await patches.PMapAllBatchedAsync(_limiter, async m =>
{ {
UpdateProgress(1); UpdateProgress(1);
_logger.LogInformation("Generating zEdit merge: {to}", m.To); _logger.LogInformation("Generating zEdit merge: {to}", m.To);

View File

@ -7,9 +7,10 @@ namespace Wabbajack.Installer.Utilities;
public class BinaryPatching public class BinaryPatching
{ {
public static async ValueTask ApplyPatch(Stream input, Stream deltaStream, Stream output) public static ValueTask ApplyPatch(Stream input, Stream deltaStream, Stream output)
{ {
var deltaApplier = new DeltaApplier(); var deltaApplier = new DeltaApplier();
deltaApplier.Apply(input, new BinaryDeltaReader(deltaStream, new NullProgressReporter()), output); deltaApplier.Apply(input, new BinaryDeltaReader(deltaStream, new NullProgressReporter()), output);
return ValueTask.CompletedTask;
} }
} }

View File

@ -7,6 +7,10 @@
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression> <PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<NoWarn>CS8600,CS8601,CS8618,CS8604</NoWarn>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Wabbajack.Downloaders.Dispatcher\Wabbajack.Downloaders.Dispatcher.csproj" /> <ProjectReference Include="..\Wabbajack.Downloaders.Dispatcher\Wabbajack.Downloaders.Dispatcher.csproj" />
<ProjectReference Include="..\Wabbajack.Downloaders.GameFile\Wabbajack.Downloaders.GameFile.csproj" /> <ProjectReference Include="..\Wabbajack.Downloaders.GameFile\Wabbajack.Downloaders.GameFile.csproj" />

View File

@ -1,4 +1,5 @@
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
using System.Text.Json; using System.Text.Json;
@ -25,12 +26,12 @@ public class Client
private readonly ILogger<Client> _logger; private readonly ILogger<Client> _logger;
private readonly HttpClient _httpClient; private readonly HttpClient _httpClient;
private readonly JsonSerializerOptions _jsonOptions; private readonly JsonSerializerOptions _jsonOptions;
private CDPAuthResponse? _entitlementData = null; private CDPAuthResponse? _entitlementData;
public const string AgentPlatform = "WINDOWS"; private const string AgentPlatform = "WINDOWS";
public const string AgentProduct = "FALLOUT4"; private const string AgentProduct = "FALLOUT4";
public const string AgentLanguage = "en"; private const string AgentLanguage = "en";
private const string ClientAPIKey = "FeBqmQA8wxd94RtqymKwzmtcQcaA5KHOpDkQBSegx4WePeluZTCIm5scoeKTbmGl"; private const string ClientApiKey = "FeBqmQA8wxd94RtqymKwzmtcQcaA5KHOpDkQBSegx4WePeluZTCIm5scoeKTbmGl";
private const string ClientId = "95578d65-45bf-4a03-b7f7-a43d29b9467d"; //private const string ClientId = "95578d65-45bf-4a03-b7f7-a43d29b9467d";
private const string AgentVersion = $"{AgentProduct};;BDK;1.0013.99999.1;{AgentPlatform}"; private const string AgentVersion = $"{AgentProduct};;BDK;1.0013.99999.1;{AgentPlatform}";
private string FingerprintKey { get; set; } private string FingerprintKey { get; set; }
@ -50,14 +51,15 @@ public class Client
public async Task Login(CancellationToken token) public async Task Login(CancellationToken token)
{ {
_logger.LogInformation("Logging into BethesdaNet");
var loginData = await _tokenProvider.Get(); var loginData = await _tokenProvider.Get();
var msg = MakeMessage(HttpMethod.Post, new Uri($"https://api.bethesda.net/beam/accounts/login/{loginData!.Username}")); var msg = MakeMessage(HttpMethod.Post, new Uri($"https://api.bethesda.net/beam/accounts/login/{loginData!.Username}"));
msg.Headers.Add("X-Client-API-key", ClientAPIKey); msg.Headers.Add("X-Client-API-key", ClientApiKey);
msg.Headers.Add("x-src-fp", FingerprintKey); msg.Headers.Add("x-src-fp", FingerprintKey);
msg.Headers.Add("X-Platform", AgentPlatform); msg.Headers.Add("X-Platform", AgentPlatform);
msg.Content = new StringContent(JsonSerializer.Serialize(new BeamLogin msg.Content = new StringContent(JsonSerializer.Serialize(new BeamLogin
{ {
Password = loginData!.Password, Password = loginData.Password,
Language = AgentLanguage Language = AgentLanguage
}, _jsonOptions), Encoding.UTF8, "application/json"); }, _jsonOptions), Encoding.UTF8, "application/json");
@ -71,10 +73,10 @@ public class Client
await _tokenProvider.SetToken(loginData); await _tokenProvider.SetToken(loginData);
} }
public async Task CDPAuth(CancellationToken token) public async Task CdpAuth(CancellationToken token)
{ {
var state = await _tokenProvider.Get(); var state = await _tokenProvider.Get();
if (string.IsNullOrEmpty(state.BeamResponse?.AccessToken)) if (string.IsNullOrEmpty(state!.BeamResponse?.AccessToken))
throw new Exception("Can't get CDPAuth before Bethesda Net login"); throw new Exception("Can't get CDPAuth before Bethesda Net login");
var msg = MakeMessage(HttpMethod.Post, new Uri("https://api.bethesda.net/cdp-user/auth")); var msg = MakeMessage(HttpMethod.Post, new Uri("https://api.bethesda.net/cdp-user/auth"));
@ -106,7 +108,7 @@ public class Client
private void SetFingerprint() private void SetFingerprint()
{ {
var keyBytes = new byte[20]; var keyBytes = new byte[20];
using (var rng = new System.Security.Cryptography.RNGCryptoServiceProvider()) using (var rng = RandomNumberGenerator.Create())
rng.GetBytes(keyBytes); rng.GetBytes(keyBytes);
FingerprintKey = string.Concat(Array.ConvertAll(keyBytes, x => x.ToString("X2"))); FingerprintKey = string.Concat(Array.ConvertAll(keyBytes, x => x.ToString("X2")));
@ -145,15 +147,9 @@ public class Client
private async Task EnsureAuthed(CancellationToken token) private async Task EnsureAuthed(CancellationToken token)
{ {
if (_entitlementData == null) if (_entitlementData == null)
await CDPAuth(token); await CdpAuth(token);
} }
private int ProductId(Game game)
{
if (game == Game.SkyrimSpecialEdition) return 4;
return 0;
}
public async Task<Depot?> GetDepots(Bethesda state, CancellationToken token) public async Task<Depot?> GetDepots(Bethesda state, CancellationToken token)
{ {
return (await MakeCdpRequest<Dictionary<string, Depot>>(state, "depots", token))?.Values.First(); return (await MakeCdpRequest<Dictionary<string, Depot>>(state, "depots", token))?.Values.First();

View File

@ -34,8 +34,6 @@ public class Client : IDisposable
private string? _twoFactorCode; private string? _twoFactorCode;
private string? _authCode; private string? _authCode;
private readonly IUserInterventionHandler _interventionHandler; private readonly IUserInterventionHandler _interventionHandler;
private bool _isConnected;
private bool _isLoggedIn;
private bool _haveSigFile; private bool _haveSigFile;
public TaskCompletionSource _licenseRequest = new(); public TaskCompletionSource _licenseRequest = new();
@ -93,8 +91,6 @@ public class Client : IDisposable
_manager.Subscribe<SteamUser.UpdateMachineAuthCallback>( OnUpdateMachineAuthCallback ); _manager.Subscribe<SteamUser.UpdateMachineAuthCallback>( OnUpdateMachineAuthCallback );
_isConnected = false;
_isLoggedIn = false;
_haveSigFile = false; _haveSigFile = false;
new Thread(() => new Thread(() =>
@ -170,7 +166,6 @@ public class Client : IDisposable
private void OnLoggedOff(SteamUser.LoggedOffCallback obj) private void OnLoggedOff(SteamUser.LoggedOffCallback obj)
{ {
_isLoggedIn = false;
} }
private void OnLoggedOn(SteamUser.LoggedOnCallback callback) private void OnLoggedOn(SteamUser.LoggedOnCallback callback)
@ -206,7 +201,6 @@ public class Client : IDisposable
return; return;
} }
_isLoggedIn = true;
_logger.LogInformation("Logged into Steam"); _logger.LogInformation("Logged into Steam");
if (_haveSigFile) if (_haveSigFile)
_loginTask.SetResult(); _loginTask.SetResult();
@ -215,7 +209,6 @@ public class Client : IDisposable
private void OnDisconnected(SteamClient.DisconnectedCallback obj) private void OnDisconnected(SteamClient.DisconnectedCallback obj)
{ {
_isConnected = false;
_logger.LogInformation("Logged out"); _logger.LogInformation("Logged out");
} }
@ -239,9 +232,7 @@ public class Client : IDisposable
{ {
_haveSigFile = false; _haveSigFile = false;
} }
_isConnected = true;
_steamUser.LogOn(new SteamUser.LogOnDetails _steamUser.LogOn(new SteamUser.LogOnDetails
{ {
Username = state.User, Username = state.User,

View File

@ -8,11 +8,4 @@
<PropertyGroup> <PropertyGroup>
<NoWarn>CS8600,CS8601,CS8618,CS8604</NoWarn> <NoWarn>CS8600,CS8601,CS8618,CS8604</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<HintPath>..\..\..\..\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\6.0.0-preview.6.21355.2\ref\net6.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
</Project> </Project>