Skip to content

Commit

Permalink
最后细节添加
Browse files Browse the repository at this point in the history
  • Loading branch information
natsurainko committed Jul 29, 2024
1 parent a8a9568 commit 99b7d94
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 29 deletions.
10 changes: 1 addition & 9 deletions Natsurainko.FluentLauncher/Experimental/Saves/SaveInfoParser.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions Natsurainko.FluentLauncher/Experimental/Servers/ServerInfo.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="NbtToolkit" Version="0.1.1-beta" />
<PackageReference Include="NbtToolkit" Version="0.1.2-beta" />
<PackageReference Include="PInvoke.User32" Version="0.7.124" />
<PackageReference Include="ReverseMarkdown" Version="3.25.0" />
<PackageReference Include="WindowsAPICodePack.Shell.CommonFileDialogs" Version="1.1.5" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
21 changes: 9 additions & 12 deletions Natsurainko.FluentLauncher/ViewModels/Cores/Manage/ModViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,16 +17,15 @@ public partial class ModViewModel : ObservableObject, INavigationAware
{
private readonly INavigationService _navigationService;

public DefaultModsManager ModsManager { get; private set; }
public ModManager ModsManager { get; private set; }

Check failure on line 20 in Natsurainko.FluentLauncher/ViewModels/Cores/Manage/ModViewModel.cs

View workflow job for this annotation

GitHub Actions / Build / Build (x64)

The type or namespace name 'ModManager' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 20 in Natsurainko.FluentLauncher/ViewModels/Cores/Manage/ModViewModel.cs

View workflow job for this annotation

GitHub Actions / Build / Build (arm64)

The type or namespace name 'ModManager' could not be found (are you missing a using directive or an assembly reference?)

public string ModsFolder { get; private set; }

public GameInfo GameInfo { get; private set; }

public bool NotSupportMod => !GameInfo.IsSupportMod();

[ObservableProperty]
public IReadOnlyList<ModInfo> mods;
public ObservableCollection<ModInfo> Mods { get; private set; } = [];

public ModViewModel(INavigationService navigationService)
{
Expand All @@ -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();
}
Expand All @@ -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));
}
}
17 changes: 13 additions & 4 deletions Natsurainko.FluentLauncher/Views/Cores/Manage/DefaultPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
MaxWidth="1000"
HorizontalAlignment="Stretch"
Spacing="{StaticResource SettingsCardSpacing}">
<StackPanel.ChildrenTransitions>
<EntranceThemeTransition FromVerticalOffset="50" />
<RepositionThemeTransition IsStaggeringEnabled="False" />
</StackPanel.ChildrenTransitions>

<TextBlock
x:Uid="Cores_Manage_DefaultPage_T1"
Expand Down Expand Up @@ -139,6 +135,19 @@
Header="Save Management"
HeaderIcon="{xh:FontIcon Glyph=&#xE81E;}"
IsClickEnabled="True" />

<TextBlock Style="{ThemeResource SettingsSectionHeaderTextBlockStyle}" Text="Storage stats" />

<controls:SettingsCard Header="Storage space usage" HeaderIcon="{xh:FontIcon Glyph=&#xe7c3;}">
<controls:SettingsCard.Description>
<TextBlock>
<Run Text="Referenced" /> <Run Text="{Binding GameStorageInfo.LibrariesCount}" /> <Run Text="Libraries;" />
<Run Text="Referenced" /> <Run Text="{Binding GameStorageInfo.AssetsCount}" /> <Run Text="Assets;" />
</TextBlock>
</controls:SettingsCard.Description>
<TextBlock Text="{Binding FormatSize}" />
</controls:SettingsCard>

</StackPanel>
</Border>
</ScrollViewer>
Expand Down
7 changes: 6 additions & 1 deletion Natsurainko.FluentLauncher/Views/Cores/Manage/SavePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,22 @@
</Border>
<StackPanel Grid.Column="2" VerticalAlignment="Center">
<TextBlock
IsTextSelectionEnabled="True"
Text="{Binding LevelName}"
TextTrimming="CharacterEllipsis"
ToolTipService.ToolTip="{Binding Path=Text, RelativeSource={RelativeSource Mode=Self}}" />
<StackPanel Orientation="Horizontal" Spacing="5">
<TextBlock Foreground="{ThemeResource ApplicationSecondaryForegroundThemeBrush}" Style="{ThemeResource CaptionTextBlockStyle}">
<TextBlock
Foreground="{ThemeResource ApplicationSecondaryForegroundThemeBrush}"
IsTextSelectionEnabled="True"
Style="{ThemeResource CaptionTextBlockStyle}">
<Run Text="{Binding FolderName}" />
<Run>(</Run><Run Text="{Binding LastPlayed}" /><Run>)</Run>
</TextBlock>
</StackPanel>
<TextBlock
Foreground="{ThemeResource ApplicationSecondaryForegroundThemeBrush}"
IsTextSelectionEnabled="True"
Style="{ThemeResource CaptionTextBlockStyle}"
Text="{Binding Converter={ThemeResource SaveInfoConverter}}" />
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 99b7d94

Please sign in to comment.