From 1081ca7a13910368c00c9e2510b15a9e1d7d2e2b Mon Sep 17 00:00:00 2001 From: AMagicPear Date: Thu, 8 May 2025 12:45:14 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat&style:=20=E4=BC=98=E5=8C=96=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E7=89=88=E6=9C=AC=E5=AD=98=E5=82=A8=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=B9=B6=E5=AE=9E=E7=8E=B0=E5=8F=AF=E6=AF=94=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E6=94=B9=E6=AD=A3=E4=BA=86=E4=BA=BF?= =?UTF-8?q?=E4=BA=9B=E6=8B=BC=E9=94=99=E7=9A=84=E5=8D=95=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PCL2.Neo.Tests/Models/Minecraft/JavaTest.cs | 6 +++ .../Models/Minecraft/Game/Data/GameEntity.cs | 31 +++++++------- .../Models/Minecraft/Game/Data/VersionInfo.cs | 41 +++++++++++++++---- .../Minecraft/Java/JavaSelectorExtension.cs | 15 +++++++ 4 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 PCL2.Neo/Models/Minecraft/Java/JavaSelectorExtension.cs diff --git a/PCL2.Neo.Tests/Models/Minecraft/JavaTest.cs b/PCL2.Neo.Tests/Models/Minecraft/JavaTest.cs index 2a211b32..9444f728 100644 --- a/PCL2.Neo.Tests/Models/Minecraft/JavaTest.cs +++ b/PCL2.Neo.Tests/Models/Minecraft/JavaTest.cs @@ -1,3 +1,4 @@ +using PCL2.Neo.Models.Minecraft.Game.Data; using PCL2.Neo.Models.Minecraft.Java; using PCL2.Neo.Utils; @@ -11,5 +12,10 @@ public async Task Test() JavaManager javaInstance = new(); await javaInstance.JavaListInit(); } + + [Test] + public void VersionCompare(){ + GameVersionNum v1; + } } } \ No newline at end of file diff --git a/PCL2.Neo/Models/Minecraft/Game/Data/GameEntity.cs b/PCL2.Neo/Models/Minecraft/Game/Data/GameEntity.cs index 67a5e281..f547276f 100644 --- a/PCL2.Neo/Models/Minecraft/Game/Data/GameEntity.cs +++ b/PCL2.Neo/Models/Minecraft/Game/Data/GameEntity.cs @@ -5,16 +5,20 @@ namespace PCL2.Neo.Models.Minecraft.Game.Data; public record GameEntityInfo { -#nullable disable /// /// The Game Version information. /// - public GameVersion GameVersion { get; set; } + public GameVersionNum? GameVersion { get; init; } + + /// + /// String typed game version. eg: 25w19a、1.21.5-rc2、25w14craftmine. + /// + public required string GameVersionString { get; init; } /// /// Game Name that is used to display in the UI. /// - public string Name { get; set; } + public required string Name { get; set; } /// /// Game Description that is used to display in the UI. @@ -24,12 +28,12 @@ public record GameEntityInfo /// /// Game Folder Path. /// - public string GamePath { get; set; } + public required string GamePath { get; set; } /// /// Game Root Path. /// - public string RootPath { get; set; } + public required string RootPath { get; set; } /// /// Game Icon that is used to display in the UI. @@ -39,21 +43,21 @@ public record GameEntityInfo /// /// The origin Game Json Content. Type is . /// - public string JsonOrigContent { get; set; } + public required string JsonOrigContent { get; set; } /// /// The Parsed Game Json Content. Type is . /// - public MetadataFile JsonContent { get; set; } + public required MetadataFile JsonContent { get; set; } /// /// Demonstrate the Game Version Type. - /// Content is . + /// Content is . /// - public VersionType Type { get; set; } + public VersionCardType Type { get; set; } /// - /// If is .Modable, Loader will have value that is used to display in the UI. + /// If is .Moddable, Loader will have value that is used to display in the UI. /// public ModLoader Loader { get; set; } @@ -64,9 +68,9 @@ public record GameEntityInfo /// /// Demonstrate is the version has been loader (runed). /// - public bool IsLoadded { get; set; } = false; + public bool IsLoaded { get; set; } = false; - private bool? _isIndie { get; set; } + private bool? _isIndie; public bool IsIndie { @@ -87,8 +91,7 @@ public bool IsIndie /// /// THe Game Jar File Path. /// - public string JarPath { get; set; } -#nullable enable + public required string JarPath { get; set; } } public class GameEntity diff --git a/PCL2.Neo/Models/Minecraft/Game/Data/VersionInfo.cs b/PCL2.Neo/Models/Minecraft/Game/Data/VersionInfo.cs index 92252ee4..542bb152 100644 --- a/PCL2.Neo/Models/Minecraft/Game/Data/VersionInfo.cs +++ b/PCL2.Neo/Models/Minecraft/Game/Data/VersionInfo.cs @@ -23,21 +23,34 @@ public enum Icons : byte NeoForge = 12 } - public enum VersionType : byte + public enum VersionCardType : byte { Auto = 0, Hide = 1, - Modable = 2, + Moddable = 2, Normal = 3, Unusual = 4, - FoolDay = 5 + FoolsDay = 5, + Error = 6, } - public record GameVersion + public record GameVersionNum(byte Sub, byte? Fix = null) : IComparable { - public byte Major { get; set; } = 1; - public byte Sub { get; set; } - public byte Fix { get; set; } + private readonly (byte Major, byte Sub, int Fix) _version = (1, Sub, Fix ?? 0); + + public byte Major => _version.Major; + public byte Sub => _version.Sub; + public byte? Fix => _version.Fix > 0 ? (byte)_version.Fix : null; + + public int CompareTo(GameVersionNum? other) + { + return other == null ? 1 : (Major, Sub, Fix ?? 0).CompareTo((other.Major, other.Sub, other.Fix ?? 0)); + } + + public override string ToString() + { + return Fix.HasValue ? $"{Major}.{Sub}.{Fix}" : $"{Major}.{Sub}"; + } } public enum ModLoader : byte @@ -50,4 +63,18 @@ public enum ModLoader : byte Rift = 5, Quilt = 6 } + + public enum McVersionState + { + Error, + Vanilla, + Snapshot, + FoolsDay, + OptiFine, + Legacy, + Forge, + NeoForge, + LiteLoader, + Fabric, + } } diff --git a/PCL2.Neo/Models/Minecraft/Java/JavaSelectorExtension.cs b/PCL2.Neo/Models/Minecraft/Java/JavaSelectorExtension.cs new file mode 100644 index 00000000..63afb2d3 --- /dev/null +++ b/PCL2.Neo/Models/Minecraft/Java/JavaSelectorExtension.cs @@ -0,0 +1,15 @@ +using CommunityToolkit.Mvvm.DependencyInjection; +using PCL2.Neo.Models.Minecraft.Game.Data; +using System.Collections.Generic; +using System.Collections.Immutable; + +namespace PCL2.Neo.Models.Minecraft.Java; + +public static class JavaSelectorExtension +{ + private static List? JavaRuntimes { get { return Ioc.Default.GetService()?.JavaList; } } + + // public static ImmutableArray SelectSuitableRuntimes(this GameEntityInfo gameEntityInfo) + // { + // } +} From 695dfaa4b7ddf65d0394d120fa5443bffbf050a1 Mon Sep 17 00:00:00 2001 From: AMagicPear Date: Thu, 8 May 2025 14:39:03 +0800 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E8=A7=86=E5=9B=BE=E5=8F=8A=E7=9B=B8=E5=85=B3=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PCL2.Neo/App.axaml.cs | 8 ++++---- PCL2.Neo/ViewModels/MainWindowViewModel.cs | 6 ++++++ .../ViewModels/Setup/SetupLaunchViewModel.cs | 13 ++++++++++++ PCL2.Neo/ViewModels/SetupViewModel.cs | 9 +++++++++ PCL2.Neo/Views/MainWindow.axaml | 5 +++-- PCL2.Neo/Views/Setup/SetupLaunchView.axaml | 20 +++++++++++++++++++ PCL2.Neo/Views/Setup/SetupLaunchView.axaml.cs | 14 +++++++++++++ PCL2.Neo/Views/Setup/SetupOtherView.axaml | 9 +++++++++ PCL2.Neo/Views/Setup/SetupOtherView.axaml.cs | 14 +++++++++++++ PCL2.Neo/Views/Setup/SetupStyleView.axaml | 9 +++++++++ PCL2.Neo/Views/Setup/SetupStyleView.axaml.cs | 14 +++++++++++++ PCL2.Neo/Views/SetupView.axaml | 14 +++++++++++++ PCL2.Neo/Views/SetupView.axaml.cs | 14 +++++++++++++ 13 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs create mode 100644 PCL2.Neo/ViewModels/SetupViewModel.cs create mode 100644 PCL2.Neo/Views/Setup/SetupLaunchView.axaml create mode 100644 PCL2.Neo/Views/Setup/SetupLaunchView.axaml.cs create mode 100644 PCL2.Neo/Views/Setup/SetupOtherView.axaml create mode 100644 PCL2.Neo/Views/Setup/SetupOtherView.axaml.cs create mode 100644 PCL2.Neo/Views/Setup/SetupStyleView.axaml create mode 100644 PCL2.Neo/Views/Setup/SetupStyleView.axaml.cs create mode 100644 PCL2.Neo/Views/SetupView.axaml create mode 100644 PCL2.Neo/Views/SetupView.axaml.cs diff --git a/PCL2.Neo/App.axaml.cs b/PCL2.Neo/App.axaml.cs index 3bc02d84..ae6fb935 100644 --- a/PCL2.Neo/App.axaml.cs +++ b/PCL2.Neo/App.axaml.cs @@ -1,19 +1,16 @@ using System.Linq; using Avalonia; -using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Data.Core.Plugins; using Avalonia.Markup.Xaml; using CommunityToolkit.Mvvm.DependencyInjection; using Microsoft.Extensions.DependencyInjection; using PCL2.Neo.Services; -using Avalonia.Platform.Storage; -using PCL2.Neo.Helpers; using PCL2.Neo.Models.Minecraft.Java; -using PCL2.Neo.Utils; using PCL2.Neo.ViewModels; using PCL2.Neo.ViewModels.Download; using PCL2.Neo.ViewModels.Home; +using PCL2.Neo.ViewModels.Setup; using PCL2.Neo.Views; using System; using System.Threading.Tasks; @@ -40,6 +37,9 @@ public override void Initialize() .AddTransient() .AddTransient() + .AddTransient() + .AddTransient() + .AddSingleton(s => new NavigationService(s)) .AddSingleton() .AddSingleton() diff --git a/PCL2.Neo/ViewModels/MainWindowViewModel.cs b/PCL2.Neo/ViewModels/MainWindowViewModel.cs index f252a6d8..a57f3f2f 100644 --- a/PCL2.Neo/ViewModels/MainWindowViewModel.cs +++ b/PCL2.Neo/ViewModels/MainWindowViewModel.cs @@ -70,6 +70,12 @@ public void NavigateToDownload() this.NavigationService.Goto(); } + [RelayCommand] + public void NavigateToSetup() + { + this.NavigationService.Goto(); + } + public void Close() { _window?.Close(); diff --git a/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs b/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs new file mode 100644 index 00000000..3ab8537e --- /dev/null +++ b/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs @@ -0,0 +1,13 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using PCL2.Neo.Models.Minecraft.Java; +using System.Collections.Generic; + +namespace PCL2.Neo.ViewModels.Setup; + +[SubViewModelOf(typeof(SetupViewModel))] +public partial class SetupLaunchViewModel : ViewModelBase +{ + [ObservableProperty] private List _javaList = []; + + +} \ No newline at end of file diff --git a/PCL2.Neo/ViewModels/SetupViewModel.cs b/PCL2.Neo/ViewModels/SetupViewModel.cs new file mode 100644 index 00000000..11e2cf20 --- /dev/null +++ b/PCL2.Neo/ViewModels/SetupViewModel.cs @@ -0,0 +1,9 @@ +using PCL2.Neo.ViewModels.Setup; + +namespace PCL2.Neo.ViewModels; + +[DefaultSubViewModel(typeof(SetupLaunchViewModel))] +public class SetupViewModel : ViewModelBase +{ + +} \ No newline at end of file diff --git a/PCL2.Neo/Views/MainWindow.axaml b/PCL2.Neo/Views/MainWindow.axaml index 7bfaa599..a8582b44 100644 --- a/PCL2.Neo/Views/MainWindow.axaml +++ b/PCL2.Neo/Views/MainWindow.axaml @@ -182,7 +182,7 @@ Name="BtnTitleSelect2" Padding="2,0" Tag="2" - Text="{DynamicResource LangTitleLink}" /> + Text="{DynamicResource LangTitleLink}"/> + Text="{DynamicResource LangTitleSetup}" + Command="{Binding NavigateToSetup}"/> + + + + + + + + + + + diff --git a/PCL2.Neo/Views/Setup/SetupLaunchView.axaml.cs b/PCL2.Neo/Views/Setup/SetupLaunchView.axaml.cs new file mode 100644 index 00000000..b348614b --- /dev/null +++ b/PCL2.Neo/Views/Setup/SetupLaunchView.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace PCL2.Neo.Views.Setup +{ + public partial class SetupLaunchView : UserControl + { + public SetupLaunchView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/Setup/SetupOtherView.axaml b/PCL2.Neo/Views/Setup/SetupOtherView.axaml new file mode 100644 index 00000000..d3aae823 --- /dev/null +++ b/PCL2.Neo/Views/Setup/SetupOtherView.axaml @@ -0,0 +1,9 @@ + + Welcome to Avalonia! + + diff --git a/PCL2.Neo/Views/Setup/SetupOtherView.axaml.cs b/PCL2.Neo/Views/Setup/SetupOtherView.axaml.cs new file mode 100644 index 00000000..d618e7ce --- /dev/null +++ b/PCL2.Neo/Views/Setup/SetupOtherView.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace PCL2.Neo.Views.Setup +{ + public partial class SetupOtherView : UserControl + { + public SetupOtherView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/Setup/SetupStyleView.axaml b/PCL2.Neo/Views/Setup/SetupStyleView.axaml new file mode 100644 index 00000000..df12302b --- /dev/null +++ b/PCL2.Neo/Views/Setup/SetupStyleView.axaml @@ -0,0 +1,9 @@ + + Welcome to Avalonia! + + diff --git a/PCL2.Neo/Views/Setup/SetupStyleView.axaml.cs b/PCL2.Neo/Views/Setup/SetupStyleView.axaml.cs new file mode 100644 index 00000000..1cef62d4 --- /dev/null +++ b/PCL2.Neo/Views/Setup/SetupStyleView.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace PCL2.Neo.Views.Setup +{ + public partial class SetupStyleView : UserControl + { + public SetupStyleView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/PCL2.Neo/Views/SetupView.axaml b/PCL2.Neo/Views/SetupView.axaml new file mode 100644 index 00000000..016b168b --- /dev/null +++ b/PCL2.Neo/Views/SetupView.axaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/PCL2.Neo/Views/SetupView.axaml.cs b/PCL2.Neo/Views/SetupView.axaml.cs new file mode 100644 index 00000000..71f26a30 --- /dev/null +++ b/PCL2.Neo/Views/SetupView.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace PCL2.Neo.Views +{ + public partial class SetupView : UserControl + { + public SetupView() + { + InitializeComponent(); + } + } +} \ No newline at end of file From 37f385674728424b82f7f94e9fcf3a6c928c15c0 Mon Sep 17 00:00:00 2001 From: AMagicPear Date: Thu, 8 May 2025 15:20:27 +0800 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=86Java?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84UI=EF=BC=8C=E4=BD=86=E6=98=AF?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E4=BA=86=E8=AF=A1=E5=BC=82=E7=8E=B0=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PCL2.Neo/Models/Minecraft/Java/JavaManager.cs | 2 +- .../ViewModels/Setup/SetupLaunchViewModel.cs | 18 +++++++++++++++++- PCL2.Neo/Views/Setup/SetupLaunchView.axaml | 14 +++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs b/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs index ffe51d6e..9e55b1f3 100644 --- a/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs +++ b/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs @@ -103,7 +103,7 @@ public async Task Refresh() else Console.WriteLine($"[Java] 用户导入的 Java 已不可用,已自动剔除:{oldRuntime.DirectoryPath}"); JavaList = newEntities; - Console.WriteLine("[Java] 刷新 Java 完成"); + Console.WriteLine($"[Java] 刷新 Java 完成,现在共有 {JavaList.Count} 个Java"); if (JavaList.Count == 0) { // TODO)) 提示用户未找到已安装的 java,是否自动下载合适版本,然后再下载 diff --git a/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs b/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs index 3ab8537e..28fb552d 100644 --- a/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs +++ b/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs @@ -1,13 +1,29 @@ using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; using PCL2.Neo.Models.Minecraft.Java; +using System; using System.Collections.Generic; +using System.Threading.Tasks; namespace PCL2.Neo.ViewModels.Setup; [SubViewModelOf(typeof(SetupViewModel))] public partial class SetupLaunchViewModel : ViewModelBase { + private readonly IJavaManager _javaManager; [ObservableProperty] private List _javaList = []; + public SetupLaunchViewModel(IJavaManager javaManager) + { + _javaManager = javaManager; + JavaList = _javaManager.JavaList; + } -} \ No newline at end of file + [RelayCommand] + private async Task RefreshJava() + { + await _javaManager.Refresh(); + JavaList = _javaManager.JavaList; + Console.WriteLine($"UI显示列表有{JavaList.Count}个Java"); + } +} diff --git a/PCL2.Neo/Views/Setup/SetupLaunchView.axaml b/PCL2.Neo/Views/Setup/SetupLaunchView.axaml index 7564f6fb..c4b3122c 100644 --- a/PCL2.Neo/Views/Setup/SetupLaunchView.axaml +++ b/PCL2.Neo/Views/Setup/SetupLaunchView.axaml @@ -14,7 +14,19 @@ - + + + + + + + + + + + + + From 767cde3d2dd55aca5794b8445ecb71590e088c75 Mon Sep 17 00:00:00 2001 From: AMagicPear Date: Thu, 8 May 2025 16:23:11 +0800 Subject: [PATCH 4/8] =?UTF-8?q?feat&fix:=20=E6=9B=B4=E6=96=B0Java=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84UI=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=9B=B4?= =?UTF-8?q?=E5=85=B7=E6=8F=8F=E8=BF=B0=E6=80=A7=E7=9A=84=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=86=E8=AF=A1=E5=BC=82=E7=8E=B0?= =?UTF-8?q?=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/Setup/SetupLaunchViewModel.cs | 28 ++++++++++++++----- PCL2.Neo/Views/Setup/SetupLaunchView.axaml | 8 +++--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs b/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs index 28fb552d..5a3f4235 100644 --- a/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs +++ b/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs @@ -1,29 +1,43 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using PCL2.Neo.Models.Minecraft.Java; -using System; -using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Threading.Tasks; namespace PCL2.Neo.ViewModels.Setup; +public record JavaUiInfo(JavaRuntime Runtime) +{ + public string Identifier => + $"{(Runtime.IsJre ? "JRE" : "JDK")} {Runtime.SlugVersion} ({Runtime.Version}) {Runtime.Architecture}"; + + public string Path => Runtime.DirectoryPath; +} + [SubViewModelOf(typeof(SetupViewModel))] public partial class SetupLaunchViewModel : ViewModelBase { private readonly IJavaManager _javaManager; - [ObservableProperty] private List _javaList = []; + [ObservableProperty] private ObservableCollection _javaInfoList = []; + + private void DoUiRefresh() + { + if (JavaInfoList.Count != 0) JavaInfoList.Clear(); + foreach (JavaRuntime runtime in _javaManager.JavaList) + JavaInfoList.Add(new JavaUiInfo(runtime)); + } public SetupLaunchViewModel(IJavaManager javaManager) { _javaManager = javaManager; - JavaList = _javaManager.JavaList; + DoUiRefresh(); } [RelayCommand] private async Task RefreshJava() { + JavaInfoList.Clear(); await _javaManager.Refresh(); - JavaList = _javaManager.JavaList; - Console.WriteLine($"UI显示列表有{JavaList.Count}个Java"); + DoUiRefresh(); } -} +} \ No newline at end of file diff --git a/PCL2.Neo/Views/Setup/SetupLaunchView.axaml b/PCL2.Neo/Views/Setup/SetupLaunchView.axaml index c4b3122c..6d5f0a45 100644 --- a/PCL2.Neo/Views/Setup/SetupLaunchView.axaml +++ b/PCL2.Neo/Views/Setup/SetupLaunchView.axaml @@ -14,14 +14,14 @@ - - + + - - + + From 9af5e0d6723a2b96e9988d1bf1d4f7728014d85f Mon Sep 17 00:00:00 2001 From: AMagicPear Date: Thu, 8 May 2025 17:10:24 +0800 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20=E6=8A=8AJava=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=92=8C=E6=89=8B=E5=8A=A8=E6=B7=BB=E5=8A=A0=E7=9A=84ViewModel?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=81=9A=E5=A5=BD=E5=95=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Minecraft/Java/IJavaManager.cs | 2 +- PCL2.Neo/Models/Minecraft/Java/JavaManager.cs | 10 ++++++---- .../ViewModels/Setup/SetupLaunchViewModel.cs | 20 +++++++++++++++++-- PCL2.Neo/Views/Setup/SetupLaunchView.axaml | 1 + 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/PCL2.Neo/Models/Minecraft/Java/IJavaManager.cs b/PCL2.Neo/Models/Minecraft/Java/IJavaManager.cs index bfe39045..de5147ec 100644 --- a/PCL2.Neo/Models/Minecraft/Java/IJavaManager.cs +++ b/PCL2.Neo/Models/Minecraft/Java/IJavaManager.cs @@ -7,6 +7,6 @@ public interface IJavaManager { List JavaList { get; } Task JavaListInit(); - Task ManualAdd(string javaDir); + Task<(JavaRuntime?, bool UpdateCurrent)> ManualAdd(string javaDir); Task Refresh(); } diff --git a/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs b/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs index 9e55b1f3..fb98eb13 100644 --- a/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs +++ b/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs @@ -66,14 +66,14 @@ public async Task JavaListInit() } } - public async Task ManualAdd(string javaDir) + public async Task<(JavaRuntime?, bool UpdateCurrent)> ManualAdd(string javaDir) { - if (!IsInitialized) return; + if (!IsInitialized) return (null, false); if (JavaList.FirstOrDefault(runtime => runtime.DirectoryPath == javaDir) is { } existingRuntime) { Console.WriteLine("选择的 Java 在列表中已存在,将其标记为手动导入。"); existingRuntime.IsUserImport = true; - return; + return (existingRuntime, true); } var entity = await JavaRuntime.CreateJavaEntityAsync(javaDir, true); @@ -81,8 +81,10 @@ public async Task ManualAdd(string javaDir) { JavaList.Add(entity); Console.WriteLine("已成功添加!"); + return (entity, false); } - else Console.WriteLine("添加的 Java 文件无法运行!"); + Console.WriteLine("添加的 Java 文件无法运行!"); + return (null, true); } public async Task Refresh() diff --git a/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs b/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs index 5a3f4235..89e8c82a 100644 --- a/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs +++ b/PCL2.Neo/ViewModels/Setup/SetupLaunchViewModel.cs @@ -1,7 +1,9 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using PCL2.Neo.Models.Minecraft.Java; +using PCL2.Neo.Services; using System.Collections.ObjectModel; +using System.IO; using System.Threading.Tasks; namespace PCL2.Neo.ViewModels.Setup; @@ -9,7 +11,7 @@ namespace PCL2.Neo.ViewModels.Setup; public record JavaUiInfo(JavaRuntime Runtime) { public string Identifier => - $"{(Runtime.IsJre ? "JRE" : "JDK")} {Runtime.SlugVersion} ({Runtime.Version}) {Runtime.Architecture}"; + $"{(Runtime.IsJre ? "JRE" : "JDK")} {Runtime.SlugVersion} ({Runtime.Version}) {Runtime.Architecture} {Runtime.Implementor}"; public string Path => Runtime.DirectoryPath; } @@ -18,6 +20,7 @@ public record JavaUiInfo(JavaRuntime Runtime) public partial class SetupLaunchViewModel : ViewModelBase { private readonly IJavaManager _javaManager; + private readonly StorageService _storageService; [ObservableProperty] private ObservableCollection _javaInfoList = []; private void DoUiRefresh() @@ -27,9 +30,10 @@ private void DoUiRefresh() JavaInfoList.Add(new JavaUiInfo(runtime)); } - public SetupLaunchViewModel(IJavaManager javaManager) + public SetupLaunchViewModel(IJavaManager javaManager, StorageService storageService) { _javaManager = javaManager; + _storageService = storageService; DoUiRefresh(); } @@ -40,4 +44,16 @@ private async Task RefreshJava() await _javaManager.Refresh(); DoUiRefresh(); } + + [RelayCommand] + private async Task ManualAdd() + { + string? javaPath = await _storageService.SelectFile("选择要添加的Java"); + if (javaPath == null) return; + var dirPath = Path.GetDirectoryName(javaPath); + if (dirPath == null) return; + (JavaRuntime? resultRuntime, bool updateCurrent) = await _javaManager.ManualAdd(dirPath); + if (resultRuntime == null || updateCurrent) return; + JavaInfoList.Add(new JavaUiInfo(resultRuntime)); + } } \ No newline at end of file diff --git a/PCL2.Neo/Views/Setup/SetupLaunchView.axaml b/PCL2.Neo/Views/Setup/SetupLaunchView.axaml index 6d5f0a45..e8dbe8db 100644 --- a/PCL2.Neo/Views/Setup/SetupLaunchView.axaml +++ b/PCL2.Neo/Views/Setup/SetupLaunchView.axaml @@ -15,6 +15,7 @@ + From 830ea6940239a8973d568755da89a1f57338e996 Mon Sep 17 00:00:00 2001 From: AMagicPear Date: Thu, 8 May 2025 22:38:54 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PCL2.Neo/Models/Minecraft/Java/JavaManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs b/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs index fb98eb13..cae8f679 100644 --- a/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs +++ b/PCL2.Neo/Models/Minecraft/Java/JavaManager.cs @@ -84,7 +84,7 @@ public async Task JavaListInit() return (entity, false); } Console.WriteLine("添加的 Java 文件无法运行!"); - return (null, true); + return (null, false); } public async Task Refresh() From 7c8d5c5a2cd47406d81a77f7548c65a7293458c4 Mon Sep 17 00:00:00 2001 From: AMagicPear Date: Sat, 10 May 2025 23:53:21 +0800 Subject: [PATCH 7/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=86=E7=A6=BB?= =?UTF-8?q?Core=E9=A1=B9=E7=9B=AE=E5=90=8E=E5=B8=A6=E6=9D=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Minecraft/Java/JavaSelectorExtension.cs | 15 --------------- PCL.Neo/App.axaml.cs | 6 +++--- PCL.Neo/PCL.Neo.csproj | 7 ++++--- PCL.Neo/ViewModels/Setup/SetupLaunchViewModel.cs | 2 +- 4 files changed, 8 insertions(+), 22 deletions(-) delete mode 100644 PCL.Neo.Core/Models/Minecraft/Java/JavaSelectorExtension.cs diff --git a/PCL.Neo.Core/Models/Minecraft/Java/JavaSelectorExtension.cs b/PCL.Neo.Core/Models/Minecraft/Java/JavaSelectorExtension.cs deleted file mode 100644 index 8c34337e..00000000 --- a/PCL.Neo.Core/Models/Minecraft/Java/JavaSelectorExtension.cs +++ /dev/null @@ -1,15 +0,0 @@ -using CommunityToolkit.Mvvm.DependencyInjection; -using PCL.Neo.Models.Minecraft.Game.Data; -using System.Collections.Generic; -using System.Collections.Immutable; - -namespace PCL.Neo.Models.Minecraft.Java; - -public static class JavaSelectorExtension -{ - private static List? JavaRuntimes { get { return Ioc.Default.GetService()?.JavaList; } } - - // public static ImmutableArray SelectSuitableRuntimes(this GameEntityInfo gameEntityInfo) - // { - // } -} diff --git a/PCL.Neo/App.axaml.cs b/PCL.Neo/App.axaml.cs index ee5267e4..a164d431 100644 --- a/PCL.Neo/App.axaml.cs +++ b/PCL.Neo/App.axaml.cs @@ -6,9 +6,7 @@ using CommunityToolkit.Mvvm.DependencyInjection; using Microsoft.Extensions.DependencyInjection; using PCL.Neo.Services; -using Avalonia.Platform.Storage; -using PCL.Neo.Helpers; -using PCL.Neo.Utils; +using PCL.Neo.Core.Models.Minecraft.Java; using PCL.Neo.ViewModels; using PCL.Neo.ViewModels.Download; using PCL.Neo.ViewModels.Home; @@ -44,6 +42,7 @@ public override void Initialize() .AddSingleton(s => new NavigationService(s)) .AddSingleton() + .AddSingleton() .BuildServiceProvider(); public override void OnFrameworkInitializationCompleted() @@ -51,6 +50,7 @@ public override void OnFrameworkInitializationCompleted() Ioc.Default.ConfigureServices(ConfigureServices()); var vm = Ioc.Default.GetRequiredService(); + Task.Run(Ioc.Default.GetRequiredService().JavaListInit); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { // Avoid duplicate validations from both Avalonia and the CommunityToolkit. diff --git a/PCL.Neo/PCL.Neo.csproj b/PCL.Neo/PCL.Neo.csproj index 962f4588..306c1cfa 100644 --- a/PCL.Neo/PCL.Neo.csproj +++ b/PCL.Neo/PCL.Neo.csproj @@ -68,10 +68,11 @@ - - - + + + + diff --git a/PCL.Neo/ViewModels/Setup/SetupLaunchViewModel.cs b/PCL.Neo/ViewModels/Setup/SetupLaunchViewModel.cs index c680ff33..cbb2eb07 100644 --- a/PCL.Neo/ViewModels/Setup/SetupLaunchViewModel.cs +++ b/PCL.Neo/ViewModels/Setup/SetupLaunchViewModel.cs @@ -1,6 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using PCL.Neo.Models.Minecraft.Java; +using PCL.Neo.Core.Models.Minecraft.Java; using PCL.Neo.Services; using System.Collections.ObjectModel; using System.IO; From 533b6b4b52bb95fa279b2ba3d8576bf04e4fd08a Mon Sep 17 00:00:00 2001 From: AMagicPear Date: Sun, 11 May 2025 00:14:36 +0800 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=E4=BE=9D=E8=B5=96=E5=8C=85=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PCL.Neo.Core/PCL.Neo.Core.csproj | 2 +- PCL.Neo/PCL.Neo.csproj | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/PCL.Neo.Core/PCL.Neo.Core.csproj b/PCL.Neo.Core/PCL.Neo.Core.csproj index a99d4376..2e2b8240 100644 --- a/PCL.Neo.Core/PCL.Neo.Core.csproj +++ b/PCL.Neo.Core/PCL.Neo.Core.csproj @@ -7,7 +7,7 @@ - + diff --git a/PCL.Neo/PCL.Neo.csproj b/PCL.Neo/PCL.Neo.csproj index 306c1cfa..1c5bf909 100644 --- a/PCL.Neo/PCL.Neo.csproj +++ b/PCL.Neo/PCL.Neo.csproj @@ -38,7 +38,6 @@ -