diff --git a/Natsurainko.FluentLauncher/App.xaml.cs b/Natsurainko.FluentLauncher/App.xaml.cs
index 65bf02fa..3accdb8e 100644
--- a/Natsurainko.FluentLauncher/App.xaml.cs
+++ b/Natsurainko.FluentLauncher/App.xaml.cs
@@ -13,7 +13,6 @@
using System.Diagnostics;
using System.Net.Http.Headers;
using System.Text;
-using System.Threading;
namespace Natsurainko.FluentLauncher;
diff --git a/Natsurainko.FluentLauncher/Package.appxmanifest b/Natsurainko.FluentLauncher/Package.appxmanifest
index d37d43e1..f21ba529 100644
--- a/Natsurainko.FluentLauncher/Package.appxmanifest
+++ b/Natsurainko.FluentLauncher/Package.appxmanifest
@@ -11,7 +11,7 @@
+ Version="2.3.1.0" />
Natsurianko.FluentLauncher
diff --git a/Natsurainko.FluentLauncher/Services/Launch/LaunchService.cs b/Natsurainko.FluentLauncher/Services/Launch/LaunchService.cs
index 4ca6574a..dc0ab312 100644
--- a/Natsurainko.FluentLauncher/Services/Launch/LaunchService.cs
+++ b/Natsurainko.FluentLauncher/Services/Launch/LaunchService.cs
@@ -11,6 +11,7 @@
using Nrk.FluentCore.Experimental.Launch;
using Nrk.FluentCore.GameManagement;
using Nrk.FluentCore.GameManagement.Dependencies;
+using Nrk.FluentCore.GameManagement.Installer;
using Nrk.FluentCore.GameManagement.Instances;
using Nrk.FluentCore.Launch;
using Nrk.FluentCore.Utils;
@@ -154,11 +155,22 @@ async Task PreCheckLaunchNeeds(
if (_settingsService.EnableAutoJava)
{
var targetJavaVersion = instance.GetSuitableJavaVersion();
-
var javaInfos = _settingsService.Javas.Select(JavaUtils.GetJavaInfo).ToArray();
- var possiblyAvailableJavas = targetJavaVersion == null
+
+ JavaInfo[] possiblyAvailableJavas;
+ bool isForgeOrNeoForge = false;
+
+ if (instance is ModifiedMinecraftInstance modifiedMinecraftInstance)
+ {
+ var loaders = modifiedMinecraftInstance.ModLoaders.Select(x => x.Type);
+ isForgeOrNeoForge = loaders.Contains(ModLoaderType.Forge) || loaders.Contains(ModLoaderType.NeoForge);
+ }
+
+ possiblyAvailableJavas = targetJavaVersion == null
? javaInfos
- : javaInfos.Where(x => x.Version.Major.ToString().Equals(targetJavaVersion)).ToArray();
+ : isForgeOrNeoForge
+ ? javaInfos.Where(x => x.Version.Major.ToString().Equals(targetJavaVersion)).ToArray()
+ : javaInfos.Where(x => x.Version.Major >= int.Parse(targetJavaVersion)).ToArray();
if (possiblyAvailableJavas.Length == 0)
throw new Exception($"No suitable version of Java found to start this game, version {targetJavaVersion} is required");
diff --git a/Natsurainko.FluentLauncher/Services/Network/DownloadService.cs b/Natsurainko.FluentLauncher/Services/Network/DownloadService.cs
index 20d8fc35..d83b4d36 100644
--- a/Natsurainko.FluentLauncher/Services/Network/DownloadService.cs
+++ b/Natsurainko.FluentLauncher/Services/Network/DownloadService.cs
@@ -1,5 +1,4 @@
using Natsurainko.FluentLauncher.Models.UI;
-using Natsurainko.FluentLauncher.Services.Launch;
using Natsurainko.FluentLauncher.Services.Network.Data;
using Natsurainko.FluentLauncher.Services.Settings;
using Natsurainko.FluentLauncher.ViewModels.Common;
@@ -20,19 +19,26 @@ namespace Natsurainko.FluentLauncher.Services.Network;
internal partial class DownloadService
{
private readonly SettingsService _settingsService;
- private readonly GameService _gameService;
- private readonly MultipartDownloader _downloader = new(HttpUtils.HttpClient, 1024 * 1024, 8, 64);
+ private MultipartDownloader _downloader;
public IDownloader Downloader { get => _downloader; }
public ObservableCollection DownloadTasks { get; } = [];
- public DownloadService(SettingsService settingsService, GameService gameService)
+ public DownloadService(SettingsService settingsService)
{
_settingsService = settingsService;
- _gameService = gameService;
+ _downloader = new(HttpUtils.HttpClient, 1024 * 1024, 8, _settingsService.MaxDownloadThreads,
+ _settingsService.CurrentDownloadSource == "Bmclapi" ? DownloadMirrors.BmclApi : null);
- // TODO: 注册下载设置变化事件
+ _settingsService.MaxDownloadThreadsChanged += (_,_) => UpdateDownloader();
+ _settingsService.CurrentDownloadSourceChanged += (_, _) => UpdateDownloader();
+ }
+
+ void UpdateDownloader()
+ {
+ _downloader = new(HttpUtils.HttpClient, 1024 * 1024, 8, _settingsService.MaxDownloadThreads,
+ _settingsService.CurrentDownloadSource == "Bmclapi" ? DownloadMirrors.BmclApi : null);
}
public void DownloadResourceFile(GameResourceFile file, string filePath)
@@ -80,6 +86,7 @@ IInstanceInstaller GetInstanceInstaller(
ModLoaderType modLoaderType = instanceInstallConfig.PrimaryLoader.Type;
object selectedInstallData = instanceInstallConfig.PrimaryLoader.SelectedInstallData;
+ IDownloadMirror? downloadMirror = _settingsService.CurrentDownloadSource == "Bmclapi" ? DownloadMirrors.BmclApi : null;
installationStageViews = GetInstallationViewModel(modLoaderType, out var vanillaStagesViewModel, out var stagesViewModel);
@@ -87,7 +94,7 @@ IInstanceInstaller GetInstanceInstaller(
{
ModLoaderType.Forge => new ForgeInstanceInstaller()
{
- //DownloadMirror = DownloadMirrors.BmclApi,
+ DownloadMirror = downloadMirror,
McVersionManifestItem = versionManifestItem,
MinecraftFolder = minecraftFolder,
CheckAllDependencies = true,
@@ -100,7 +107,7 @@ IInstanceInstaller GetInstanceInstaller(
},
ModLoaderType.NeoForge => new ForgeInstanceInstaller()
{
- //DownloadMirror = DownloadMirrors.BmclApi,
+ DownloadMirror = downloadMirror,
McVersionManifestItem = versionManifestItem,
MinecraftFolder = minecraftFolder,
CheckAllDependencies = true,
@@ -113,7 +120,7 @@ IInstanceInstaller GetInstanceInstaller(
},
ModLoaderType.OptiFine => new OptiFineInstanceInstaller()
{
- DownloadMirror = DownloadMirrors.BmclApi,
+ DownloadMirror = downloadMirror,
McVersionManifestItem = versionManifestItem,
MinecraftFolder = minecraftFolder,
CheckAllDependencies = true,
@@ -125,7 +132,7 @@ IInstanceInstaller GetInstanceInstaller(
},
ModLoaderType.Fabric => new FabricInstanceInstaller()
{
- DownloadMirror = DownloadMirrors.BmclApi,
+ DownloadMirror = downloadMirror,
McVersionManifestItem = versionManifestItem,
MinecraftFolder = minecraftFolder,
CheckAllDependencies = true,
@@ -136,7 +143,7 @@ IInstanceInstaller GetInstanceInstaller(
},
ModLoaderType.Quilt => new QuiltInstanceInstaller()
{
- DownloadMirror = DownloadMirrors.BmclApi,
+ DownloadMirror = downloadMirror,
McVersionManifestItem = versionManifestItem,
MinecraftFolder = minecraftFolder,
CheckAllDependencies = true,
@@ -156,7 +163,7 @@ List GetInstallationViewModel(
out InstallationViewModel vanillaStagesViewModel,
out object stagesViewModel)
{
- List stageViewModels = new();
+ List stageViewModels = [];
vanillaStagesViewModel = new();
if (modLoaderType == ModLoaderType.Quilt)
diff --git a/Natsurainko.FluentLauncher/Services/Settings/SettingsService.cs b/Natsurainko.FluentLauncher/Services/Settings/SettingsService.cs
index 527b56bb..3417b328 100644
--- a/Natsurainko.FluentLauncher/Services/Settings/SettingsService.cs
+++ b/Natsurainko.FluentLauncher/Services/Settings/SettingsService.cs
@@ -2,30 +2,25 @@
using FluentLauncher.Infra.Settings.Converters;
using Natsurainko.FluentLauncher.Services.Storage;
using Natsurainko.FluentLauncher.Utils;
-using Nrk.FluentCore.Management;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;
-using System.Text.Json.Serialization;
using Windows.Storage;
namespace Natsurainko.FluentLauncher.Services.Settings;
public partial class SettingsService : SettingsContainer
{
- #region New IFluentCoreSettingsService Property
-
- public ObservableCollection MinecraftFolders { get; private set; } = new();
- public ObservableCollection Javas { get; private set; } = new();
+ public ObservableCollection MinecraftFolders { get; private set; } = [];
+ public ObservableCollection Javas { get; private set; } = [];
[SettingItem(Default = "", Converter = typeof(JsonStringConverter))]
public partial string ActiveMinecraftFolder { get; set; }
- //[SettingItem(typeof(GameInfo), "ActiveGameInfo", Converter = typeof(JsonStringConverter))]
- [SettingItem]
+ [SettingItem] //[SettingItem(typeof(GameInfo), "ActiveGameInfo", Converter = typeof(JsonStringConverter))]
public partial string? ActiveInstanceId { get; set; }
[SettingItem(Default = "", Converter = typeof(JsonStringConverter))]
@@ -34,8 +29,6 @@ public partial class SettingsService : SettingsContainer
[SettingItem(Default = 1024, Converter = typeof(JsonStringConverter))]
public partial int JavaMemory { get; set; }
- #endregion
-
[SettingItem(Default = true, Converter = typeof(JsonStringConverter))]
public partial bool EnableAutoMemory { get; set; }
@@ -159,7 +152,7 @@ public SettingsService(ISettingsStorage storage) : base(storage)
Array.ForEach(minecraftFolders, MinecraftFolders.Add);
MinecraftFolders.CollectionChanged += (sender, e) =>
{
- appsettings.Values["MinecraftFolders"] = JsonSerializer.Serialize(MinecraftFolders.ToArray(), FLSerializerContext.Default.StringArray);
+ appsettings.Values["MinecraftFolders"] = JsonSerializer.Serialize([.. MinecraftFolders], FLSerializerContext.Default.StringArray);
};
// Init Javas
@@ -174,7 +167,7 @@ public SettingsService(ISettingsStorage storage) : base(storage)
Array.ForEach(javaRuntimes, Javas.Add);
Javas.CollectionChanged += (sender, e) =>
{
- appsettings.Values["Javas"] = JsonSerializer.Serialize(Javas.ToArray(), FLSerializerContext.Default.StringArray);
+ appsettings.Values["Javas"] = JsonSerializer.Serialize([.. Javas], FLSerializerContext.Default.StringArray);
};
}
diff --git a/Natsurainko.FluentLauncher/Utils/Extensions/ProcessExtensions.cs b/Natsurainko.FluentLauncher/Utils/Extensions/ProcessExtensions.cs
index c05562ff..b2141a10 100644
--- a/Natsurainko.FluentLauncher/Utils/Extensions/ProcessExtensions.cs
+++ b/Natsurainko.FluentLauncher/Utils/Extensions/ProcessExtensions.cs
@@ -1,8 +1,6 @@
-using CommunityToolkit.Mvvm.DependencyInjection;
-using System;
+using System;
using System.Diagnostics;
using System.Management;
-using System.Runtime.CompilerServices;
namespace Natsurainko.FluentLauncher.Utils.Extensions;