Skip to content

Commit

Permalink
Remove ipc code (#797)
Browse files Browse the repository at this point in the history
* WIP removed IPC code and replacing IResource with Activities

* More changes caused by removing the rate limiter

* Remove more dead code

* WIP

* Lots more refactoring

* Latest work, likely will need to revert some of this

* Somehow this whole thing builds

* A few tests pass

* Fix a few broken tests

* All the tests pass? What is this madness?

* Code cleanup

* Latest cleanup

* Remove unused imports

* Make some internal classes internal

* Add some debugging code, found when I was verifying OAuth still worked

* Handle PR feedback

* Switch from T? to Optional<T>

* Merge main

* Merge main (again)
  • Loading branch information
halgari authored Nov 30, 2023
1 parent 753a9b1 commit 79171ab
Show file tree
Hide file tree
Showing 123 changed files with 1,120 additions and 3,217 deletions.
14 changes: 0 additions & 14 deletions NexusMods.App.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.App", "src\NexusM
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.CLI.Tests", "tests\NexusMods.CLI.Tests\NexusMods.CLI.Tests.csproj", "{A4B8AD2F-BCF9-4139-8F0C-36B528FDBF66}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.DataModel.RateLimiting", "src\NexusMods.DataModel.RateLimiting\NexusMods.DataModel.RateLimiting.csproj", "{B4CA4927-6FFA-422B-8E54-413ECFCD6C39}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.DataModel", "src\NexusMods.DataModel\NexusMods.DataModel.csproj", "{3D21A286-CADC-40CF-AF29-790DAAD4363A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.DataModel.Tests", "tests\NexusMods.DataModel.Tests\NexusMods.DataModel.Tests.csproj", "{9F803B18-7365-418E-9873-414383CD820B}"
Expand All @@ -29,8 +27,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.Common", "src\Nex
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.FileExtractor.Tests", "tests\NexusMods.FileExtractor.Tests\NexusMods.FileExtractor.Tests.csproj", "{AB2AD95A-17AA-473B-8E1C-02ACED2F8520}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.DataModel.RateLimiting.Tests", "tests\NexusMods.DataModel.RateLimiting.Tests\NexusMods.DataModel.RateLimiting.Tests.csproj", "{1E5939B0-0C91-4074-94F6-A70F522B99B7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.Games.DarkestDungeon", "src\Games\NexusMods.Games.DarkestDungeon\NexusMods.Games.DarkestDungeon.csproj", "{EDDDDE44-9059-4F05-83F4-D0C5D0AE2CC3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NexusMods.App.UI", "src\NexusMods.App.UI\NexusMods.App.UI.csproj", "{4767144A-0130-47F2-9940-5D68CCBEE241}"
Expand Down Expand Up @@ -165,10 +161,6 @@ Global
{A4B8AD2F-BCF9-4139-8F0C-36B528FDBF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4B8AD2F-BCF9-4139-8F0C-36B528FDBF66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4B8AD2F-BCF9-4139-8F0C-36B528FDBF66}.Release|Any CPU.Build.0 = Release|Any CPU
{B4CA4927-6FFA-422B-8E54-413ECFCD6C39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4CA4927-6FFA-422B-8E54-413ECFCD6C39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4CA4927-6FFA-422B-8E54-413ECFCD6C39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4CA4927-6FFA-422B-8E54-413ECFCD6C39}.Release|Any CPU.Build.0 = Release|Any CPU
{3D21A286-CADC-40CF-AF29-790DAAD4363A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D21A286-CADC-40CF-AF29-790DAAD4363A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D21A286-CADC-40CF-AF29-790DAAD4363A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -189,10 +181,6 @@ Global
{AB2AD95A-17AA-473B-8E1C-02ACED2F8520}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB2AD95A-17AA-473B-8E1C-02ACED2F8520}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB2AD95A-17AA-473B-8E1C-02ACED2F8520}.Release|Any CPU.Build.0 = Release|Any CPU
{1E5939B0-0C91-4074-94F6-A70F522B99B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E5939B0-0C91-4074-94F6-A70F522B99B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E5939B0-0C91-4074-94F6-A70F522B99B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E5939B0-0C91-4074-94F6-A70F522B99B7}.Release|Any CPU.Build.0 = Release|Any CPU
{EDDDDE44-9059-4F05-83F4-D0C5D0AE2CC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDDDDE44-9059-4F05-83F4-D0C5D0AE2CC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDDDDE44-9059-4F05-83F4-D0C5D0AE2CC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -335,13 +323,11 @@ Global
{D66C4BA1-C129-4DC1-954E-6D9E0B9CB691} = {E7BAE287-D505-4D6D-A090-665A64309B2D}
{78B79659-4A68-4E92-8765-E6570916792F} = {E7BAE287-D505-4D6D-A090-665A64309B2D}
{3D21A286-CADC-40CF-AF29-790DAAD4363A} = {E7BAE287-D505-4D6D-A090-665A64309B2D}
{B4CA4927-6FFA-422B-8E54-413ECFCD6C39} = {E7BAE287-D505-4D6D-A090-665A64309B2D}
{BB552259-24B0-4166-8A67-5649CE42BE83} = {E7BAE287-D505-4D6D-A090-665A64309B2D}
{A4B8AD2F-BCF9-4139-8F0C-36B528FDBF66} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
{643BE310-8A6C-405C-AAE5-E0A3A3298624} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
{4FD95FB7-BD1D-4D79-90F8-9980DE5D6C28} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
{846232AE-BDEA-4673-918E-A2079D4E78E0} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
{1E5939B0-0C91-4074-94F6-A70F522B99B7} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
{9F803B18-7365-418E-9873-414383CD820B} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
{AB2AD95A-17AA-473B-8E1C-02ACED2F8520} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
{897C4198-884F-448A-B0B0-C2A6D971EAE0} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
Expand Down
9 changes: 2 additions & 7 deletions benchmarks/NexusMods.Benchmarks/Benchmarks/DataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
using NexusMods.DataModel;
using NexusMods.DataModel.Abstractions;
using NexusMods.DataModel.Abstractions.Ids;
using NexusMods.DataModel.Interprocess;
using NexusMods.DataModel.Interprocess.Messages;
using NexusMods.DataModel.Loadouts;
using NexusMods.DataModel.Loadouts.ModFiles;
using NexusMods.Hashing.xxHash64;
using NexusMods.DataModel.Messaging;
using NexusMods.Paths;
using NexusMods.Paths.Extensions;
using Hash = NexusMods.Hashing.xxHash64.Hash;

namespace NexusMods.Benchmarks.Benchmarks;
Expand Down Expand Up @@ -43,9 +40,7 @@ public DataStoreBenchmark()
var provider = host.Services.GetRequiredService<IServiceProvider>();
_dataStore = new SqliteDataStore(
provider.GetRequiredService<ILogger<SqliteDataStore>>(),
new DataModelSettings(FileSystem.Shared), provider,
provider.GetRequiredService<IMessageProducer<IdUpdated>>(),
provider.GetRequiredService<IMessageConsumer<IdUpdated>>());
new DataModelSettings(FileSystem.Shared), provider);

_rawData = new byte[1024];
Random.Shared.NextBytes(_rawData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
using NexusMods.Abstractions.Activities;
using NexusMods.Common;
using NexusMods.FileExtractor.FileSignatures;
using NexusMods.Paths;

namespace NexusMods.FileExtractor.Extractors;

/// <summary>
/// General purpose abstraction over an extracting library for utility.
/// Each <see cref="IExtractor"/> can support extracting from one or more archive formats.
/// General purpose abstraction over an extracting library for utility.
/// Each <see cref="IExtractor"/> can support extracting from one or more archive formats.
/// </summary>
public interface IExtractor
{
/// <summary>
/// The activity group for activities created by extractors.
/// </summary>
public static readonly ActivityGroup Group = ActivityGroup.From("FileExtractor");

/// <summary>
/// A list of all the file type signatures supported by this extractor.
/// </summary>
Expand All @@ -29,14 +35,14 @@ public interface IExtractor
/// <typeparam name="T">Return type</typeparam>
/// <returns>A Dictionary of RelativePath -> Return value from `func`</returns>
/// <remarks>
/// Does not extract files to disk. If you need to save the data; copy it elsewhere.
/// The source data passed to func can be in-memory.
/// Does not extract files to disk. If you need to save the data; copy it elsewhere.
/// The source data passed to func can be in-memory.
/// </remarks>
public Task<IDictionary<RelativePath, T>> ForEachEntryAsync<T>(IStreamFactory source,
Func<RelativePath, IStreamFactory, ValueTask<T>> func, CancellationToken token = default);

Check failure on line 42 in src/ArchiveManagement/NexusMods.FileExtractor/Extractors/IExtractor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible null reference assignment.

Possible null reference assignment

/// <summary>
/// Unconditionally extract all files from `sFn` to a specific folder.
/// Unconditionally extract all files from `sFn` to a specific folder.
/// </summary>
/// <param name="source">The source of the incoming stream</param>
/// <param name="destination">Where the files are to be extracted</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using CliWrap.Exceptions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using NexusMods.Abstractions.Activities;
using NexusMods.Common;
using NexusMods.DataModel.RateLimiting;
using NexusMods.DataModel.Activities;
using NexusMods.FileExtractor.FileSignatures;
using NexusMods.FileExtractor.StreamFactories;
using NexusMods.Paths;
Expand All @@ -26,7 +27,7 @@ public class SevenZipExtractor : IExtractor
{
private readonly TemporaryFileManager _manager;
private readonly ILogger<SevenZipExtractor> _logger;
private readonly IResource<IExtractor, Size> _limiter;
private readonly IActivityFactory _activityFactory;

private static readonly IOSInformation OSInformation = Paths.OSInformation.Shared;

Expand All @@ -45,27 +46,29 @@ public class SevenZipExtractor : IExtractor
/// </summary>
/// <param name="logger">Provides logger support. Use <see cref="NullLogger.Instance"/> if you don't want logging.</param>

Check warning on line 47 in src/ArchiveManagement/NexusMods.FileExtractor/Extractors/SevenZipExtractor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Cannot resolve reference in XML comment

Cannot resolve symbol 'NullLogger'
/// <param name="fileManager">Manager that can be used to create temporary folders.</param>
/// <param name="limiter">Limits CPU core usage depending on our use case.</param>
/// <param name="activityFactory"></param>
/// <param name="fileSystem">Filesystem to use when constructing and using paths</param>
public SevenZipExtractor(ILogger<SevenZipExtractor> logger, TemporaryFileManager fileManager, IResource<IExtractor, Size> limiter, IFileSystem fileSystem)
public SevenZipExtractor(ILogger<SevenZipExtractor> logger, TemporaryFileManager fileManager, IActivityFactory activityFactory, IFileSystem fileSystem)
{
_logger = logger;
_manager = fileManager;
_limiter = limiter;
_activityFactory = activityFactory;
_exePath = fileSystem.GetKnownPath(KnownPath.EntryDirectory).Combine(GetExeLocation().ToRelativePath()).ToString();
}

/// <inheritdoc />
public async Task ExtractAllAsync(IStreamFactory sFn, AbsolutePath destination, CancellationToken token)
{
using var job = await _limiter.BeginAsync($"[{nameof(ExtractAllAsync)}] Extracting {sFn.Name.FileName}", sFn.Size, token);
using var job = _activityFactory.Create<Size>(IExtractor.Group, "Extracting {File}", sFn.Name);
await ExtractAllAsync_Impl(sFn, destination, token, job);
}

/// <inheritdoc />
public async Task<IDictionary<RelativePath, T>> ForEachEntryAsync<T>(IStreamFactory sFn, Func<RelativePath, IStreamFactory, ValueTask<T>> func, CancellationToken token)
{
using var job = await _limiter.BeginAsync($"[{nameof(ForEachEntryAsync)}] Extracting {sFn.Name.FileName}", sFn.Size, token);
using var job = _activityFactory.Create<Size>(IExtractor.Group, "Extracting {File}", sFn.Name);
job.SetMax(sFn.Size);

await using var dest = _manager.CreateFolder();
await ExtractAllAsync_Impl(sFn, dest, token, job);

Expand Down Expand Up @@ -101,7 +104,7 @@ from sig in signatures
return Priority.None;
}

private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destination, CancellationToken token, IJob<IExtractor, Size> job)
private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destination, CancellationToken token, IActivitySource<Size> activity)
{
TemporaryPath? spoolFile = null;
var processStdOutput = new StringBuilder();
Expand All @@ -127,9 +130,9 @@ private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destina

var totalSize = source.FileInfo.Size;
var lastPercent = 0;
job.Size = totalSize;

activity.SetMax(totalSize);

// NOTE: 7z.exe has a bug with long destination path with forwards `/` separators on windows,
// as a workaround we need to change the separators to backwards '\' on windows.
// See: https://sourceforge.net/p/sevenzip/discussion/45797/thread/a9a0f02618/
Expand All @@ -143,20 +146,20 @@ private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destina
{
if (string.IsNullOrWhiteSpace(line)) return;
processStdOutput.AppendLine($"[7z stdout] {line}");

if (line.Length <= 4 || line[3] != '%') return;
if (!int.TryParse(line.AsSpan()[..3], out var percentInt)) return;

var oldPosition = lastPercent == 0 ? Size.Zero : totalSize / 100 * lastPercent;
var newPosition = percentInt == 0 ? Size.Zero : totalSize / 100 * percentInt;
var throughput = newPosition - oldPosition;
if (throughput > Size.Zero)
job.ReportNoWait(throughput);
activity.AddProgress(throughput);

lastPercent = percentInt;
}))
.WithStandardErrorPipe(PipeTarget.ToDelegate(line =>
{
{
if (string.IsNullOrWhiteSpace(line)) return;
processStdError.AppendLine($"[7z stderr] {line}");
}))
Expand All @@ -168,7 +171,7 @@ private async Task ExtractAllAsync_Impl(IStreamFactory sFn, AbsolutePath destina
catch (CommandExecutionException ex)
{
_logger.LogError(ex, "While executing 7zip");
_logger.LogInformation("Output from the extractor, trying to extract file {File}:\n{StdOutput}\n{StdError}",
_logger.LogInformation("Output from the extractor, trying to extract file {File}:\n{StdOutput}\n{StdError}",
sFn.Name, processStdOutput.ToString(), processStdError.ToString());
throw;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('NuGet.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<ProjectReference Include="..\..\NexusMods.Abstractions\NexusMods.Abstractions.csproj" />
<ProjectReference Include="..\..\NexusMods.Common\NexusMods.Common.csproj" />
<ProjectReference Include="..\..\NexusMods.DataModel.RateLimiting\NexusMods.DataModel.RateLimiting.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CliWrap" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="NexusMods.ProxyConsole.Abstractions" />
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="TransparentValueObjects" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/ArchiveManagement/NexusMods.FileExtractor/Services.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NexusMods.DataModel.RateLimiting;
using NexusMods.FileExtractor.Extractors;
using NexusMods.Paths;

Expand All @@ -27,7 +26,6 @@ public static IServiceCollection AddFileExtractors(this IServiceCollection coll,
coll.AddSingleton<FileExtractor>();
coll.AddSingleton<IExtractor, SevenZipExtractor>();
coll.TryAddSingleton<TemporaryFileManager, TemporaryFileManagerEx>();
coll.TryAddSingleton<IResource<IExtractor, Size>>(_ => new Resource<IExtractor, Size>("File Extraction"));
return coll;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using NexusMods.Abstractions.Values;
using NexusMods.App.UI;
using NexusMods.DataModel.RateLimiting;
using ReactiveUI;

Check warning on line 5 in src/Games/NexusMods.Games.FOMOD.UI/FooterStepper/FooterStepperDesignViewModel.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using ReactiveUI.Fody.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using NexusMods.Abstractions.Values;
using NexusMods.App.UI;
using NexusMods.DataModel.RateLimiting;
using ReactiveUI;

Check warning on line 6 in src/Games/NexusMods.Games.FOMOD.UI/FooterStepper/FooterStepperViewModel.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using ReactiveUI.Fody.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reactive;
using NexusMods.Abstractions.Values;
using NexusMods.App.UI;
using NexusMods.DataModel.RateLimiting;
using ReactiveUI;

Check warning on line 4 in src/Games/NexusMods.Games.FOMOD.UI/FooterStepper/IFooterStepperViewModel.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed

namespace NexusMods.Games.FOMOD.UI;
Expand Down
2 changes: 1 addition & 1 deletion src/Games/NexusMods.Games.FOMOD.UI/GuidedInstallerUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using Avalonia.ReactiveUI;

Check warning on line 4 in src/Games/NexusMods.Games.FOMOD.UI/GuidedInstallerUi.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using NexusMods.Abstractions.Values;
using NexusMods.App.UI;
using NexusMods.Common.GuidedInstaller;
using NexusMods.DataModel.RateLimiting;
using ReactiveUI;

namespace NexusMods.Games.FOMOD.UI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using Avalonia.Media;
using DynamicData;
using JetBrains.Annotations;
using NexusMods.Abstractions.Values;
using NexusMods.App.UI;
using NexusMods.Common.GuidedInstaller;
using NexusMods.Common.GuidedInstaller.ValueObjects;
using NexusMods.DataModel.RateLimiting;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.ObjectModel;
using Avalonia.Media;
using NexusMods.Abstractions.Values;

Check warning on line 3 in src/Games/NexusMods.Games.FOMOD.UI/Step/IGuidedInstallerStepViewModel.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using NexusMods.App.UI;
using NexusMods.Common.GuidedInstaller;
using NexusMods.DataModel.RateLimiting;

namespace NexusMods.Games.FOMOD.UI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Diagnostics;
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.Values;
using NexusMods.Common;
using NexusMods.Common.GuidedInstaller;
using NexusMods.Common.GuidedInstaller.ValueObjects;
using NexusMods.DataModel.ModInstallers;
using NexusMods.DataModel.RateLimiting;
using NexusMods.Paths;
using NexusMods.Paths.FileTree;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
using DynamicData;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.DateTime;
using NexusMods.Common;
using NexusMods.DataModel;
using NexusMods.DataModel.Abstractions;
using NexusMods.DataModel.Abstractions.Ids;
using NexusMods.DataModel.ArchiveMetaData;
using NexusMods.DataModel.RateLimiting;
using NexusMods.Hashing.xxHash64;
using NexusMods.Networking.Downloaders.Interfaces;
using NexusMods.Networking.Downloaders.Tasks;
using NexusMods.Networking.Downloaders.Tasks.State;
Expand Down Expand Up @@ -170,10 +169,9 @@ public void OnPaused(IDownloadTask task)
/// <inheritdoc />
public Size GetThroughput()
{
var provider = DateTimeProvider.Instance;
var totalThroughput = 0L;
foreach (var download in _currentDownloads)
totalThroughput += download.CalculateThroughput(provider);
totalThroughput += download.CalculateThroughput();

return Size.FromLong(totalThroughput);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using DynamicData;
using NexusMods.DataModel;
using NexusMods.DataModel.RateLimiting;
using NexusMods.Hashing.xxHash64;
using NexusMods.Networking.NexusWebApi.Types;
using NexusMods.Paths;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NexusMods.DataModel.RateLimiting;
using NexusMods.Abstractions.DateTime;
using NexusMods.Networking.Downloaders.Tasks.State;

namespace NexusMods.Networking.Downloaders.Interfaces;
Expand All @@ -18,7 +18,7 @@ public interface IDownloadTask
/// Calculates the download speed of the current job.
/// </summary>
/// <returns>Current speed in terms of bytes per second.</returns>
long CalculateThroughput<TDateTimeProvider>(TDateTimeProvider provider) where TDateTimeProvider : IDateTimeProvider;
long CalculateThroughput();

/// <summary>
/// Service this task is associated with.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\NexusMods.DataModel.RateLimiting\NexusMods.DataModel.RateLimiting.csproj" />
<ProjectReference Include="..\..\NexusMods.DataModel\NexusMods.DataModel.csproj" />
<ProjectReference Include="..\NexusMods.Networking.HttpDownloader\NexusMods.Networking.HttpDownloader.csproj" />
<ProjectReference Include="..\NexusMods.Networking.NexusWebApi\NexusMods.Networking.NexusWebApi.csproj" />
Expand Down
Loading

0 comments on commit 79171ab

Please sign in to comment.