Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add faster file download approach #2672

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
069ba2b
Replace usage of ResumableDownloader with NonReusableDownloader for f…
AlexDickerson Dec 27, 2024
dc6847e
Reverted unneeded change to AInstaller
AlexDickerson Dec 27, 2024
28a7f4e
Added more explicit error logging
AlexDickerson Dec 27, 2024
861e7df
Synced Namespaces
AlexDickerson Dec 27, 2024
44fe695
Adding UI for setting minimum file size at which to use resumable dow…
AlexDickerson Dec 28, 2024
fa7b2a0
Reverting unintended changes
AlexDickerson Dec 28, 2024
5ef9812
Reverting unneeded changes
AlexDickerson Dec 28, 2024
c25f439
Remove deprecated nexus auth method
AlexDickerson Dec 28, 2024
e8eff20
Merge pull request #2673 from AlexDickerson/removeSetNexusAPI
tr4wzified Dec 28, 2024
54863c6
Refactored performance settings and its dependency injection
AlexDickerson Dec 28, 2024
e8fa2be
Replaced references to concrete SettingsManager with interface
AlexDickerson Dec 28, 2024
76cd4dc
Removed two unnecessary usings
AlexDickerson Dec 28, 2024
f0d8b64
Fixed DownloadClientFactory to compare file size correctly
AlexDickerson Dec 28, 2024
66545cd
One more cleanup pass
AlexDickerson Dec 28, 2024
5ff915c
Replace usage of ResumableDownloader with NonReusableDownloader for f…
AlexDickerson Dec 27, 2024
4120d41
Reverted unneeded change to AInstaller
AlexDickerson Dec 27, 2024
d6ec4b2
Added more explicit error logging
AlexDickerson Dec 27, 2024
6fc715a
Synced Namespaces
AlexDickerson Dec 27, 2024
c87b302
Adding UI for setting minimum file size at which to use resumable dow…
AlexDickerson Dec 28, 2024
19c7583
Reverting unintended changes
AlexDickerson Dec 28, 2024
2fcad64
Reverting unneeded changes
AlexDickerson Dec 28, 2024
2d77b12
Refactored performance settings and its dependency injection
AlexDickerson Dec 28, 2024
7c73b24
Replaced references to concrete SettingsManager with interface
AlexDickerson Dec 28, 2024
31626cf
Removed two unnecessary usings
AlexDickerson Dec 28, 2024
a3bbcbf
Fixed DownloadClientFactory to compare file size correctly
AlexDickerson Dec 28, 2024
192c34b
One more cleanup pass
AlexDickerson Dec 28, 2024
7dd4ac7
Merge branch 'downloadsRefactor' of https://github.com/AlexDickerson/…
AlexDickerson Dec 28, 2024
a3e9016
Refactored downloader to resume on network failures
AlexDickerson Dec 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions Wabbajack.App.Wpf/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Wabbajack.Downloaders;
using SteamKit2.GC.Dota.Internal;
using Wabbajack.Downloaders;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Paths;
using Wabbajack.RateLimiter;
Expand All @@ -14,41 +15,65 @@ public class Mo2ModlistInstallationSettings
public bool AutomaticallyOverrideExistingInstall { get; set; }
}

public class PerformanceSettings : ViewModel
public class PerformanceSettingsViewModel : ViewModel
{
private readonly Configuration.MainSettings _settings;
private readonly int _defaultMaximumMemoryPerDownloadThreadMb;
private readonly int _defaultMaximumMemoryPerDownloadThreadMB;
private readonly long _defaultMinimumFileSizeForResumableDownloadMB;

public PerformanceSettings(Configuration.MainSettings settings, IResource<DownloadDispatcher> downloadResources, SystemParametersConstructor systemParams)
public PerformanceSettingsViewModel(Configuration.MainSettings settings, IResource<DownloadDispatcher> downloadResources, SystemParametersConstructor systemParams)
{
var p = systemParams.Create();

_settings = settings;
// Split half of available memory among download threads
_defaultMaximumMemoryPerDownloadThreadMb = (int)(p.SystemMemorySize / downloadResources.MaxTasks / 1024 / 1024) / 2;
_maximumMemoryPerDownloadThreadMb = settings.PerformanceSettings.MaximumMemoryPerDownloadThreadMb;
_defaultMaximumMemoryPerDownloadThreadMB = (int)(p.SystemMemorySize / downloadResources.MaxTasks / 1024 / 1024) / 2;
_defaultMinimumFileSizeForResumableDownloadMB = long.MaxValue;
_maximumMemoryPerDownloadThreadMB = settings.MaximumMemoryPerDownloadThreadInMB;
_minimumFileSizeForResumableDownloadMB = settings.MinimumFileSizeForResumableDownloadMB;

if (MaximumMemoryPerDownloadThreadMb < 0)
{
ResetMaximumMemoryPerDownloadThreadMb();
}

if (settings.MinimumFileSizeForResumableDownloadMB < 0)
{
ResetMinimumFileSizeForResumableDownload();
}
}

private int _maximumMemoryPerDownloadThreadMb;
private int _maximumMemoryPerDownloadThreadMB;
private long _minimumFileSizeForResumableDownloadMB;

public int MaximumMemoryPerDownloadThreadMb
{
get => _maximumMemoryPerDownloadThreadMb;
get => _maximumMemoryPerDownloadThreadMB;
set
{
RaiseAndSetIfChanged(ref _maximumMemoryPerDownloadThreadMB, value);
_settings.MaximumMemoryPerDownloadThreadInMB = value;
}
}

public long MinimumFileSizeForResumableDownload
{
get => _minimumFileSizeForResumableDownloadMB;
set
{
RaiseAndSetIfChanged(ref _maximumMemoryPerDownloadThreadMb, value);
_settings.PerformanceSettings.MaximumMemoryPerDownloadThreadMb = value;
RaiseAndSetIfChanged(ref _minimumFileSizeForResumableDownloadMB, value);
_settings.MinimumFileSizeForResumableDownloadMB = value;
}
}

public void ResetMaximumMemoryPerDownloadThreadMb()
{
MaximumMemoryPerDownloadThreadMb = _defaultMaximumMemoryPerDownloadThreadMb;
MaximumMemoryPerDownloadThreadMb = _defaultMaximumMemoryPerDownloadThreadMB;
}

public void ResetMinimumFileSizeForResumableDownload()
{
MinimumFileSizeForResumableDownload = _defaultMinimumFileSizeForResumableDownloadMB;
}
}
}
4 changes: 2 additions & 2 deletions Wabbajack.App.Wpf/View Models/Compilers/CompilerVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CompilerVM : BackNavigatingVM, ICpuStatusVM
{
private const string LastSavedCompilerSettings = "last-saved-compiler-settings";
private readonly DTOSerializer _dtos;
private readonly SettingsManager _settingsManager;
private readonly ISettingsManager _settingsManager;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<CompilerVM> _logger;
private readonly ResourceMonitor _resourceMonitor;
Expand Down Expand Up @@ -106,7 +106,7 @@ public class CompilerVM : BackNavigatingVM, ICpuStatusVM

[Reactive] public ErrorResponse ErrorState { get; private set; }

public CompilerVM(ILogger<CompilerVM> logger, DTOSerializer dtos, SettingsManager settingsManager,
public CompilerVM(ILogger<CompilerVM> logger, DTOSerializer dtos, ISettingsManager settingsManager,
IServiceProvider serviceProvider, LogStream loggerProvider, ResourceMonitor resourceMonitor,
CompilerSettingsInferencer inferencer, Client wjClient, IEnumerable<INeedsLogin> logins, DownloadDispatcher downloadDispatcher) : base(logger)
{
Expand Down
8 changes: 3 additions & 5 deletions Wabbajack.App.Wpf/View Models/Gallery/ModListGalleryVM.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@


using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -77,13 +75,13 @@ public GameTypeEntry SelectedGameTypeEntry
private readonly ILogger<ModListGalleryVM> _logger;
private readonly GameLocator _locator;
private readonly ModListDownloadMaintainer _maintainer;
private readonly SettingsManager _settingsManager;
private readonly ISettingsManager _settingsManager;
private readonly CancellationToken _cancellationToken;

public ICommand ClearFiltersCommand { get; set; }

public ModListGalleryVM(ILogger<ModListGalleryVM> logger, Client wjClient, GameLocator locator,
SettingsManager settingsManager, ModListDownloadMaintainer maintainer, CancellationToken cancellationToken)
ISettingsManager settingsManager, ModListDownloadMaintainer maintainer, CancellationToken cancellationToken)
: base(logger)
{
_wjClient = wjClient;
Expand Down
6 changes: 2 additions & 4 deletions Wabbajack.App.Wpf/View Models/Installers/InstallerVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Shell;
using System.Windows.Threading;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAPICodePack.Dialogs;
using Wabbajack.Common;
Expand All @@ -34,7 +33,6 @@
using Wabbajack.Paths.IO;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.Util;
using System.Windows.Forms;
using Microsoft.Extensions.DependencyInjection;
using Wabbajack.CLI.Verbs;
using Wabbajack.VFS;
Expand Down Expand Up @@ -114,7 +112,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM

private readonly DTOSerializer _dtos;
private readonly ILogger<InstallerVM> _logger;
private readonly SettingsManager _settingsManager;
private readonly ISettingsManager _settingsManager;
private readonly IServiceProvider _serviceProvider;
private readonly SystemParametersConstructor _parametersConstructor;
private readonly IGameLocator _gameLocator;
Expand Down Expand Up @@ -156,7 +154,7 @@ public class InstallerVM : BackNavigatingVM, IBackNavigatingVM, ICpuStatusVM

public ReactiveCommand<Unit, Unit> VerifyCommand { get; }

public InstallerVM(ILogger<InstallerVM> logger, DTOSerializer dtos, SettingsManager settingsManager, IServiceProvider serviceProvider,
public InstallerVM(ILogger<InstallerVM> logger, DTOSerializer dtos, ISettingsManager settingsManager, IServiceProvider serviceProvider,
SystemParametersConstructor parametersConstructor, IGameLocator gameLocator, LogStream loggerProvider, ResourceMonitor resourceMonitor,
Wabbajack.Services.OSIntegrated.Configuration configuration, HttpClient client, DownloadDispatcher dispatcher, IEnumerable<INeedsLogin> logins,
CancellationToken cancellationToken) : base(logger)
Expand Down
8 changes: 4 additions & 4 deletions Wabbajack.App.Wpf/View Models/Settings/SettingsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace Wabbajack
public class SettingsVM : BackNavigatingVM
{
private readonly Configuration.MainSettings _settings;
private readonly SettingsManager _settingsManager;
private readonly ISettingsManager _settingsManager;

public LoginManagerVM Login { get; }
public PerformanceSettings Performance { get; }
public PerformanceSettingsViewModel Performance { get; }
public AuthorFilesVM AuthorFile { get; }

public ICommand OpenTerminalCommand { get; }
Expand All @@ -36,14 +36,14 @@ public SettingsVM(ILogger<SettingsVM> logger, IServiceProvider provider)
: base(logger)
{
_settings = provider.GetRequiredService<Configuration.MainSettings>();
_settingsManager = provider.GetRequiredService<SettingsManager>();
_settingsManager = provider.GetRequiredService<ISettingsManager>();

Login = new LoginManagerVM(provider.GetRequiredService<ILogger<LoginManagerVM>>(), this,
provider.GetRequiredService<IEnumerable<INeedsLogin>>());
AuthorFile = new AuthorFilesVM(provider.GetRequiredService<ILogger<AuthorFilesVM>>()!,
provider.GetRequiredService<WabbajackApiTokenProvider>()!, provider.GetRequiredService<Client>()!, this);
OpenTerminalCommand = ReactiveCommand.CreateFromTask(OpenTerminal);
Performance = new PerformanceSettings(
Performance = new PerformanceSettingsViewModel(
_settings,
provider.GetRequiredService<IResource<DownloadDispatcher>>(),
provider.GetRequiredService<SystemParametersConstructor>());
Expand Down
26 changes: 25 additions & 1 deletion Wabbajack.App.Wpf/Views/Settings/PerformanceSettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:xwpf="http://schemas.xceed.com/wpf/xaml/toolkit"
d:DesignHeight="450"
d:DesignWidth="800"
x:TypeArguments="local:PerformanceSettings"
x:TypeArguments="local:PerformanceSettingsViewModel"
mc:Ignorable="d">
<Border
x:Name="PerformanceView"
Expand Down Expand Up @@ -71,6 +71,30 @@
HorizontalAlignment="Left">
<TextBlock FontSize="14">Reset</TextBlock>
</Button>
<TextBlock
Grid.Row="6"
FontSize="14"
Foreground="{StaticResource ForegroundBrush}"
Text="Minimum File Size for Fast Download (MB)"
ToolTip="Defines the file size at which a slower but more robust download process will be used. If you have slow or unreliable internet this should be kept at zero." />
<xwpf:LongUpDown
x:Name="MinimumFileSizeForResumableDownloadIntegerUpDown"
Grid.Row="6"
Grid.Column="2"
Width="80"
HorizontalAlignment="Left"
Foreground="{StaticResource ForegroundBrush}"
Maximum="1000000000"
Minimum="0" />
<Button
x:Name="ResetMinimumFileSizeForResumableDownload"
Grid.Row="6"
Grid.Column="3"
Margin="20,0,0,0"
Padding="10,0"
HorizontalAlignment="Left">
<TextBlock FontSize="14">Reset</TextBlock>
</Button>
</Grid>
</Border>
</rxui:ReactiveUserControl>
15 changes: 14 additions & 1 deletion Wabbajack.App.Wpf/Views/Settings/PerformanceSettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Wabbajack
/// <summary>
/// Interaction logic for PerformanceSettingsView.xaml
/// </summary>
public partial class PerformanceSettingsView : ReactiveUserControl<PerformanceSettings>
public partial class PerformanceSettingsView : ReactiveUserControl<PerformanceSettingsViewModel>
{
public PerformanceSettingsView()
{
Expand All @@ -21,16 +21,29 @@ public PerformanceSettingsView()
x => x.MaximumMemoryPerDownloadThreadMb,
x => x.MaximumMemoryPerDownloadThreadIntegerUpDown.Value)
.DisposeWith(disposable);

this.BindStrict(
ViewModel,
x => x.MinimumFileSizeForResumableDownload,
x => x.MinimumFileSizeForResumableDownloadIntegerUpDown.Value)
.DisposeWith(disposable);

this.EditResourceSettings.Command = ReactiveCommand.Create(() =>
{
UIUtils.OpenFile(
KnownFolders.WabbajackAppLocal.Combine("saved_settings", "resource_settings.json"));
Environment.Exit(0);
});

ResetMaximumMemoryPerDownloadThread.Command = ReactiveCommand.Create(() =>
{
ViewModel.ResetMaximumMemoryPerDownloadThreadMb();
});

ResetMinimumFileSizeForResumableDownload.Command = ReactiveCommand.Create(() =>
{
ViewModel.ResetMinimumFileSizeForResumableDownload();
});
});
}
}
Expand Down
7 changes: 2 additions & 5 deletions Wabbajack.CLI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.CommandLine;
using System.CommandLine.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -11,14 +10,13 @@
using NLog.Targets;
using Octokit;
using Wabbajack.DTOs.Interventions;
using Wabbajack.Networking.Http;
using Wabbajack.Networking.Http.Interfaces;
using Wabbajack.Paths.IO;
using Wabbajack.Server.Lib;
using Wabbajack.Services.OSIntegrated;
using Wabbajack.VFS;
using Client = Wabbajack.Networking.GitHub.Client;
using Wabbajack.CLI.Builder;
using Wabbajack.Downloader.Services;

namespace Wabbajack.CLI;

Expand All @@ -31,8 +29,7 @@ private static async Task<int> Main(string[] args)
.ConfigureServices((host, services) =>
{
services.AddSingleton(new JsonSerializerOptions());
services.AddSingleton<HttpClient, HttpClient>();
services.AddSingleton<IHttpDownloader, SingleThreadedDownloader>();
services.AddDownloaderService();
services.AddSingleton<IConsole, SystemConsole>();
services.AddSingleton<CommandLineBuilder, CommandLineBuilder>();
services.AddSingleton<TemporaryFileManager>();
Expand Down
2 changes: 0 additions & 2 deletions Wabbajack.CLI/VerbRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public static void AddCLIVerbs(this IServiceCollection services) {
services.AddSingleton<MirrorFile>();
CommandLineBuilder.RegisterCommand<ModlistReport>(ModlistReport.Definition, c => ((ModlistReport)c).Run);
services.AddSingleton<ModlistReport>();
CommandLineBuilder.RegisterCommand<SetNexusApiKey>(SetNexusApiKey.Definition, c => ((SetNexusApiKey)c).Run);
services.AddSingleton<SetNexusApiKey>();
CommandLineBuilder.RegisterCommand<SteamDownloadFile>(SteamDownloadFile.Definition, c => ((SteamDownloadFile)c).Run);
services.AddSingleton<SteamDownloadFile>();
CommandLineBuilder.RegisterCommand<SteamDumpAppInfo>(SteamDumpAppInfo.Definition, c => ((SteamDumpAppInfo)c).Run);
Expand Down
40 changes: 0 additions & 40 deletions Wabbajack.CLI/Verbs/SetNexusApiKey.cs

This file was deleted.

Loading
Loading