Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 17 additions & 14 deletions PCL.Neo.Core/Models/Minecraft/Game/Data/GameEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@

public record GameEntityInfo
{
#nullable disable
/// <summary>
/// The Game Version information.
/// </summary>
public GameVersion GameVersion { get; set; }
public GameVersionNum? GameVersion { get; init; }

/// <summary>
/// String typed game version. eg: 25w19a、1.21.5-rc2、25w14craftmine.
/// </summary>
public required string GameVersionString { get; init; }

/// <summary>
/// Game Name that is used to display in the UI.
/// </summary>
public string Name { get; set; }
public required string Name { get; set; }

/// <summary>
/// Game Description that is used to display in the UI.
/// </summary>
public string Description { get; set; }

Check warning on line 25 in PCL.Neo.Core/Models/Minecraft/Game/Data/GameEntity.cs

View workflow job for this annotation

GitHub Actions / build-AppImage

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 25 in PCL.Neo.Core/Models/Minecraft/Game/Data/GameEntity.cs

View workflow job for this annotation

GitHub Actions / build-MacOsApp

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 25 in PCL.Neo.Core/Models/Minecraft/Game/Data/GameEntity.cs

View workflow job for this annotation

GitHub Actions / build-WinExe

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

/// <summary>
/// Game Folder Path.
/// </summary>
public string GamePath { get; set; }
public required string GamePath { get; set; }

/// <summary>
/// Game Root Path.
/// </summary>
public string RootPath { get; set; }
public required string RootPath { get; set; }

/// <summary>
/// Game Icon that is used to display in the UI.
Expand All @@ -38,21 +42,21 @@
/// <summary>
/// The origin Game Json Content. Type is <see langword="string"/>.
/// </summary>
public string JsonOrigContent { get; set; }
public required string JsonOrigContent { get; set; }

/// <summary>
/// The Parsed Game Json Content. Type is <see cref="MetadataFile"/>.
/// </summary>
public MetadataFile JsonContent { get; set; }
public required MetadataFile JsonContent { get; set; }

/// <summary>
/// Demonstrate the Game Version Type.
/// Content is <see cref="VersionType"/>.
/// Content is <see cref="VersionCardType"/>.
/// </summary>
public VersionType Type { get; set; }
public VersionCardType Type { get; set; }

/// <summary>
/// If <see cref="Type"/> is <see cref="VersionType"/>.Modable, Loader will have value that is used to display in the UI.
/// If <see cref="Type"/> is <see cref="VersionCardType"/>.Moddable, Loader will have value that is used to display in the UI.
/// </summary>
public ModLoader Loader { get; set; }

Expand All @@ -63,9 +67,9 @@
/// <summary>
/// Demonstrate is the version has been loader (runed).
/// </summary>
public bool IsLoadded { get; set; } = false;
public bool IsLoaded { get; set; } = false;

private bool? _isIndie { get; set; }
private bool? _isIndie;

public bool IsIndie
{
Expand All @@ -86,8 +90,7 @@
/// <summary>
/// THe Game Jar File Path.
/// </summary>
public string JarPath { get; set; }
#nullable enable
public required string JarPath { get; set; }
}

public class GameEntity
Expand Down
41 changes: 34 additions & 7 deletions PCL.Neo.Core/Models/Minecraft/Game/Data/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,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<GameVersionNum>
{
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
Expand All @@ -44,4 +57,18 @@ public enum ModLoader : byte
Rift = 5,
Quilt = 6
}

public enum McVersionState
{
Error,
Vanilla,
Snapshot,
FoolsDay,
OptiFine,
Legacy,
Forge,
NeoForge,
LiteLoader,
Fabric,
}
}
2 changes: 1 addition & 1 deletion PCL.Neo.Core/Models/Minecraft/Java/IJavaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public interface IJavaManager
{
List<JavaRuntime> JavaList { get; }
Task JavaListInit();
Task ManualAdd(string javaDir);
Task<(JavaRuntime?, bool UpdateCurrent)> ManualAdd(string javaDir);
Task Refresh();
}
12 changes: 7 additions & 5 deletions PCL.Neo.Core/Models/Minecraft/Java/JavaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
IsInitialized = true;
TestOutput();
}
catch (Exception e)

Check warning on line 51 in PCL.Neo.Core/Models/Minecraft/Java/JavaManager.cs

View workflow job for this annotation

GitHub Actions / build-AppImage

The variable 'e' is declared but never used

Check warning on line 51 in PCL.Neo.Core/Models/Minecraft/Java/JavaManager.cs

View workflow job for this annotation

GitHub Actions / build-MacOsApp

The variable 'e' is declared but never used

Check warning on line 51 in PCL.Neo.Core/Models/Minecraft/Java/JavaManager.cs

View workflow job for this annotation

GitHub Actions / build-WinExe

The variable 'e' is declared but never used
{
Console.WriteLine("初始化 Java 失败");
IsInitialized = false;
Expand All @@ -56,23 +56,25 @@
}
}

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);
if (entity is { Compability: not JavaCompability.Error })
{
JavaList.Add(entity);
Console.WriteLine("已成功添加!");
return (entity, false);
}
else Console.WriteLine("添加的 Java 文件无法运行!");
Console.WriteLine("添加的 Java 文件无法运行!");
return (null, false);
}

