From 99b7d94d855c619ea092cebe36f302d4a79483e2 Mon Sep 17 00:00:00 2001 From: natsurainko Date: Mon, 29 Jul 2024 16:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E5=90=8E=E7=BB=86=E8=8A=82=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Natsurainko.FluentCore | 2 +- .../Experimental/Saves/SaveInfoParser.cs | 10 +----- .../Experimental/Servers/ServerInfo.cs | 11 +++++++ .../Natsurainko.FluentLauncher.csproj | 2 +- .../Cores/Manage/DefaultViewModel.cs | 33 ++++++++++++++++++- .../ViewModels/Cores/Manage/ModViewModel.cs | 21 +++++------- .../Views/Cores/Manage/DefaultPage.xaml | 17 +++++++--- .../Views/Cores/Manage/SavePage.xaml | 7 +++- .../Converters/SaveInfoConverter.cs | 2 ++ 9 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 Natsurainko.FluentLauncher/Experimental/Servers/ServerInfo.cs diff --git a/Natsurainko.FluentCore b/Natsurainko.FluentCore index 2c8e9999..9a92b2df 160000 --- a/Natsurainko.FluentCore +++ b/Natsurainko.FluentCore @@ -1 +1 @@ -Subproject commit 2c8e99991168f7130c669e35896d5cc060407628 +Subproject commit 9a92b2df76d2f11d0849e1dc9c106529b2c0cd5d diff --git a/Natsurainko.FluentLauncher/Experimental/Saves/SaveInfoParser.cs b/Natsurainko.FluentLauncher/Experimental/Saves/SaveInfoParser.cs index 43cb452d..542b266c 100644 --- a/Natsurainko.FluentLauncher/Experimental/Saves/SaveInfoParser.cs +++ b/Natsurainko.FluentLauncher/Experimental/Saves/SaveInfoParser.cs @@ -1,7 +1,6 @@ using NbtToolkit.Binary; using System; using System.IO; -using System.IO.Compression; using System.Threading.Tasks; namespace Natsurainko.FluentLauncher.Experimental.Saves; @@ -21,15 +20,8 @@ await Task.Run(() => var time = DateTime.Now; using var fileStream = new FileStream(Path.Combine(saveFolder, "level.dat"), FileMode.Open, FileAccess.Read); - using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress); - using var memoryStream = new MemoryStream(); - gzipStream.CopyTo(memoryStream); - byte[] bytes = memoryStream.ToArray(); + using var _nbtReader = new NbtReader(fileStream, NbtCompression.GZip, true); - // Create a stream from the decompressed bytes - using var _stream = new MemoryStream(bytes); - - using var _nbtReader = new NbtReader(_stream, NbtCompression.None, true); var rootTag = _nbtReader.ReadRootTag(); var dataTagCompound = rootTag["Data"].AsTagCompound(); diff --git a/Natsurainko.FluentLauncher/Experimental/Servers/ServerInfo.cs b/Natsurainko.FluentLauncher/Experimental/Servers/ServerInfo.cs new file mode 100644 index 00000000..e73411e8 --- /dev/null +++ b/Natsurainko.FluentLauncher/Experimental/Servers/ServerInfo.cs @@ -0,0 +1,11 @@ +#nullable disable +namespace Natsurainko.FluentLauncher.Experimental.Servers; + +internal record ServerInfo +{ + public string Name { get; set; } + + public string Address { get; set; } + + public string Icon { get; set; } +} diff --git a/Natsurainko.FluentLauncher/Natsurainko.FluentLauncher.csproj b/Natsurainko.FluentLauncher/Natsurainko.FluentLauncher.csproj index 66c959d5..43f8bc19 100644 --- a/Natsurainko.FluentLauncher/Natsurainko.FluentLauncher.csproj +++ b/Natsurainko.FluentLauncher/Natsurainko.FluentLauncher.csproj @@ -51,7 +51,7 @@ - + diff --git a/Natsurainko.FluentLauncher/ViewModels/Cores/Manage/DefaultViewModel.cs b/Natsurainko.FluentLauncher/ViewModels/Cores/Manage/DefaultViewModel.cs index 6fabdca6..95e7322b 100644 --- a/Natsurainko.FluentLauncher/ViewModels/Cores/Manage/DefaultViewModel.cs +++ b/Natsurainko.FluentLauncher/ViewModels/Cores/Manage/DefaultViewModel.cs @@ -29,13 +29,44 @@ public DefaultViewModel(GameService gameService, INavigationService navigationSe _navigationService = navigationService; } + [ObservableProperty] + [NotifyPropertyChangedFor(nameof(FormatSize))] + private GameStorageInfo gameStorageInfo; + + public string FormatSize + { + get + { + if (GameStorageInfo == null) + return string.Empty; + + double d = GameStorageInfo.TotalSize; + int i = 0; + + while ((d > 1024) && (i < 5)) + { + d /= 1024; + i++; + } + + var unit = new string[] { "B", "KB", "MB", "GB", "TB" }; + return string.Format("{0} {1}", Math.Round(d, 2), unit[i]); + } + } + void INavigationAware.OnNavigatedTo(object parameter) { GameInfo = parameter as GameInfo; GameConfig = GameInfo.GetConfig(); + Task.Run(() => + { + var gameStorageInfo = GameInfo.GetStorageInfo(); + App.DispatcherQueue.TryEnqueue(() => GameStorageInfo = gameStorageInfo); + }); + GameConfig.PropertyChanged += GameConfig_PropertyChanged; - } + } private void GameConfig_PropertyChanged(object sender, PropertyChangedEventArgs e) { diff --git a/Natsurainko.FluentLauncher/ViewModels/Cores/Manage/ModViewModel.cs b/Natsurainko.FluentLauncher/ViewModels/Cores/Manage/ModViewModel.cs index 0bc1feb6..43a87dd3 100644 --- a/Natsurainko.FluentLauncher/ViewModels/Cores/Manage/ModViewModel.cs +++ b/Natsurainko.FluentLauncher/ViewModels/Cores/Manage/ModViewModel.cs @@ -5,9 +5,8 @@ using Nrk.FluentCore.Management; using Nrk.FluentCore.Management.Mods; using System; -using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; -using System.Linq; using System.Threading.Tasks; using Windows.System; @@ -18,7 +17,7 @@ public partial class ModViewModel : ObservableObject, INavigationAware { private readonly INavigationService _navigationService; - public DefaultModsManager ModsManager { get; private set; } + public ModManager ModsManager { get; private set; } public string ModsFolder { get; private set; } @@ -26,8 +25,7 @@ public partial class ModViewModel : ObservableObject, INavigationAware public bool NotSupportMod => !GameInfo.IsSupportMod(); - [ObservableProperty] - public IReadOnlyList mods; + public ObservableCollection Mods { get; private set; } = []; public ModViewModel(INavigationService navigationService) { @@ -42,7 +40,7 @@ void INavigationAware.OnNavigatedTo(object parameter) if (!Directory.Exists(ModsFolder)) Directory.CreateDirectory(ModsFolder); - ModsManager = new DefaultModsManager(ModsFolder); + ModsManager = new ModManager(ModsFolder); LoadModList(); } @@ -57,12 +55,11 @@ public void DeleteMod(ModInfo modInfo) LoadModList(); } - private void LoadModList() + private async void LoadModList() { - Task.Run(() => - { - var modInfos = ModsManager.EnumerateMods().ToList(); - App.DispatcherQueue.TryEnqueue(() => Mods = modInfos); - }); + Mods.Clear(); + + await foreach (var saveInfo in ModsManager.EnumerateModsAsync()) + App.DispatcherQueue.TryEnqueue(() => Mods.Add(saveInfo)); } } diff --git a/Natsurainko.FluentLauncher/Views/Cores/Manage/DefaultPage.xaml b/Natsurainko.FluentLauncher/Views/Cores/Manage/DefaultPage.xaml index 78214a14..013af07f 100644 --- a/Natsurainko.FluentLauncher/Views/Cores/Manage/DefaultPage.xaml +++ b/Natsurainko.FluentLauncher/Views/Cores/Manage/DefaultPage.xaml @@ -15,10 +15,6 @@ MaxWidth="1000" HorizontalAlignment="Stretch" Spacing="{StaticResource SettingsCardSpacing}"> - - - - + + + + + + + + + + + + + diff --git a/Natsurainko.FluentLauncher/Views/Cores/Manage/SavePage.xaml b/Natsurainko.FluentLauncher/Views/Cores/Manage/SavePage.xaml index 5ab8cc7d..507fcb59 100644 --- a/Natsurainko.FluentLauncher/Views/Cores/Manage/SavePage.xaml +++ b/Natsurainko.FluentLauncher/Views/Cores/Manage/SavePage.xaml @@ -69,17 +69,22 @@ - + () diff --git a/Natsurainko.FluentLauncher/XamlHelpers/Converters/SaveInfoConverter.cs b/Natsurainko.FluentLauncher/XamlHelpers/Converters/SaveInfoConverter.cs index 77778516..59b07991 100644 --- a/Natsurainko.FluentLauncher/XamlHelpers/Converters/SaveInfoConverter.cs +++ b/Natsurainko.FluentLauncher/XamlHelpers/Converters/SaveInfoConverter.cs @@ -21,6 +21,8 @@ public object Convert(object value, Type targetType, object parameter, string la tags.Add(ResourceUtils.GetValue("Converters", "_SaveCommands")); tags.Add(ResourceUtils.GetValue("Converters", "_SaveVersion").Replace("${version}", saveInfo.Version)); + + tags.Add($"Seed: {saveInfo.Seed}"); return string.Join(", ", tags); }