From ddf886b20abe1164e914e90db5b626b0e7d16c13 Mon Sep 17 00:00:00 2001 From: muqing <1966944300@qq.com> Date: Thu, 1 Aug 2024 22:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E4=B8=80=E4=B8=8B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E7=B4=AF=E4=BA=86=EF=BC=8C=E5=96=9D=E4=B8=80?= =?UTF-8?q?=E6=9D=AF=E5=92=96=E5=95=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Activation/DefaultActivationHandler.cs | 1 - RustTools/App.xaml.cs | 72 ++++++++++++++---- RustTools/MainWindow.xaml.cs | 2 - RustTools/Package.appinstaller | 1 - RustTools/Package.appxmanifest | 10 +++ RustTools/RustTools.csproj | 4 + RustTools/Views/SettingsPage.xaml | 15 +++- RustTools/Views/SettingsPage.xaml.cs | 74 +++++++++++-------- RustTools/WindowUI/ImportModule.xaml | 47 ++++++++++++ RustTools/WindowUI/ImportModule.xaml.cs | 72 ++++++++++++++++++ RustTools/WindowUI/ModulePage.xaml | 5 +- RustTools/muqing/IniHelper.cs | 5 +- RustTools/muqing/gj.cs | 8 ++ RustTools/muqing/mod.cs | 35 ++++++++- 14 files changed, 296 insertions(+), 55 deletions(-) create mode 100644 RustTools/WindowUI/ImportModule.xaml create mode 100644 RustTools/WindowUI/ImportModule.xaml.cs diff --git a/RustTools/Activation/DefaultActivationHandler.cs b/RustTools/Activation/DefaultActivationHandler.cs index 86bb48a..9320861 100644 --- a/RustTools/Activation/DefaultActivationHandler.cs +++ b/RustTools/Activation/DefaultActivationHandler.cs @@ -4,7 +4,6 @@ using RustTools.Contracts.Services; using RustTools.ViewModels; namespace RustTools.Activation; - public class DefaultActivationHandler : ActivationHandler { private readonly INavigationService _navigationService; diff --git a/RustTools/App.xaml.cs b/RustTools/App.xaml.cs index ae37fa7..179e20a 100644 --- a/RustTools/App.xaml.cs +++ b/RustTools/App.xaml.cs @@ -3,20 +3,24 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.UI.Xaml; -using RustTools.Activation; using RustTools.Contracts.Services; -using RustTools.Helpers; using RustTools.Models; using RustTools.Services; using RustTools.ViewModels; using RustTools.Views; -using System.Threading; using RustTools.muqing; +using RustTools.Activation; +using System.Diagnostics; +using RustTools.WindowUI; +using Windows.ApplicationModel.Activation; +using Windows.Storage; +using Microsoft.UI.Xaml.Controls; +using Microsoft.Windows.AppLifecycle; namespace RustTools; // To learn more about WinUI 3, see https://docs.microsoft.com/windows/apps/winui/winui3/. -public partial class App : Application +public partial class App : Microsoft.UI.Xaml.Application { // The .NET Generic Host provides dependency injection, configuration, logging, and other services. // https://docs.microsoft.com/dotnet/core/extensions/generic-host @@ -46,18 +50,15 @@ public partial class App : Application public App() { InitializeComponent(); - System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName("RustTools");//获取指定的进程名 - if (myProcesses.Length > 1) //如果可以获取到知道的进程名则说明已经启动 - { - Exit(); //关闭系统 - } + // 注册激活事件处理程序 + Host = Microsoft.Extensions.Hosting.Host. CreateDefaultBuilder(). UseContentRoot(AppContext.BaseDirectory). ConfigureServices((context, services) => { // Default Activation Handler - services.AddTransient, DefaultActivationHandler>(); + services.AddTransient, DefaultActivationHandler>(); // Other Activation Handlers @@ -103,10 +104,53 @@ public partial class App : Application // https://docs.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.application.unhandledexception. } - protected async override void OnLaunched(LaunchActivatedEventArgs args) - { - base.OnLaunched(args); - await App.GetService().ActivateAsync(args); + protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) + { + + + var activatedEventArgs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs(); + if (activatedEventArgs.Kind == Microsoft.Windows.AppLifecycle.ExtendedActivationKind.File) + { + gj.sc("打开文件"); + if (activatedEventArgs.Kind == ExtendedActivationKind.File) + { + if (activatedEventArgs.Data is IFileActivatedEventArgs fileArgs) + { + var files = fileArgs.Files; + // 处理打开的文件 + foreach (var file in files) + { + var storageFile = file as Windows.Storage.StorageFile; + if (storageFile != null) + { + gj.sc(storageFile.Path); + var importModule=new ImportModule(storageFile.Path); + importModule.Activate(); + // 读取或处理文件内容 + } + } + } + } + return; + } + // If this is the first instance launched, then register it as the "main" instance. + // If this isn't the first instance launched, then "main" will already be registered, + // so retrieve it. + var mainInstance = Microsoft.Windows.AppLifecycle.AppInstance.FindOrRegisterForKey("main"); + // If the instance that's executing the OnLaunched handler right now + // isn't the "main" instance. + if (!mainInstance.IsCurrent) + { + // Redirect the activation (and args) to the "main" instance, and exit. + await mainInstance.RedirectActivationToAsync(activatedEventArgs); + System.Diagnostics.Process.GetCurrentProcess().Kill(); + return; + } + else + { + base.OnLaunched(args); + await App.GetService().ActivateAsync(args); + } } } diff --git a/RustTools/MainWindow.xaml.cs b/RustTools/MainWindow.xaml.cs index c24de72..5130ca1 100644 --- a/RustTools/MainWindow.xaml.cs +++ b/RustTools/MainWindow.xaml.cs @@ -7,13 +7,11 @@ namespace RustTools; public sealed partial class MainWindow : WindowEx { private readonly Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue; - public static MainWindow Main; private readonly UISettings settings; public MainWindow() { - Main = this; gj.SetBackTheme(this); InitializeComponent(); //AppWindow.SetIcon("Assets/tool.png"); diff --git a/RustTools/Package.appinstaller b/RustTools/Package.appinstaller index c619457..3d36cf8 100644 --- a/RustTools/Package.appinstaller +++ b/RustTools/Package.appinstaller @@ -9,7 +9,6 @@ Version="{Version}" Publisher="{Publisher}" Uri="{MainPackageUri}"/> - diff --git a/RustTools/Package.appxmanifest b/RustTools/Package.appxmanifest index 3b5708e..13c619b 100644 --- a/RustTools/Package.appxmanifest +++ b/RustTools/Package.appxmanifest @@ -58,6 +58,16 @@ + + + + .rwmod + + 添加模组 + Assets\tool.png + 需要绑定铁锈路径 + + diff --git a/RustTools/RustTools.csproj b/RustTools/RustTools.csproj index ebd2834..f319a17 100644 --- a/RustTools/RustTools.csproj +++ b/RustTools/RustTools.csproj @@ -27,6 +27,7 @@ + @@ -56,6 +57,9 @@ True \ + + MSBuild:Compile + MSBuild:Compile diff --git a/RustTools/Views/SettingsPage.xaml b/RustTools/Views/SettingsPage.xaml index 0d67c47..edbc958 100644 --- a/RustTools/Views/SettingsPage.xaml +++ b/RustTools/Views/SettingsPage.xaml @@ -70,12 +70,21 @@ + QuerySubmitted="AutoSuggestBox_Url" /> + + + diff --git a/RustTools/Views/SettingsPage.xaml.cs b/RustTools/Views/SettingsPage.xaml.cs index 66f3274..0e0a9a7 100644 --- a/RustTools/Views/SettingsPage.xaml.cs +++ b/RustTools/Views/SettingsPage.xaml.cs @@ -1,15 +1,9 @@ -using Microsoft.UI; -using Microsoft.UI.Composition.SystemBackdrops; + using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Data; -using Microsoft.UI.Xaml.Media; using RustTools.muqing; using RustTools.ViewModels; -using Windows.Storage.AccessCache; using Windows.Storage.Pickers; -using Windows.Storage; -using WinUIEx; namespace RustTools.Views; @@ -52,13 +46,14 @@ public sealed partial class SettingsPage : Page } BackgroundRadioButtons.SelectionChanged += BackgroundColor_SelectionChanged; ModFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl); + MapsFileUrlText.Text = iniHelper.GetValue(IniHelper.CODE.Rust,IniHelper.KEY.MapsFileUrl); } private bool Backone = false; private void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (Backone) { - if (MainWindow.Main != null && sender is RadioButtons rb) + if (App.MainWindow != null && sender is RadioButtons rb) { var colorName = rb.SelectedItem as string; var iniHelper = new IniHelper(); @@ -66,7 +61,7 @@ public sealed partial class SettingsPage : Page #pragma warning disable CS8604 // 引用类型参数可能为 null。 iniHelper.SetValue(IniHelper.CODE.Settings, IniHelper.KEY.SystemBackdrop, colorName); iniHelper.Save(); - gj.SetBackTheme(MainWindow.Main); + gj.SetBackTheme(App.MainWindow); } } else @@ -75,30 +70,32 @@ public sealed partial class SettingsPage : Page } } - private async void AutoSuggestBox_ModFileUrl(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) + private async void AutoSuggestBox_Url(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { - var dialog = new ContentDialog(); - dialog.XamlRoot = this.XamlRoot; - - //dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style; - dialog.Title = "选择搜索模式"; - dialog.SecondaryButtonText = "手动选择"; - dialog.CloseButtonText = "自动搜索"; - dialog.Content = "自动搜索利用助手专属搜索引擎进行全盘搜索游戏文件夹,直到找到 Rusted Warfare 文件夹为止 途中可选择中断。"; + var dialog = new ContentDialog + { + XamlRoot = XamlRoot, + //dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style; + Title = "选择搜索模式", + SecondaryButtonText = "手动选择", + PrimaryButtonText = "自动搜索", + Content = "手动选择请找到Rusted Warfare文件目录软件会自动给你填写mod和maps路径," + + "自动搜索直到找到 Rusted Warfare 文件夹为止 途中可选择中断。" + }; //dialog.DefaultButton = ContentDialogButton.Primary; dialog.SecondaryButtonClick += Dialog_SecondaryButtonClick; - dialog.CloseButtonClick += Dialog_CloseButtonClick; + dialog.PrimaryButtonClick += Dialog_PrimaryButtonClick; await dialog.ShowAsync(); } - - private void Dialog_CloseButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){ - var mod = new mod(); - ModFileUrlText.Text = mod.FileDir; + private void Dialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){ + var mod = new Mod(); + ModFileUrlText.Text =mod.getUnitsDir(); + MapsFileUrlText.Text =mod.getMaps(); + SaveModAndMaps(); } private async void Dialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args){ - var openPicker = new FolderPicker(); var window = App.MainWindow; var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window); @@ -109,18 +106,37 @@ public sealed partial class SettingsPage : Page if (folder != null) { //StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder); - ModFileUrlText.Text = folder.Path; + var a = Path.Combine(folder.Path, "mods\\units"); + ModFileUrlText.Text = a; + var b = Path.Combine(folder.Path, "mods\\maps"); + MapsFileUrlText.Text = b; + SaveModAndMaps(); } } + private void SaveModAndMaps() + { + var iniHelper = new IniHelper(); + 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(); + } + private void ModFileUrlText_LostFocus(object sender, RoutedEventArgs e) { - - // 获取 AutoSuggestBox 的当前文本 - var text = ModFileUrlText.Text; + var a=(AutoSuggestBox) sender; var iniHelper = new IniHelper(); iniHelper.Load(IniHelper.FILE.Config); - iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl, text); + if (a.Name.Equals("MapsFileUrlText")) + { + iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.MapsFileUrl, MapsFileUrlText.Text); + } + else if(a.Name.Equals("ModFileUrlText")) + { + iniHelper.SetValue(IniHelper.CODE.Rust, IniHelper.KEY.ModFileUrl, ModFileUrlText.Text); + } + // 获取 AutoSuggestBox 的当前文本 iniHelper.Save(); } } diff --git a/RustTools/WindowUI/ImportModule.xaml b/RustTools/WindowUI/ImportModule.xaml new file mode 100644 index 0000000..4c63c51 --- /dev/null +++ b/RustTools/WindowUI/ImportModule.xaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + +