Skip to content

Commit

Permalink
优化安装器的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Jan 4, 2025
1 parent 884f978 commit 764ed82
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 23 deletions.
19 changes: 15 additions & 4 deletions MinecraftLaunch/Components/Installer/CompositionInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public sealed class CompositionInstaller : InstallerBase {
/// <summary>
/// 自定义下载进度计算表达式
/// </summary>
public override Func<double, double> CalculateExpression { get; set; } = x => x.ToPercentage(0.0d, 0.6d);
public override Func<double, double> CalculateExpression { get; set; }
= x => x.ToPercentage(0.0d, 0.6d);

public override GameEntry InheritedFrom { get; }
public event EventHandler SubInstallerCompleted;

public override GameEntry InheritedFrom { get; set; }

public CompositionInstaller(InstallerBase installerBase, string customId, OptiFineInstallEntity entity = default) {
if (installerBase is NeoForgeInstaller or QuiltInstaller) {
Expand All @@ -42,13 +45,15 @@ public CompositionInstaller(InstallerBase mainInstaller, InstallerBase subInstal

_entity = entity;
_customId = customId;
_subInstaller = subInstaller;
_mainInstaller = mainInstaller;
}

public override async Task<bool> InstallAsync(CancellationToken cancellation = default) {
_mainInstaller.ProgressChanged += OnProgressChanged;
await _mainInstaller.InstallAsync(cancellation);

SubInstallerCompleted?.Invoke(this, default);
if (_entity is null && _subInstaller is null) {
CalculateExpression = null;
ReportProgress(1.0d, "Installation is complete", TaskStatus.RanToCompletion);
Expand All @@ -59,11 +64,17 @@ public override async Task<bool> InstallAsync(CancellationToken cancellation = d
ReportProgress(0.6d, "Start installing the sub loader", TaskStatus.WaitingToRun);
//sub1
if (_subInstaller is not null) {
//handle gameEntry
if (_mainInstaller is VanlliaInstaller) {
_subInstaller.InheritedFrom = _mainInstaller.InheritedFrom;
}

CalculateExpression = x => x.ToPercentage(0.6d, 0.8d);
_mainInstaller.ProgressChanged += OnProgressChanged;
await _mainInstaller.InstallAsync(cancellation);
_subInstaller.ProgressChanged += OnProgressChanged;
await _subInstaller.InstallAsync(cancellation);
}

//sub1 end
if (_entity is null) {
CalculateExpression = null;
ReportProgress(1.0d, "Installation is complete", TaskStatus.RanToCompletion);
Expand Down
23 changes: 18 additions & 5 deletions MinecraftLaunch/Components/Installer/FabricInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@

namespace MinecraftLaunch.Components.Installer;

public sealed class FabricInstaller(GameEntry inheritedFrom, FabricBuildEntry entry, string customId = default, DownloaderConfiguration configuration = default) : InstallerBase {
private readonly string _customId = customId;
private readonly FabricBuildEntry _fabricBuildEntry = entry;
private readonly DownloaderConfiguration _configuration = configuration;
public sealed class FabricInstaller : InstallerBase {
private readonly string _customId;
private readonly FabricBuildEntry _fabricBuildEntry;
private readonly DownloaderConfiguration _configuration;

public override GameEntry InheritedFrom => inheritedFrom;
public override GameEntry InheritedFrom { get; set; }

public FabricInstaller(FabricBuildEntry entry, string customId = default, DownloaderConfiguration configuration = default) {
_customId = customId;
_fabricBuildEntry = entry;
_configuration = configuration;
}

public FabricInstaller(GameEntry inheritedFrom, FabricBuildEntry entry, string customId = default, DownloaderConfiguration configuration = default) {
_customId = customId;
_fabricBuildEntry = entry;
_configuration = configuration;
InheritedFrom = inheritedFrom;
}

public override async Task<bool> InstallAsync(CancellationToken cancellation = default) {
/*
Expand Down
25 changes: 20 additions & 5 deletions MinecraftLaunch/Components/Installer/ForgeInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@

namespace MinecraftLaunch.Components.Installer;

public sealed class ForgeInstaller(GameEntry inheritedFrom, ForgeInstallEntry installEntry, string javaPath, string customId = default, DownloaderConfiguration configuration = default) : InstallerBase {
private readonly string _customId = customId;
private readonly string _javaPath = javaPath;
private readonly ForgeInstallEntry _installEntry = installEntry;
public sealed class ForgeInstaller : InstallerBase {
private readonly string _customId;
private readonly string _javaPath;
private readonly ForgeInstallEntry _installEntry;
private readonly DownloaderConfiguration _configuration = default;

public override GameEntry InheritedFrom => inheritedFrom;
public ForgeInstaller(ForgeInstallEntry installEntry, string javaPath, string customId = default, DownloaderConfiguration configuration = default) {
_customId = customId;
_javaPath = javaPath;
_configuration = configuration;
_installEntry = installEntry;
}

public ForgeInstaller(GameEntry inheritedFrom, ForgeInstallEntry installEntry, string javaPath, string customId = default, DownloaderConfiguration configuration = default) {
_customId = customId;
_javaPath = javaPath;
_configuration = configuration;
_installEntry = installEntry;
InheritedFrom = inheritedFrom;
}

public override GameEntry InheritedFrom { get; set; }

public override async Task<bool> InstallAsync(CancellationToken cancellation = default) {
List<HighVersionForgeProcessorEntry> highVersionForgeProcessors = default;
Expand Down
2 changes: 1 addition & 1 deletion MinecraftLaunch/Components/Installer/InstallerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class InstallerBase : IInstaller {

public event EventHandler<ProgressChangedEventArgs> ProgressChanged;

public abstract GameEntry InheritedFrom { get; }
public abstract GameEntry InheritedFrom { get; set; }
public virtual Func<double, double> CalculateExpression { get; set; }

public abstract Task<bool> InstallAsync(CancellationToken cancellation = default);
Expand Down
2 changes: 1 addition & 1 deletion MinecraftLaunch/Components/Installer/NeoForgeInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MinecraftLaunch.Components.Installer;

public sealed class NeoForgeInstaller : InstallerBase {
public override GameEntry InheritedFrom => throw new NotImplementedException();
public override GameEntry InheritedFrom { get; set; }

public override Task<bool> InstallAsync(CancellationToken cancellation = default) {
throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion MinecraftLaunch/Components/Installer/OptifineInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class OptifineInstaller(
private readonly OptiFineInstallEntity _installEntry = installEntry;
private readonly DownloaderConfiguration _configuration = configuration;

public override GameEntry InheritedFrom => inheritedFrom;
public override GameEntry InheritedFrom { get; set; } = inheritedFrom;

public override async Task<bool> InstallAsync(CancellationToken cancellation = default) {
/*
Expand Down
23 changes: 18 additions & 5 deletions MinecraftLaunch/Components/Installer/QuiltInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@

namespace MinecraftLaunch.Components.Installer;

public sealed class QuiltInstaller(GameEntry inheritedFrom, QuiltBuildEntry entry, string customId = default, DownloaderConfiguration configuration = default) : InstallerBase {
private readonly string _customId = customId;
private readonly QuiltBuildEntry _quiltBuildEntry = entry;
private readonly DownloaderConfiguration _configuration = configuration;
public sealed class QuiltInstaller : InstallerBase {
private readonly string _customId;
private readonly QuiltBuildEntry _quiltBuildEntry;
private readonly DownloaderConfiguration _configuration;

public override GameEntry InheritedFrom => inheritedFrom;
public override GameEntry InheritedFrom { get; set; }

public QuiltInstaller(QuiltBuildEntry entry, string customId = default, DownloaderConfiguration configuration = default) {
_configuration = configuration;
_quiltBuildEntry = entry;
_customId = customId;
}

public QuiltInstaller(GameEntry inheritedFrom, QuiltBuildEntry entry, string customId = default, DownloaderConfiguration configuration = default) {
_configuration = configuration;
_quiltBuildEntry = entry;
_customId = customId;
InheritedFrom = inheritedFrom;
}

public override async Task<bool> InstallAsync(CancellationToken cancellation = default) {
/*
Expand Down
3 changes: 2 additions & 1 deletion MinecraftLaunch/Components/Installer/VanlliaInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class VanlliaInstaller(IGameResolver gameFoloder, string gameId, D
private readonly IGameResolver _gameResolver = gameFoloder;
private readonly DownloaderConfiguration _configuration = configuration;

public override GameEntry InheritedFrom => throw new NotSupportedException();
public override GameEntry InheritedFrom { get; set; }

public override async Task<bool> InstallAsync(CancellationToken cancellation = default) {
/*
Expand Down Expand Up @@ -62,6 +62,7 @@ await resourceChecker.MissingResources.DownloadResourceEntrysAsync(_configuratio
}, cancellation);
}

InheritedFrom = _gameResolver.GetGameEntity(_gameId);
ReportProgress(1.0d, "Installation is complete", TaskStatus.Canceled);
ReportCompleted();
return true;
Expand Down

0 comments on commit 764ed82

Please sign in to comment.