XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

SpaceEngineersModDev/SpaceEngineersBlueprintEditorInWinUI

完善文件夹设置和缓存清理

829580e
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

10 个文件 +169 -10
Modified SpaceEngineersBlueprintEditor/Implements/Services/SettingService.cs +11 -1
@@ -18,6 +18,14 @@ internal class SettingService : GlobalServiceBase, ISettingService
18 18 throw new NullReferenceException();
19 19 }
20 20
21 public void AddTextBlock(TextBlock textBlock, Action<string?> loadFunc)
22 {
23 if (textBlock.Tag is string profilePath)
24 settingControls.Add(textBlock, new TextBlockProfileInfoEntry(profilePath, loadFunc));
25 else
26 throw new NullReferenceException();
27 }
28
21 29 private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
22 30 {
23 31 if (settingControls.TryGetValue(sender, out var profileInfo) && profileInfo is ComboBoxProfileInfoEntry comboBoxProfileInfo && e.AddedItems.Count > 0 && e.AddedItems[0] is ComboBoxItem comboBoxItem && comboBoxItem.Tag is string value)
@@ -29,7 +37,9 @@ internal class SettingService : GlobalServiceBase, ISettingService
29 37 foreach (var item in settingControls)
30 38 {
31 39 if (item.Key is ComboBox comboBox && item.Value is ComboBoxProfileInfoEntry comboBoxProfileInfo)
32 comboBox.SelectedItem = comboBoxProfileInfo.ProfileLoadFunc.Invoke([.. comboBox.Items], ProfileHelper.GetProfileValue(comboBoxProfileInfo.ProfilePath));
40 comboBox.SelectedItem = comboBoxProfileInfo.ProfileLoadFunc([.. comboBox.Items], ProfileHelper.GetProfileValue(comboBoxProfileInfo.ProfilePath));
41 if (item.Key is TextBlock textBlock && item.Value is TextBlockProfileInfoEntry textBlockProfileInfo)
42 textBlockProfileInfo.ProfileLoadFunc(ProfileHelper.GetProfileValue(textBlockProfileInfo.ProfilePath)?.ToString());
33 43 }
34 44 }
35 45
Modified SpaceEngineersBlueprintEditor/Interface/Services/ISettingService.cs +1 -0
@@ -4,6 +4,7 @@ public interface ISettingService
4 4 {
5 5 Dictionary<object, IProfileInfoEntry> SettingControls { get; }
6 6 void AddComboBox(ComboBox comboBox, Func<string, object?> saveFunc, Func<List<object>, object?, object?> loadFunc);
7 void AddTextBlock(TextBlock textBlock, Action<string?> loadFunc);
7 8 void Initialize();
8 9 void RegisterEvents();
9 10 }
Added SpaceEngineersBlueprintEditor/Model/TextBlockProfileInfoEntry.cs +5 -0
@@ -0,0 +1,5 @@
1 using SpaceEngineersBlueprintEditor.Interface;
2
3 namespace SpaceEngineersBlueprintEditor.Model;
4
5 public record class TextBlockProfileInfoEntry(string ProfilePath, Action<string?> ProfileLoadFunc) : IProfileInfoEntry { }
Modified SpaceEngineersBlueprintEditor/Profiles/CrossVersionProfiles/SystemProfile.cs +0 -3
@@ -18,9 +18,6 @@ public partial class SystemProfile
18 18 static partial void SetNavigationStyleProperty(NavigationViewPaneDisplayMode value)
19 19 {
20 20 if (GlobalServiceManager.GetService<INavigationViewService>() is INavigationViewService navigationViewService && navigationViewService.NavigationView is not null)
21 {
22
23 21 navigationViewService.NavigationView.PaneDisplayMode = value;
24 }
25 22 }
26 23 }
Modified SpaceEngineersBlueprintEditor/Strings/en-us/Resources.resw +36 -0
@@ -225,6 +225,10 @@
225 225 <value>Navigation style</value>
226 226 <comment>导航栏样式</comment>
227 227 </data>
228 <data name="SettingPage_NavigationStyle.Description" xml:space="preserve">
229 <value>The position of the navigation bar</value>
230 <comment>导航栏出现的位置</comment>
231 </data>
228 232 <data name="SettingPage_NavigationStyle_Auto.Content" xml:space="preserve">
229 233 <value>Auto</value>
230 234 <comment>自动</comment>
@@ -249,6 +253,38 @@
249 253 <value>About</value>
250 254 <comment>关于</comment>
251 255 </data>
256 <data name="SettingPage_EnvironmentTitle.Text" xml:space="preserve">
257 <value>Environment</value>
258 <comment>环境</comment>
259 </data>
260 <data name="SettingPage_Paths.Header" xml:space="preserve">
261 <value>All paths</value>
262 <comment>所有目录</comment>
263 </data>
264 <data name="SettingPage_Paths.Description" xml:space="preserve">
265 <value>Application environment folders</value>
266 <comment>应用程序的环境目录</comment>
267 </data>
268 <data name="SettingPage_GameRootPath.Header" xml:space="preserve">
269 <value>Game root path</value>
270 <comment>游戏根目录</comment>
271 </data>
272 <data name="SettingPage_CachePath.Header" xml:space="preserve">
273 <value>Cache path</value>
274 <comment>缓存目录</comment>
275 </data>
276 <data name="SettingPage_OpenPath.Content" xml:space="preserve">
277 <value>Open</value>
278 <comment>打开目录</comment>
279 </data>
280 <data name="SettingPage_ChangePath.Content" xml:space="preserve">
281 <value>Change</value>
282 <comment>更改目录</comment>
283 </data>
284 <data name="SettingPage_ClearCache.Content" xml:space="preserve">
285 <value>Clear</value>
286 <comment>清除缓存</comment>
287 </data>
252 288 <data name="AppShell_ShellMenu_ViewDefinitions.Content" xml:space="preserve">
253 289 <value>Game Definitions</value>
254 290 <comment>游戏定义集</comment>
Modified SpaceEngineersBlueprintEditor/Utilities/Helpers/FileHelper.cs +16 -0
@@ -8,6 +8,22 @@ namespace SpaceEngineersBlueprintEditor.Utilities.Helpers;
8 8
9 9 public static class FileHelper
10 10 {
11 public static long GetDirectorySize(DirectoryInfo directoryInfo)
12 {
13 long size = 0;
14 FileInfo[] files = directoryInfo.GetFiles();
15 foreach (FileInfo file in files)
16 {
17 size += file.Length;
18 }
19 DirectoryInfo[] directories = directoryInfo.GetDirectories();
20 foreach (DirectoryInfo directory in directories)
21 {
22 size += GetDirectorySize(directory);
23 }
24 return size;
25 }
26
11 27 public static string GetCopyFileName(string originalName, int currentNum = 1)
12 28 {
13 29 var currentFileName = @$"{Path.GetDirectoryName(originalName)}\{Path.GetFileNameWithoutExtension(originalName)}_{currentNum}{Path.GetExtension(originalName)}";
Modified SpaceEngineersBlueprintEditor/ViewModels/SettingPageViewModel.cs +70 -3
@@ -2,7 +2,13 @@
2 2 using CommunityToolkit.Mvvm.Input;
3 3 using SpaceEngineersBlueprintEditor.Implements.Services;
4 4 using SpaceEngineersBlueprintEditor.Interface.Services;
5 using SpaceEngineersBlueprintEditor.Utilities;
6 using SpaceEngineersBlueprintEditor.Views;
7 using System.Diagnostics;
8 using Windows.Storage;
9 using Windows.Storage.Pickers;
5 10 using Windows.System;
11 using XFEExtension.NetCore.FileExtension;
6 12
7 13 namespace SpaceEngineersBlueprintEditor.ViewModels;
8 14
@@ -10,20 +16,81 @@ public partial class SettingPageViewModel : ViewModelBase
10 16 {
11 17 [ObservableProperty]
12 18 string currentVersion = "";
13
19 [ObservableProperty]
20 string spaceEngineersRootPath = "";
21 [ObservableProperty]
22 string appCachePath = "";
23 [ObservableProperty]
24 string appCacheSize = "";
14 25 public ISettingService SettingService { get; } = new SettingService();
15 26
16 27 public SettingPageViewModel()
17 28 {
29 SpaceEngineersRootPath = SystemProfile.GameRootPath;
30 AppCachePath = AppPath.AppCache;
18 31 if (System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version is Version version)
19 32 {
20 33 CurrentVersion = version.ToString();
21 34 }
35 AppCacheSize = FileHelper.GetDirectorySize(new(AppPath.AppCache)).FileSize();
36 }
37
38 private static async Task<(ContentDialog, StorageFolder)?> UserChoseAndGetDialog(string originalPath)
39 {
40 var openPicker = new FolderPicker();
41 WinRT.Interop.InitializeWithWindow.Initialize(openPicker, WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow));
42 openPicker.ViewMode = PickerViewMode.List;
43 var folder = await openPicker.PickSingleFolderAsync();
44 if (folder is not null && SettingPage.Current is not null)
45 {
46 var contentDialog = new ContentDialog
47 {
48 DefaultButton = ContentDialogButton.Primary,
49 IsPrimaryButtonEnabled = true,
50 Content = $"将目录从:{originalPath}\n更改为:{folder.Path}\n\n是否更改?",
51 PrimaryButtonText = "确认",
52 IsSecondaryButtonEnabled = true,
53 SecondaryButtonText = "取消",
54 XamlRoot = SettingPage.Current.Content.XamlRoot
55 };
56 return (contentDialog, folder);
57 }
58 return null;
59 }
60
61 [RelayCommand]
62 static async Task LinkToGithubRepo() => await Launcher.LaunchUriAsync(new Uri("https://github.com/XFEstudio/SpaceEngineersBlueprintEditorInWinUI"));
63
64 [RelayCommand]
65 static void OpenPath(string originalPath) => Process.Start("explorer.exe", originalPath);
66
67 [RelayCommand]
68 async Task ClearCache()
69 {
70 if (SettingPage.Current is not null)
71 {
72 var contentDialog = new ContentDialog
73 {
74 DefaultButton = ContentDialogButton.Primary,
75 IsPrimaryButtonEnabled = true,
76 Content = "是否清除包括已加载的游戏定义集在内的缓存文件?",
77 PrimaryButtonText = "确认",
78 IsSecondaryButtonEnabled = true,
79 SecondaryButtonText = "取消",
80 XamlRoot = SettingPage.Current.Content.XamlRoot
81 };
82 if (await contentDialog.ShowAsync() == ContentDialogResult.Primary)
83 {
84 Directory.Delete(AppPath.AppCache, true);
85 AppCacheSize = FileHelper.GetDirectorySize(new(AppPath.AppCache)).FileSize();
86 }
87 }
22 88 }
23 89
24 90 [RelayCommand]
25 static async Task LinkToGithubRepo()
91 static async Task ChangeGameRootPath()
26 92 {
27 await Launcher.LaunchUriAsync(new Uri("https://github.com/XFEstudio/SpaceEngineersBlueprintEditorInWinUI"));
93 if (await UserChoseAndGetDialog(SystemProfile.GameRootPath) is (ContentDialog, StorageFolder) result && await result.Item1.ShowAsync() == ContentDialogResult.Primary)
94 SystemProfile.GameRootPath = result.Item2.Path;
28 95 }
29 96 }
Modified SpaceEngineersBlueprintEditor/Views/GameDefinitionsViewPage.xaml +1 -1
@@ -20,7 +20,7 @@
20 20 </StackPanel>
21 21 </Grid>
22 22 </Grid>
23 <Grid ColumnDefinitions="4*, *" RowSpacing="20">
23 <Grid ColumnDefinitions="8*, 3*" RowSpacing="20">
24 24 <ItemsView x:Name="definitionsItemView" Canvas.ZIndex="0" Padding="4" ItemsSource="{x:Bind ViewModel.Definitions}">
25 25 <ItemsView.Layout>
26 26 <UniformGridLayout Orientation="Horizontal" />
Modified SpaceEngineersBlueprintEditor/Views/SettingPage.xaml +28 -1
@@ -18,7 +18,7 @@
18 18 </Style.Setters>
19 19 </Style>
20 20 </Page.Resources>
21
21
22 22 <Grid>
23 23 <ScrollViewer>
24 24 <StackPanel Spacing="4">
@@ -45,6 +45,33 @@
45 45 <ComboBoxItem x:Uid="SettingPage_NavigationStyle_LeftMinimal" Tag="LeftMinimal"/>
46 46 </ComboBox>
47 47 </toolkit:SettingsCard>
48 <TextBlock x:Uid="SettingPage_EnvironmentTitle" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"/>
49 <toolkit:SettingsExpander x:Uid="SettingPage_Paths">
50 <toolkit:SettingsExpander.HeaderIcon>
51 <FontIcon Glyph="&#xEC6C;"/>
52 </toolkit:SettingsExpander.HeaderIcon>
53 <toolkit:SettingsExpander.Items>
54 <toolkit:SettingsCard x:Uid="SettingPage_GameRootPath" Description="{x:Bind ViewModel.SpaceEngineersRootPath, Mode=OneWay}" IsClickEnabled="True" Command="{x:Bind ViewModel.OpenPathCommand}" CommandParameter="{x:Bind ViewModel.SpaceEngineersRootPath, Mode=OneWay}">
55 <toolkit:SettingsCard.ActionIcon>
56 <FontIcon Glyph="&#xE8A7;"/>
57 </toolkit:SettingsCard.ActionIcon>
58 <Button x:Uid="SettingPage_ChangePath" Command="{x:Bind ViewModel.ChangeGameRootPathCommand}"/>
59 </toolkit:SettingsCard>
60 <toolkit:SettingsCard x:Uid="SettingPage_CachePath" Description="{x:Bind ViewModel.AppCachePath, Mode=OneWay}" IsClickEnabled="True" Command="{x:Bind ViewModel.OpenPathCommand}" CommandParameter="{x:Bind ViewModel.AppCachePath, Mode=OneWay}">
61 <toolkit:SettingsCard.ActionIcon>
62 <FontIcon Glyph="&#xE8A7;"/>
63 </toolkit:SettingsCard.ActionIcon>
64 <Grid ColumnSpacing="20">
65 <Grid.ColumnDefinitions>
66 <ColumnDefinition Width="*"/>
67 <ColumnDefinition Width="*"/>
68 </Grid.ColumnDefinitions>
69 <TextBlock Style="{ThemeResource CaptionTextBlockStyle}" Text="{x:Bind ViewModel.AppCacheSize, Mode=OneWay}" VerticalAlignment="Center"/>
70 <Button Grid.Column="1" x:Uid="SettingPage_ClearCache" Command="{x:Bind ViewModel.ClearCacheCommand}"/>
71 </Grid>
72 </toolkit:SettingsCard>
73 </toolkit:SettingsExpander.Items>
74 </toolkit:SettingsExpander>
48 75 <TextBlock x:Uid="SettingPage_AboutTitle" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"/>
49 76 <toolkit:SettingsExpander x:Uid="SettingPage_AppInfo_Expander">
50 77 <toolkit:SettingsExpander.HeaderIcon>
Modified SpaceEngineersBlueprintEditor/Views/SettingPage.xaml.cs +1 -1
@@ -9,7 +9,7 @@ namespace SpaceEngineersBlueprintEditor.Views;
9 9 public sealed partial class SettingPage : Page
10 10 {
11 11 public SettingPageViewModel ViewModel { get; set; } = new();
12 public SettingPage? Current { get; set; }
12 public static SettingPage? Current { get; set; }
13 13 public SettingPage()
14 14 {
15 15 PageManager.AddOrUpdateCurrentPage(Current = this);