Skip to content

Commit

Permalink
修复了镜像源、分片下载设置项无效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
natsurainko committed Feb 7, 2025
1 parent 3131b35 commit 8d98da2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions Natsurainko.FluentLauncher/Services/Network/DownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using static Nrk.FluentCore.GameManagement.Installer.FabricInstanceInstaller;
using static Nrk.FluentCore.GameManagement.Installer.ForgeInstanceInstaller;
using static Nrk.FluentCore.GameManagement.Installer.OptiFineInstanceInstaller;
Expand All @@ -30,11 +31,10 @@ internal partial class DownloadService
public DownloadService(SettingsService settingsService)
{
_settingsService = settingsService;
_downloader = new(HttpUtils.HttpClient, 1024 * 1024, 8, _settingsService.MaxDownloadThreads,
_settingsService.CurrentDownloadSource == "Bmclapi" ? DownloadMirrors.BmclApi : null);
SetDownloader();

_settingsService.MaxDownloadThreadsChanged += (_,_) => UpdateDownloader();
_settingsService.CurrentDownloadSourceChanged += (_, _) => UpdateDownloader();
_settingsService.MaxDownloadThreadsChanged += (_,_) => SetDownloader();
_settingsService.CurrentDownloadSourceChanged += (_, _) => SetDownloader();
}

public void DownloadResourceFile(GameResourceFile file, string filePath)
Expand Down Expand Up @@ -75,10 +75,15 @@ private void InsertTask(TaskViewModel taskViewModel)
});
}

private void UpdateDownloader()
[MemberNotNull(nameof(_downloader))]
private void SetDownloader()
{
_downloader = new(HttpUtils.HttpClient, 1024 * 1024, 8, _settingsService.MaxDownloadThreads,
_settingsService.CurrentDownloadSource == "Bmclapi" ? DownloadMirrors.BmclApi : null);
_downloader = new(
httpClient: HttpUtils.HttpClient,
workersPerDownloadTask: 8,
concurrentDownloadTasks: _settingsService.MaxDownloadThreads,
enableMultiPartDownload: _settingsService.EnableFragmentDownload,
mirror: _settingsService.CurrentDownloadSource == "Bmclapi" ? DownloadMirrors.BmclApi : null);
}

IInstanceInstaller GetInstanceInstaller(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public partial class SettingsService : SettingsContainer
[SettingItem(Default = true, Converter = typeof(JsonStringConverter<bool>))]
public partial bool EnableFragmentDownload { get; set; }

[SettingItem(Default = 128, Converter = typeof(JsonStringConverter<int>))]
[SettingItem(Default = 64, Converter = typeof(JsonStringConverter<int>))]
public partial int MaxDownloadThreads { get; set; }

#endregion
Expand Down

0 comments on commit 8d98da2

Please sign in to comment.