public async Task Refresh()
Expand All @@ -93,7 +95,7 @@
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,是否自动下载合适版本,然后再下载
Expand Down
2 changes: 1 addition & 1 deletion PCL.Neo.Core/PCL.Neo.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SevenZip" Version="19.0.0" />
<PackageReference Include="LZMA-SDK" Version="22.1.1" />
</ItemGroup>

</Project>
11 changes: 7 additions & 4 deletions PCL.Neo/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
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 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;
using PCL.Neo.Views;
using System;
using System.Threading.Tasks;
using PCL.Neo.ViewModels.Setup;

namespace PCL.Neo
{
Expand All @@ -39,15 +37,20 @@ public override void Initialize()
.AddTransient<DownloadGameViewModel>()
.AddTransient<DownloadModViewModel>()

.AddTransient<SetupViewModel>()
.AddTransient<SetupLaunchViewModel>()

.AddSingleton<NavigationService>(s => new NavigationService(s))
.AddSingleton<StorageService>()
.AddSingleton<IJavaManager,JavaManager>()
.BuildServiceProvider();

public override void OnFrameworkInitializationCompleted()
{
Ioc.Default.ConfigureServices(ConfigureServices());

var vm = Ioc.Default.GetRequiredService<MainWindowViewModel>();
Task.Run(Ioc.Default.GetRequiredService<IJavaManager>().JavaListInit);
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
Expand Down
8 changes: 4 additions & 4 deletions PCL.Neo/PCL.Neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<PackageReference Include="DotNet.Bundle" Version="0.9.13" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
<PackageReference Include="LZMA-SDK" Version="22.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -68,10 +67,11 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Models\Minecraft\Game\Data\" />
<Folder Include="Models\Minecraft\Java\" />
<Folder Include="Models\Minecraft\Mod\" />
<Folder Include="Views\MainPage\" />
<Folder Include="Views\SubPage\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PCL.Neo.Core\PCL.Neo.Core.csproj" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions PCL.Neo/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{
throw new System.NotImplementedException();
}
public MainWindowViewModel(Window window)

Check warning on line 34 in PCL.Neo/ViewModels/MainWindowViewModel.cs

View workflow job for this annotation

GitHub Actions / build-AppImage

Non-nullable property 'NavigationService' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 34 in PCL.Neo/ViewModels/MainWindowViewModel.cs

View workflow job for this annotation

GitHub Actions / build-MacOsApp

Non-nullable property 'NavigationService' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 34 in PCL.Neo/ViewModels/MainWindowViewModel.cs

View workflow job for this annotation

GitHub Actions / build-WinExe

Non-nullable property 'NavigationService' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
{
this._window = window;
}
Expand Down Expand Up @@ -70,6 +70,12 @@
this.NavigationService.Goto<DownloadViewModel>();
}

[RelayCommand]
public void NavigateToSetup()
{
this.NavigationService.Goto<SetupViewModel>();
}

public void Close()
{
_window?.Close();
Expand Down
59 changes: 59 additions & 0 deletions PCL.Neo/ViewModels/Setup/SetupLaunchViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using PCL.Neo.Core.Models.Minecraft.Java;
using PCL.Neo.Services;
using System.Collections.ObjectModel;
using System.IO;
using System.Threading.Tasks;

namespace PCL.Neo.ViewModels.Setup;

public record JavaUiInfo(JavaRuntime Runtime)
{
public string Identifier =>
$"{(Runtime.IsJre ? "JRE" : "JDK")} {Runtime.SlugVersion} ({Runtime.Version}) {Runtime.Architecture} {Runtime.Implementor}";

public string Path => Runtime.DirectoryPath;
}

[SubViewModelOf(typeof(SetupViewModel))]
public partial class SetupLaunchViewModel : ViewModelBase
{
private readonly IJavaManager _javaManager;
private readonly StorageService _storageService;
[ObservableProperty] private ObservableCollection<JavaUiInfo> _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, StorageService storageService)
{
_javaManager = javaManager;
_storageService = storageService;
DoUiRefresh();
}

[RelayCommand]
private async Task RefreshJava()
{
JavaInfoList.Clear();
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));
}
}
9 changes: 9 additions & 0 deletions PCL.Neo/ViewModels/SetupViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using PCL.Neo.ViewModels.Setup;

namespace PCL.Neo.ViewModels;

[DefaultSubViewModel(typeof(SetupLaunchViewModel))]
public class SetupViewModel : ViewModelBase
{

}
5 changes: 3 additions & 2 deletions PCL.Neo/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
Name="BtnTitleSelect2"
Padding="2,0"
Tag="2"
Text="{DynamicResource LangTitleLink}" />
Text="{DynamicResource LangTitleLink}"/>
<pc:MyRadioButton
IsChecked="{Binding IsNavBtn4Checked}"
Logo="{DynamicResource BtnTitleSelect3}"
Expand All @@ -191,7 +191,8 @@
Name="BtnTitleSelect3"
Padding="2,0"
Tag="3"
Text="{DynamicResource LangTitleSetup}" />
Text="{DynamicResource LangTitleSetup}"
Command="{Binding NavigateToSetup}"/>
<pc:MyRadioButton
IsChecked="{Binding IsNavBtn5Checked}"
Logo="{StaticResource BtnTitleSelect4}"
Expand Down
Loading
Loading