From 91659543fa710c1ab4a80ff99dcd0d0a4b4e5fa0 Mon Sep 17 00:00:00 2001 From: muqing <1966944300@qq.com> Date: Thu, 15 Aug 2024 09:40:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E7=99=BB=E9=99=86=E7=9A=84UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RustTools/ApiFox/mod.cs | 9 +- RustTools/App.xaml.cs | 14 +-- RustTools/DataList/CommunityList.cs | 4 +- RustTools/DataList/HomeBanner.cs | 9 +- RustTools/DataList/ModInfo.cs | 3 +- RustTools/DataList/ModListResponse.cs | 4 +- RustTools/DataList/MovingInfo.cs | 8 +- RustTools/Editor/EditorLoad.cs | 13 +-- RustTools/Editor/EditorTreeView.cs | 22 ++--- RustTools/Editor/EditorWin.xaml.cs | 65 ++++++------- .../Editor/ExplorerItemTemplateSelector.cs | 13 +-- .../Helpers/SettingsStorageExtensions.cs | 4 +- RustTools/Helpers/TitleBarHelper.cs | 1 - RustTools/MainWindow.xaml.cs | 6 +- RustTools/RustTools.csproj | 14 +++ RustTools/Services/LocalSettingsService.cs | 2 - RustTools/Styles/TitleSubtitleControl.cs | 24 +---- RustTools/Themes/ButtonIcon.xaml | 21 +++++ RustTools/Themes/ButtonIcon.xaml.cs | 31 +++++++ RustTools/Themes/LoginPage.xaml | 84 +++++++++++++++++ RustTools/Themes/LoginPage.xaml.cs | 91 +++++++++++++++++++ RustTools/Themes/NullPage.xaml.cs | 9 +- RustTools/ViewModels/ButtonViewModel.cs | 8 ++ RustTools/ViewModels/ConcernViewModel.cs | 3 +- RustTools/ViewModels/HomePageViewModel.cs | 4 +- RustTools/ViewModels/ModuleViewModel.cs | 13 +-- RustTools/ViewModels/RankingViewModel.cs | 2 - RustTools/ViewModels/SettingsViewModel.cs | 4 - RustTools/Views/ConcernPage.xaml.cs | 18 +--- RustTools/Views/HomePage.xaml.cs | 4 +- RustTools/Views/ModulePage.xaml.cs | 8 +- RustTools/Views/RankingPage.xaml.cs | 21 +---- RustTools/Views/SettingsPage.xaml.cs | 37 ++++---- RustTools/Views/ShellPage.xaml.cs | 18 ++-- RustTools/Views/UserPage.xaml | 43 +-------- RustTools/Views/UserPage.xaml.cs | 20 +--- RustTools/WindowUI/ImportModule.xaml.cs | 40 ++++---- RustTools/WindowUI/ModuleInfoWin.xaml.cs | 23 ++--- RustTools/muqing/IniHelper.cs | 9 +- RustTools/muqing/gj.cs | 13 +-- RustTools/muqing/mod.cs | 20 ++-- RustTools/muqing/wj.cs | 15 ++- RustTools/muqing/wl.cs | 8 +- 43 files changed, 421 insertions(+), 361 deletions(-) create mode 100644 RustTools/Themes/ButtonIcon.xaml create mode 100644 RustTools/Themes/ButtonIcon.xaml.cs create mode 100644 RustTools/Themes/LoginPage.xaml create mode 100644 RustTools/Themes/LoginPage.xaml.cs create mode 100644 RustTools/ViewModels/ButtonViewModel.cs diff --git a/RustTools/ApiFox/mod.cs b/RustTools/ApiFox/mod.cs index ab00397..a39ec98 100644 --- a/RustTools/ApiFox/mod.cs +++ b/RustTools/ApiFox/mod.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RustTools.muqing; +using RustTools.muqing; namespace RustTools.ApiFox; @@ -40,7 +35,7 @@ class mod public static async Task getInfo(string account, string modId) { - + var v = await wl.postAsync("/php/mod.php?action=getInfo", new string[][]{ new string[] { "account", account }, new string[] { "modId", modId} diff --git a/RustTools/App.xaml.cs b/RustTools/App.xaml.cs index dba5fc5..5c06b34 100644 --- a/RustTools/App.xaml.cs +++ b/RustTools/App.xaml.cs @@ -2,17 +2,16 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.UI.Xaml; +using Microsoft.Windows.AppLifecycle; +using RustTools.Activation; using RustTools.Contracts.Services; using RustTools.Models; +using RustTools.muqing; using RustTools.Services; using RustTools.ViewModels; using RustTools.Views; -using RustTools.muqing; -using RustTools.Activation; using RustTools.WindowUI; using Windows.ApplicationModel.Activation; -using Microsoft.Windows.AppLifecycle; -using WinUIEx; namespace RustTools; @@ -41,7 +40,10 @@ public partial class App : Microsoft.UI.Xaml.Application } - public static UIElement? AppTitlebar { get; set; } + public static UIElement? AppTitlebar + { + get; set; + } public static WindowEx? MainWindow; public App() @@ -123,7 +125,7 @@ public partial class App : Microsoft.UI.Xaml.Application if (storageFile != null) { gj.sc(storageFile.Path); - var importModule=new ImportModule(storageFile.Path); + var importModule = new ImportModule(storageFile.Path); importModule.Activate(); // 读取或处理文件内容 } diff --git a/RustTools/DataList/CommunityList.cs b/RustTools/DataList/CommunityList.cs index 67d57a5..8e0511d 100644 --- a/RustTools/DataList/CommunityList.cs +++ b/RustTools/DataList/CommunityList.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.ObjectModel; -using Newtonsoft.Json; +using Newtonsoft.Json; public class CommunityList { diff --git a/RustTools/DataList/HomeBanner.cs b/RustTools/DataList/HomeBanner.cs index 4191978..c81a4ee 100644 --- a/RustTools/DataList/HomeBanner.cs +++ b/RustTools/DataList/HomeBanner.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static System.Runtime.InteropServices.JavaScript.JSType; - -namespace RustTools.DataList; +namespace RustTools.DataList; public class HomeBanner { diff --git a/RustTools/DataList/ModInfo.cs b/RustTools/DataList/ModInfo.cs index 6dd2389..0bc840f 100644 --- a/RustTools/DataList/ModInfo.cs +++ b/RustTools/DataList/ModInfo.cs @@ -1,5 +1,4 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; public class ModInfo { diff --git a/RustTools/DataList/ModListResponse.cs b/RustTools/DataList/ModListResponse.cs index 6403bfb..0cc34dd 100644 --- a/RustTools/DataList/ModListResponse.cs +++ b/RustTools/DataList/ModListResponse.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; public class ModListResponse diff --git a/RustTools/DataList/MovingInfo.cs b/RustTools/DataList/MovingInfo.cs index 2297c07..f35d37e 100644 --- a/RustTools/DataList/MovingInfo.cs +++ b/RustTools/DataList/MovingInfo.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RustTools.DataList; +namespace RustTools.DataList; public class MovingInfo { public class Data diff --git a/RustTools/Editor/EditorLoad.cs b/RustTools/Editor/EditorLoad.cs index e8ef08a..119403e 100644 --- a/RustTools/Editor/EditorLoad.cs +++ b/RustTools/Editor/EditorLoad.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Windows.ApplicationModel.Payments; +using System.Collections.ObjectModel; namespace RustTools.Editor; public class EditorLoad @@ -67,7 +59,8 @@ public class EditorLoad // Type = ExplorerItem.ExplorerItemType.Folder, //}; //LoadDirectory(directoryInfos,rootItem); - foreach (var file in directoryInfos.GetDirectories()) { + foreach (var file in directoryInfos.GetDirectories()) + { var explorerItem = new ExplorerItem() { Name = file.Name, diff --git a/RustTools/Editor/EditorTreeView.cs b/RustTools/Editor/EditorTreeView.cs index 8587ecf..6a6baa1 100644 --- a/RustTools/Editor/EditorTreeView.cs +++ b/RustTools/Editor/EditorTreeView.cs @@ -1,18 +1,15 @@  -using Microsoft.UI.Xaml.Controls; +using System.Diagnostics; using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Input; using RustTools.muqing; using Windows.ApplicationModel.DataTransfer; -using Microsoft.UI.Xaml.Input; using Windows.Storage; -using RustTools.Helpers; -using Microsoft.UI.Xaml.Media; -using Windows.Foundation; -using System.Diagnostics; namespace RustTools.Editor; -public class EditorTreeView: TreeView +public class EditorTreeView : TreeView { public EditorTreeView() { @@ -34,7 +31,8 @@ public class EditorTreeView: TreeView e.Data.SetData("path", firstItem.Dir); e.Data.RequestedOperation = DataPackageOperation.Move; // Use Copy to avoid moving items } - private void EditorTreeView_DragItemsCompleted(TreeView sender, TreeViewDragItemsCompletedEventArgs e) { + private void EditorTreeView_DragItemsCompleted(TreeView sender, TreeViewDragItemsCompletedEventArgs e) + { // 获取拖拽的项 var items = e.Items.Cast().ToList(); @@ -114,9 +112,9 @@ public class EditorTreeView: TreeView var storageItems = await e.DataView.GetStorageItemsAsync(); // 获取目标文件夹,即拖放的位置 - - // 获取目标位置 - var treeView = sender as TreeView; + + // 获取目标位置 + var treeView = sender as TreeView; var data = await e.DataView.GetDataAsync("path"); gj.sc(data); @@ -125,7 +123,7 @@ public class EditorTreeView: TreeView if (item is StorageFolder folder) { // 移动文件夹 - gj.sc(folder.Path+"-->"); + gj.sc(folder.Path + "-->"); //var newFolder = await folder.MoveAsync(targetFolder, folder.Name, NameCollisionOption.ReplaceExisting); } else if (item is StorageFile file) diff --git a/RustTools/Editor/EditorWin.xaml.cs b/RustTools/Editor/EditorWin.xaml.cs index 0a8805a..332b2f7 100644 --- a/RustTools/Editor/EditorWin.xaml.cs +++ b/RustTools/Editor/EditorWin.xaml.cs @@ -1,18 +1,10 @@ -using System; using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Reflection; -using System.Reflection.Metadata; using Microsoft.UI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Documents; using Microsoft.UI.Xaml.Input; using RustTools.muqing; -using Windows.ApplicationModel.DataTransfer; using WinRT.Interop; namespace RustTools.Editor; /// @@ -22,7 +14,7 @@ public sealed partial class EditorWin : WindowEx { private readonly ObservableCollection TabViewList = new(); //Ŀ¼б - public ObservableCollection DataSource=new (); + public ObservableCollection DataSource = new(); public EditorWin() { InitializeComponent(); @@ -42,7 +34,7 @@ public sealed partial class EditorWin : WindowEx //Closed += EditorWin_Closed; var directoryInfo = new DirectoryInfo("D:\\steam\\steamapps\\common\\Rusted Warfare\\mods\\units\\Ͻ0.90.2"); DataSource = new EditorLoad().GetData(directoryInfo.FullName); - Title=directoryInfo.Name; + Title = directoryInfo.Name; TitleText.Text = directoryInfo.Name; Closed += EditorWin_Closed; } @@ -59,35 +51,36 @@ public sealed partial class EditorWin : WindowEx // ֹڹر e.Handled = true; } - if (ClosedDialog != null) { + if (ClosedDialog != null) + { return; } - // ʾһԻ򣬸֪ûڲܹر - ClosedDialog = new ContentDialog - { - XamlRoot = page.XamlRoot, - Title = "", - Content = "㻹δļڱС", - PrimaryButtonText = "ر", - PrimaryButtonStyle = Application.Current.Resources["AccentButtonStyle"] as Style, - SecondaryButtonText = "ֱӹر", - CloseButtonText = "ȡ" - }; - var result = await ClosedDialog.ShowAsync(); - if (result == ContentDialogResult.Primary) - { - IsSave = true; - Application.Current.Exit(); - return; - } - else if (result == ContentDialogResult.Secondary) - { + // ʾһԻ򣬸֪ûڲܹر + ClosedDialog = new ContentDialog + { + XamlRoot = page.XamlRoot, + Title = "", + Content = "㻹δļڱС", + PrimaryButtonText = "ر", + PrimaryButtonStyle = Application.Current.Resources["AccentButtonStyle"] as Style, + SecondaryButtonText = "ֱӹر", + CloseButtonText = "ȡ" + }; + var result = await ClosedDialog.ShowAsync(); + if (result == ContentDialogResult.Primary) + { + IsSave = true; + Application.Current.Exit(); + return; + } + else if (result == ContentDialogResult.Secondary) + { - IsSave = true; - Application.Current.Exit(); - return; - } - ClosedDialog = null; + IsSave = true; + Application.Current.Exit(); + return; + } + ClosedDialog = null; } private Microsoft.UI.Windowing.AppWindow GetAppWindowForCurrentWindow() diff --git a/RustTools/Editor/ExplorerItemTemplateSelector.cs b/RustTools/Editor/ExplorerItemTemplateSelector.cs index 10350b1..dd4bfba 100644 --- a/RustTools/Editor/ExplorerItemTemplateSelector.cs +++ b/RustTools/Editor/ExplorerItemTemplateSelector.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml; -using System.Collections.ObjectModel; +using System.Collections.ObjectModel; using System.ComponentModel; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; namespace RustTools.Editor; public class ExplorerItemTemplateSelector : DataTemplateSelector @@ -40,7 +35,7 @@ public class ExplorerItem : INotifyPropertyChanged } public string? Dir { - get;set; + get; set; } private ObservableCollection? m_children; public ObservableCollection Children diff --git a/RustTools/Helpers/SettingsStorageExtensions.cs b/RustTools/Helpers/SettingsStorageExtensions.cs index 5d37f18..15af8d4 100644 --- a/RustTools/Helpers/SettingsStorageExtensions.cs +++ b/RustTools/Helpers/SettingsStorageExtensions.cs @@ -1,6 +1,4 @@ -using RustTools.Helpers; - -using Windows.Storage; +using Windows.Storage; using Windows.Storage.Streams; namespace RustTools.Helpers; diff --git a/RustTools/Helpers/TitleBarHelper.cs b/RustTools/Helpers/TitleBarHelper.cs index 39358ba..ab8ab89 100644 --- a/RustTools/Helpers/TitleBarHelper.cs +++ b/RustTools/Helpers/TitleBarHelper.cs @@ -2,7 +2,6 @@ using Microsoft.UI; using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Media; using Windows.UI; using Windows.UI.ViewManagement; diff --git a/RustTools/MainWindow.xaml.cs b/RustTools/MainWindow.xaml.cs index 66ddfe7..4f1bd48 100644 --- a/RustTools/MainWindow.xaml.cs +++ b/RustTools/MainWindow.xaml.cs @@ -1,9 +1,5 @@ -using System.Resources; -using Microsoft.UI.Xaml; -using RustTools.Helpers; +using RustTools.Helpers; using RustTools.muqing; -using RustTools.WindowUI; -using Windows.Storage; using Windows.UI.ViewManagement; namespace RustTools; diff --git a/RustTools/RustTools.csproj b/RustTools/RustTools.csproj index f1f0cec..4f030a3 100644 --- a/RustTools/RustTools.csproj +++ b/RustTools/RustTools.csproj @@ -62,12 +62,26 @@ + + + + $(DefaultXamlRuntime) + Designer + MSBuild:Compile + + + + + + + + \ No newline at end of file diff --git a/RustTools/Services/LocalSettingsService.cs b/RustTools/Services/LocalSettingsService.cs index 49effd9..57dddbd 100644 --- a/RustTools/Services/LocalSettingsService.cs +++ b/RustTools/Services/LocalSettingsService.cs @@ -3,8 +3,6 @@ using RustTools.Contracts.Services; using RustTools.Helpers; using RustTools.Models; - -using Windows.ApplicationModel; using Windows.Storage; namespace RustTools.Services; diff --git a/RustTools/Styles/TitleSubtitleControl.cs b/RustTools/Styles/TitleSubtitleControl.cs index e015e61..d99d4b2 100644 --- a/RustTools/Styles/TitleSubtitleControl.cs +++ b/RustTools/Styles/TitleSubtitleControl.cs @@ -1,18 +1,5 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Data; -using Microsoft.UI.Xaml.Documents; -using Microsoft.UI.Xaml.Input; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Navigation; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Windows.Foundation; -using Windows.Foundation.Collections; namespace RustTools.Styles; public sealed class TitleSubtitleControl : Control @@ -24,16 +11,9 @@ public sealed class TitleSubtitleControl : Control public string TitleText { - get - { - return (string)GetValue(TitleTextProperty); - } - set - { - SetValue(TitleTextProperty, value); - } + get => (string)GetValue(TitleTextProperty); + set => SetValue(TitleTextProperty, value); } - public static readonly DependencyProperty TitleTextProperty = DependencyProperty.Register("TitleText", typeof(string), typeof(TitleSubtitleControl), new PropertyMetadata("")); diff --git a/RustTools/Themes/ButtonIcon.xaml b/RustTools/Themes/ButtonIcon.xaml new file mode 100644 index 0000000..d933e19 --- /dev/null +++ b/RustTools/Themes/ButtonIcon.xaml @@ -0,0 +1,21 @@ + + + + diff --git a/RustTools/Themes/ButtonIcon.xaml.cs b/RustTools/Themes/ButtonIcon.xaml.cs new file mode 100644 index 0000000..818a600 --- /dev/null +++ b/RustTools/Themes/ButtonIcon.xaml.cs @@ -0,0 +1,31 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +namespace RustTools.Themes; +public sealed partial class ButtonIcon : UserControl +{ + public ButtonIcon() + { + this.InitializeComponent(); + DefaultStyleKey = typeof(ButtonIcon); + } + + public string Glyph + { + get => (string)GetValue(GlyphProperty); + set => SetValue(GlyphProperty, value); + } + public static readonly DependencyProperty GlyphProperty = + DependencyProperty.Register("Glyph", typeof(string), typeof(ButtonIcon), new PropertyMetadata("\uE70A")); // Ĭֵ + public event RoutedEventHandler Click + { + add + { + button.Click += value; + } + remove + { + button.Click -= value; + } + } + +} diff --git a/RustTools/Themes/LoginPage.xaml b/RustTools/Themes/LoginPage.xaml new file mode 100644 index 0000000..19683eb --- /dev/null +++ b/RustTools/Themes/LoginPage.xaml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + public sealed partial class ConcernPage : Page { - public ConcernViewModel ViewModels { get; set; } + public ConcernViewModel ViewModels + { + get; set; + } public ConcernPage() { ViewModels = App.GetService(); diff --git a/RustTools/Views/HomePage.xaml.cs b/RustTools/Views/HomePage.xaml.cs index b21e7d5..1f2a683 100644 --- a/RustTools/Views/HomePage.xaml.cs +++ b/RustTools/Views/HomePage.xaml.cs @@ -1,11 +1,11 @@ using System.Collections.ObjectModel; using System.Diagnostics; +using System.Text.RegularExpressions; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Newtonsoft.Json; using RustTools.DataList; using RustTools.ViewModels; -using System.Text.RegularExpressions; using RustTools.WindowUI; namespace RustTools.Views; public sealed partial class HomePage : Page @@ -75,7 +75,7 @@ public sealed partial class HomePage : Page } } - private void RefreshRandom(object sender,RoutedEventArgs e) + private void RefreshRandom(object sender, RoutedEventArgs e) { ViewModel.random(); } diff --git a/RustTools/Views/ModulePage.xaml.cs b/RustTools/Views/ModulePage.xaml.cs index 476e6df..210eecf 100644 --- a/RustTools/Views/ModulePage.xaml.cs +++ b/RustTools/Views/ModulePage.xaml.cs @@ -1,15 +1,9 @@ - -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Reflection.Metadata.Ecma335; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Media; using RustTools.muqing; using RustTools.ViewModels; -using static IniHelper; -using static System.Collections.Specialized.BitVector32; namespace RustTools.Views; /// /// 模组碎片 @@ -69,7 +63,7 @@ public class DataObject if (dictionary.TryGetValue("mod", out var sectionValues)) { gj.sc(sectionValues); - Name =sectionValues.TryGetValue("title", out var value) ? value : Name; + Name = sectionValues.TryGetValue("title", out var value) ? value : Name; gj.sc(value); Info = sectionValues.TryGetValue("description", out var description) ? description : Info; } diff --git a/RustTools/Views/RankingPage.xaml.cs b/RustTools/Views/RankingPage.xaml.cs index d38301a..3d48531 100644 --- a/RustTools/Views/RankingPage.xaml.cs +++ b/RustTools/Views/RankingPage.xaml.cs @@ -1,21 +1,6 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; -using Microsoft.UI.Xaml.Data; -using Microsoft.UI.Xaml.Input; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Navigation; using RustTools.ViewModels; -using Newtonsoft.Json; -using RustTools.muqing; -using System.Collections; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -33,9 +18,9 @@ public sealed partial class RankingPage : Page public RankingPage() { - ViewModel=App.GetService(); + ViewModel = App.GetService(); InitializeComponent(); - list.ItemClick +=HomePage.ListAClick; + list.ItemClick += HomePage.ListAClick; } @@ -51,7 +36,7 @@ public sealed partial class RankingPage : Page var menu = (MenuFlyoutItem)sender; if (menu != null && menu.Tag != null) { - var tag =(string) menu.Tag; + var tag = (string)menu.Tag; ViewModel.ListTab(tag); } } diff --git a/RustTools/Views/SettingsPage.xaml.cs b/RustTools/Views/SettingsPage.xaml.cs index 0922d8b..74296e7 100644 --- a/RustTools/Views/SettingsPage.xaml.cs +++ b/RustTools/Views/SettingsPage.xaml.cs @@ -54,7 +54,7 @@ public sealed partial class SettingsPage : Page private async void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (Backone) - { + { if (App.MainWindow != null && sender is RadioButtons rb) { var colorName = rb.SelectedItem as string; @@ -70,7 +70,7 @@ public sealed partial class SettingsPage : Page { Backone = true; } - } + } private async void AutoSuggestBox_Url(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { @@ -90,11 +90,12 @@ public sealed partial class SettingsPage : Page await dialog.ShowAsync(); } - private void Dialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){ + private void Dialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { sender.Hide(); var mod = new Mod(XamlRoot, (FileDri) => { - gj.sc("找到了QWQ:::"+FileDri); + gj.sc("找到了QWQ:::" + FileDri); var a = Path.Combine(FileDri, "mods\\units"); ModFileUrlText.Text = a; var b = Path.Combine(FileDri, "mods\\maps"); @@ -103,7 +104,8 @@ public sealed partial class SettingsPage : Page }); } - private async void Dialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){ + private async void Dialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { var openPicker = new FolderPicker(); var window = App.MainWindow; var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window); @@ -125,7 +127,7 @@ public sealed partial class SettingsPage : Page private async void SaveModAndMaps() { var iniHelper = new IniHelper(); - iniHelper.Load(IniHelper.FILE.Config); + iniHelper.Load(IniHelper.FILE.Config); iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl, MapsFileUrlText.Text); iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl, ModFileUrlText.Text); iniHelper.Save(); @@ -133,37 +135,38 @@ public sealed partial class SettingsPage : Page private async void ModFileUrlText_LostFocus(object sender, RoutedEventArgs e) { - var a=(AutoSuggestBox) sender; + var a = (AutoSuggestBox)sender; var iniHelper = new IniHelper(); - iniHelper.Load(IniHelper.FILE.Config); + iniHelper.Load(IniHelper.FILE.Config); if (a.Name.Equals("MapsFileUrlText")) { var Url = MapsFileUrlText.Text; - if (!Directory.Exists(Url)&&Url!=string.Empty) { + if (!Directory.Exists(Url) && Url != string.Empty) + { Url = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl); - MapsFileUrlText.Text= Url; + MapsFileUrlText.Text = Url; } if (Url != string.Empty) { Url = Path.GetFullPath(Url); } - iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl,Url); - MapsFileUrlText.Text = Url; + iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl, Url); + MapsFileUrlText.Text = Url; } - else if(a.Name.Equals("ModFileUrlText")) + else if (a.Name.Equals("ModFileUrlText")) { var Url = ModFileUrlText.Text; - if (!Directory.Exists(Url)&&Url!=string.Empty) + if (!Directory.Exists(Url) && Url != string.Empty) { - Url=iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); + Url = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); ModFileUrlText.Text = Url; } if (Url != string.Empty) { Url = Path.GetFullPath(Url); } - iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl,Url); - ModFileUrlText.Text = Url; + iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl, Url); + ModFileUrlText.Text = Url; } // 获取 AutoSuggestBox 的当前文本 iniHelper.Save(); diff --git a/RustTools/Views/ShellPage.xaml.cs b/RustTools/Views/ShellPage.xaml.cs index a717527..fa3209a 100644 --- a/RustTools/Views/ShellPage.xaml.cs +++ b/RustTools/Views/ShellPage.xaml.cs @@ -1,11 +1,9 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Input; -using Microsoft.UI.Xaml.Media; using RustTools.Contracts.Services; using RustTools.Helpers; -using RustTools.muqing; using RustTools.ViewModels; using Windows.System; @@ -22,13 +20,13 @@ public sealed partial class ShellPage : Page public ShellPage(ShellViewModel viewModel) { - //< NavigationViewItem - // x: Uid = "Shell_Main" - // helpers: NavigationHelper.NavigateTo = "RustTools.ViewModels.MainViewModel"> - // < NavigationViewItem.Icon > - // < FontIcon FontFamily = "{StaticResource SymbolThemeFontFamily}" Glyph = "" /> - // - // + //< NavigationViewItem + // x: Uid = "Shell_Main" + // helpers: NavigationHelper.NavigateTo = "RustTools.ViewModels.MainViewModel"> + // < NavigationViewItem.Icon > + // < FontIcon FontFamily = "{StaticResource SymbolThemeFontFamily}" Glyph = "" /> + // + // ViewModel = viewModel; InitializeComponent(); @@ -43,7 +41,7 @@ public sealed partial class ShellPage : Page App.MainWindow.SetTitleBar(AppTitleBar); App.MainWindow.Activated += MainWindow_Activated; App.MainWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico")); - AppTitleBarText.Text = "app_name".GetLocalized() +" " +"app_version".GetLocalized(); + AppTitleBarText.Text = "app_name".GetLocalized() + " " + "app_version".GetLocalized(); } private void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) diff --git a/RustTools/Views/UserPage.xaml b/RustTools/Views/UserPage.xaml index 0081b09..3688dad 100644 --- a/RustTools/Views/UserPage.xaml +++ b/RustTools/Views/UserPage.xaml @@ -7,51 +7,12 @@ xmlns:local="using:RustTools.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:styles="using:RustTools.Styles" + xmlns:themes="using:RustTools.Themes" mc:Ignorable="d"> - - - - - - - - - - public sealed partial class UserPage : Page { - public UserViewModel UserViewModel { get; set; } + public UserViewModel UserViewModel + { + get; set; + } public UserPage() { - UserViewModel=App.GetService(); + UserViewModel = App.GetService(); InitializeComponent(); } } diff --git a/RustTools/WindowUI/ImportModule.xaml.cs b/RustTools/WindowUI/ImportModule.xaml.cs index 04c8cd5..0fb8f5d 100644 --- a/RustTools/WindowUI/ImportModule.xaml.cs +++ b/RustTools/WindowUI/ImportModule.xaml.cs @@ -1,7 +1,6 @@ using System.Diagnostics; -using System.IO; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using RustTools.muqing; @@ -10,33 +9,34 @@ namespace RustTools.WindowUI; public sealed partial class ImportModule : WindowEx { private readonly FileInfo? fileInfo; - private string ImpUrl= string.Empty; + private string ImpUrl = string.Empty; public ImportModule(string file) { InitializeComponent(); ExtendsContentIntoTitleBar = true; - if (file == string.Empty) { + if (file == string.Empty) + { Close(); return; } fileInfo = new FileInfo(file); var iniHelper = new IniHelper(); - iniHelper.Load(IniHelper.FILE.Config); - if (file.EndsWith(".rwmod")) - { - var l = " | "; - var formattedSize = wj.FormatFileSize(fileInfo.Length); - MessageText.Text = ":ģ" + l + "С" + formattedSize; - ImpUrl = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); - InfoText.Text = string.Format("ԭλ {0} --> {1} \nڴʱ벻Ҫرմ˴ ɹԶر ʧʾȨ޵ȴ", - file, ImpUrl); - } - NameText.Text = - fileInfo.Name; + iniHelper.Load(IniHelper.FILE.Config); + if (file.EndsWith(".rwmod")) + { + var l = " | "; + var formattedSize = wj.FormatFileSize(fileInfo.Length); + MessageText.Text = ":ģ" + l + "С" + formattedSize; + ImpUrl = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); + InfoText.Text = string.Format("ԭλ {0} --> {1} \nڴʱ벻Ҫرմ˴ ɹԶر ʧʾȨ޵ȴ", + file, ImpUrl); + } + NameText.Text = + fileInfo.Name; - GridView.Loaded += GridView_Loaded; - // Loaded ¼ + GridView.Loaded += GridView_Loaded; + // Loaded ¼ } private void GridView_Loaded(object sender, RoutedEventArgs e) @@ -89,10 +89,10 @@ public sealed partial class ImportModule : WindowEx { return; } - var button=sender as Button; + var button = sender as Button; if (button == null) { return; } - button.IsEnabled=false; + button.IsEnabled = false; gj.sc(fileInfo.ToString()); // ȷĿļд @@ -100,7 +100,7 @@ public sealed partial class ImportModule : WindowEx var destinationZipPath = Path.Combine(ImpUrl, fileInfo.Name); - await CopyFileWithProgressAsync( fileInfo.ToString() ,destinationZipPath, (percentage) => + await CopyFileWithProgressAsync(fileInfo.ToString(), destinationZipPath, (percentage) => { button.Content = $"{percentage:F2}%"; Debug.WriteLine($"ƽ: {percentage:F2}%"); diff --git a/RustTools/WindowUI/ModuleInfoWin.xaml.cs b/RustTools/WindowUI/ModuleInfoWin.xaml.cs index 26e65af..2aebb5f 100644 --- a/RustTools/WindowUI/ModuleInfoWin.xaml.cs +++ b/RustTools/WindowUI/ModuleInfoWin.xaml.cs @@ -1,16 +1,11 @@ +using System.Collections.ObjectModel; +using System.Diagnostics; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using RustTools.muqing; using Newtonsoft.Json; -using System.Collections.ObjectModel; -using Windows.ApplicationModel.Core; -using System.Diagnostics; -using Windows.UI.ViewManagement; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI; +using RustTools.muqing; using static RustTools.muqing.wl; -using System.Threading; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -124,13 +119,13 @@ public sealed partial class ModuleInfoWin : WindowEx var v = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); if (v == string.Empty) { - var dialog=new ContentDialog() + var dialog = new ContentDialog() { XamlRoot = grid.XamlRoot, - Title="", - Content="úģ·", - SecondaryButtonText="ȡ" - + Title = "", + Content = "úģ·", + SecondaryButtonText = "ȡ" + }; await dialog.ShowAsync(); return; @@ -156,7 +151,7 @@ public sealed partial class ModuleInfoWin : WindowEx File.Delete(PathMod + ".rwmod"); } // ļı· - await downloader.DownloadFileAsync(Mod.Link,PathMod, (totalBytesRead, totalBytes) => + await downloader.DownloadFileAsync(Mod.Link, PathMod, (totalBytesRead, totalBytes) => { DownloadDialogText.Text = $"Downloaded {totalBytesRead} of {totalBytes} bytes. {(totalBytes > 0 ? (double)totalBytesRead / totalBytes * 100 : 0):0.00}% complete."; //Debug.WriteLine($"Downloaded {totalBytesRead} of {totalBytes} bytes. {(totalBytes > 0 ? (double)totalBytesRead / totalBytes * 100 : 0):0.00}% complete."); diff --git a/RustTools/muqing/IniHelper.cs b/RustTools/muqing/IniHelper.cs index c39a6eb..3ff615d 100644 --- a/RustTools/muqing/IniHelper.cs +++ b/RustTools/muqing/IniHelper.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using RustTools.muqing; -using Windows.Storage; +using Windows.Storage; public class IniHelper { @@ -107,7 +103,8 @@ public class IniHelper /// public void Save() { - if (filePath==null||filePath==string.Empty) { + if (filePath == null || filePath == string.Empty) + { return; } diff --git a/RustTools/muqing/gj.cs b/RustTools/muqing/gj.cs index c8216f0..61b4277 100644 --- a/RustTools/muqing/gj.cs +++ b/RustTools/muqing/gj.cs @@ -2,17 +2,14 @@ using System.Diagnostics; namespace RustTools.muqing; using System; -using System.Diagnostics.Tracing; using System.Management; +using System.Runtime.InteropServices; using Microsoft.UI; using Microsoft.UI.Composition.SystemBackdrops; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media; -using Windows.UI.ViewManagement; -using System.Runtime.InteropServices; - using Windows.UI; -using System.Text.RegularExpressions; +using Windows.UI.ViewManagement; #pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 #pragma warning disable IDE1006 // 命名样式 @@ -89,7 +86,7 @@ public class gj private const int WAINACTIVE = 0x00; private const int WAACTIVE = 0x01; private const int WMACTIVATE = 0x0006; - public static void UpdateTitleBar(WindowEx a,ElementTheme theme) + public static void UpdateTitleBar(WindowEx a, ElementTheme theme) { if (a.ExtendsContentIntoTitleBar) { @@ -166,8 +163,8 @@ public class gj /// public static Dictionary> IniInfo(string filePath) { - - var sections=new Dictionary>(); + + var sections = new Dictionary>(); using (var reader = new StreamReader(filePath)) { string? line; diff --git a/RustTools/muqing/mod.cs b/RustTools/muqing/mod.cs index 07d004b..8127ac1 100644 --- a/RustTools/muqing/mod.cs +++ b/RustTools/muqing/mod.cs @@ -1,16 +1,11 @@ using System.Diagnostics; -using System.Reflection.Emit; +using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Media; using Microsoft.Win32; -using Newtonsoft.Json.Linq; using RustTools.muqing; -using Windows.ApplicationModel.Core; -using Windows.UI.Core; -using Microsoft.UI.Dispatching; public class Mod { @@ -36,8 +31,8 @@ public class Mod "androidstudioword","ͼսƽ̨","xshell7" }; //Ϸλ - public string FileDir =string.Empty; - private readonly ContentDialog? dialog =null; + public string FileDir = string.Empty; + private readonly ContentDialog? dialog = null; //MainPageĺ̨code public async void Invoke(Action action, Windows.UI.Core.CoreDispatcherPriority Priority = Windows.UI.Core.CoreDispatcherPriority.Normal) { @@ -57,7 +52,8 @@ public class Mod Debug.WriteLine("ʼִļ"); //steamеλ steam(); - if (FileDir == string.Empty) { + if (FileDir == string.Empty) + { //Ҳִ gj.sc("Ҳִ"); dialog = new ContentDialog() @@ -75,7 +71,8 @@ public class Mod await init(); // ʹ DispatcherQueue UI ίл UI ߳ - _dispatcherQueue.TryEnqueue(() => { + _dispatcherQueue.TryEnqueue(() => + { dialog.Closing -= Dialog_Closing; dialog.Hide(); action?.Invoke(FileDir); @@ -100,7 +97,8 @@ public class Mod } - private void Dialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args){ + private void Dialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) + { gj.sc(args.Result); if (args.Result != ContentDialogResult.Primary) { diff --git a/RustTools/muqing/wj.cs b/RustTools/muqing/wj.cs index 23cde15..5b8ffd8 100644 --- a/RustTools/muqing/wj.cs +++ b/RustTools/muqing/wj.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +using System.Diagnostics; using System.IO.Compression; -using Windows.Storage; -using Windows.Storage.Streams; namespace RustTools.muqing; #pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 @@ -26,17 +22,18 @@ public class wj public const string UUID = "win.uuid"; } - public static bool xrwb(string name,string str) + public static bool xrwb(string name, string str) { // 获取当前执行文件的目录 //var currentDirectory = Directory.GetCurrentDirectory(); - var filePath = Path.Combine(CD,name); + var filePath = Path.Combine(CD, name); try { File.WriteAllText(filePath, str); return true; } - catch (Exception ex) { + catch (Exception ex) + { Debug.WriteLine(ex.ToString()); } // 将 UUID 写入文件 @@ -51,7 +48,7 @@ public class wj public static bool cz(string name) { - return File.Exists(Path.Combine(CD,name)); + return File.Exists(Path.Combine(CD, name)); } public static string FormatFileSize(long bytes) diff --git a/RustTools/muqing/wl.cs b/RustTools/muqing/wl.cs index bf0c9c3..24f2879 100644 --- a/RustTools/muqing/wl.cs +++ b/RustTools/muqing/wl.cs @@ -1,6 +1,4 @@ -using System.Text.RegularExpressions; -using System.Threading; -using RestSharp; +using RestSharp; namespace RustTools.muqing; #pragma warning disable CS8981 // 该类型名称仅包含小写 ascii 字符。此类名称可能会成为该语言的保留值。 @@ -63,7 +61,7 @@ class wl public class FileDownloader { - private readonly HttpClient _httpClient=new(); + private readonly HttpClient _httpClient = new(); private bool IsDelete = false; public FileDownloader() { @@ -91,7 +89,7 @@ class wl //if (IsDelete) { // break; //} - await fileStream.WriteAsync(buffer, 0, bytesRead,cancellationToken); + await fileStream.WriteAsync(buffer, 0, bytesRead, cancellationToken); totalBytesRead += bytesRead; progress?.Invoke(totalBytesRead, totalBytes); }