From 416c7d18edb1dbde4027993ce7498b55b4e3f00d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=AB=98=E6=80=A1=E9=A3=9E?= <363301617@qq.com>
Date: Sun, 4 Aug 2024 21:18:44 +0800
Subject: [PATCH] Use SynchronizationContext.Post method to replace BeginInvoke
Use SynchronizationContext.Post method to replace BeginInvoke
---
.../Extensions/DataType/Enums/MenuType.cs | 23 +
WindowsTools/Models/ShellMenuItemModel.cs | 52 +-
WindowsTools/Program.cs | 7 +-
WindowsTools/Properties/AssemblyInfo.cs | 6 +-
WindowsTools/Strings/ShellMenu.Designer.cs | 96 +-
WindowsTools/Strings/ShellMenu.en-us.resx | 34 +-
WindowsTools/Strings/ShellMenu.resx | 34 +-
WindowsTools/Strings/ShellMenu.zh-hans.resx | 31 +-
.../UI/Backdrop/DesktopAcrylicBackdrop.cs | 24 +-
WindowsTools/UI/Backdrop/MicaBackdrop.cs | 24 +-
.../Controls/FirstLevelMenuEditControl.xaml | 1082 -----------------
.../FirstLevelMenuEditControl.xaml.cs | 681 -----------
.../Controls/SecondLevelMenuEditControl.xaml | 779 ------------
.../SecondLevelMenuEditControl.xaml.cs | 573 ---------
.../UI/Dialogs/AppInformationDialog.xaml | 1 -
.../UI/Dialogs/AppInformationDialog.xaml.cs | 23 +-
.../UI/Dialogs/FileCheckDialog.xaml.cs | 7 +-
.../UI/Dialogs/RestartAppsDialog.xaml.cs | 8 +-
WindowsTools/Views/Pages/AboutPage.xaml.cs | 26 +-
.../Views/Pages/CodeScannerPage.xaml.cs | 33 +-
.../Views/Pages/DownloadManagerPage.xaml.cs | 43 +-
.../Views/Pages/ExtensionNamePage.xaml.cs | 11 +-
.../Views/Pages/FileCertificatePage.xaml.cs | 11 +-
WindowsTools/Views/Pages/FileNamePage.xaml.cs | 11 +-
.../Views/Pages/FilePropertiesPage.xaml.cs | 11 +-
.../Views/Pages/FileUnlockPage.xaml.cs | 40 +-
.../Views/Pages/IconExtractPage.xaml.cs | 23 +-
WindowsTools/Views/Pages/LoafPage.xaml | 1 -
WindowsTools/Views/Pages/LoafPage.xaml.cs | 25 +-
.../Views/Pages/LoopbackManagerPage.xaml.cs | 19 +-
WindowsTools/Views/Pages/MainPage.xaml | 2 +
WindowsTools/Views/Pages/MainPage.xaml.cs | 18 +-
.../Views/Pages/PriExtractPage.xaml.cs | 36 +-
WindowsTools/Views/Pages/ShellMenuPage.xaml | 958 +++++++++++----
.../Views/Pages/ShellMenuPage.xaml.cs | 857 +++++++++++--
.../Views/Pages/SimulateUpdatePage.xaml.cs | 13 +-
.../Views/Pages/UpdateManagerPage.xaml.cs | 51 +-
.../Views/Pages/UpperAndLowerCasePage.xaml.cs | 11 +-
WindowsTools/Views/Pages/WinSATPage.xaml | 1 -
WindowsTools/Views/Pages/WinSATPage.xaml.cs | 28 +-
.../WindowsAPI/ComTypes/ACTIVATEOPTIONS.cs | 34 +
.../ComTypes/BackgroundCopyCallback.cs | 9 +-
.../ComTypes/DODownloadStatusCallback.cs | 3 +-
.../ComTypes/IApplicationActivationManager.cs | 38 +
.../ComTypes/IBackgroundCopyCallback.cs | 8 +-
.../ComTypes/IDODownloadStatusCallback.cs | 3 +-
.../WindowsAPI/ComTypes/IDOManager.cs | 4 +-
.../ComTypes/IDataTransferManagerInterop.cs | 6 +-
.../WindowsAPI/ComTypes/IPinnedList3.cs | 4 +-
.../WindowsAPI/ComTypes/IProgressDialog.cs | 18 +-
.../WindowsAPI/ComTypes/IShellLink.cs | 36 +-
WindowsToolsPackage/Package.appxmanifest | 2 +-
.../Properties/AssemblyInfo.cs | 6 +-
53 files changed, 1913 insertions(+), 3972 deletions(-)
create mode 100644 WindowsTools/Extensions/DataType/Enums/MenuType.cs
delete mode 100644 WindowsTools/UI/Controls/FirstLevelMenuEditControl.xaml
delete mode 100644 WindowsTools/UI/Controls/FirstLevelMenuEditControl.xaml.cs
delete mode 100644 WindowsTools/UI/Controls/SecondLevelMenuEditControl.xaml
delete mode 100644 WindowsTools/UI/Controls/SecondLevelMenuEditControl.xaml.cs
create mode 100644 WindowsTools/WindowsAPI/ComTypes/ACTIVATEOPTIONS.cs
create mode 100644 WindowsTools/WindowsAPI/ComTypes/IApplicationActivationManager.cs
diff --git a/WindowsTools/Extensions/DataType/Enums/MenuType.cs b/WindowsTools/Extensions/DataType/Enums/MenuType.cs
new file mode 100644
index 0000000..c953c95
--- /dev/null
+++ b/WindowsTools/Extensions/DataType/Enums/MenuType.cs
@@ -0,0 +1,23 @@
+namespace WindowsTools.Extensions.DataType.Enums
+{
+ ///
+ /// 菜单类型
+ ///
+ public enum MenuType
+ {
+ ///
+ /// 根菜单
+ ///
+ RootMenu = 0,
+
+ ///
+ /// 一级菜单
+ ///
+ FirstLevelMenu = 1,
+
+ ///
+ /// 二级菜单
+ ///
+ SecondLevelMenu = 2
+ }
+}
diff --git a/WindowsTools/Models/ShellMenuItemModel.cs b/WindowsTools/Models/ShellMenuItemModel.cs
index 3e71258..d011018 100644
--- a/WindowsTools/Models/ShellMenuItemModel.cs
+++ b/WindowsTools/Models/ShellMenuItemModel.cs
@@ -1,5 +1,8 @@
-using System.ComponentModel;
+using System;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
using Windows.UI.Xaml.Media;
+using WindowsTools.Extensions.DataType.Enums;
namespace WindowsTools.Models
{
@@ -8,6 +11,32 @@ namespace WindowsTools.Models
///
public class ShellMenuItemModel : INotifyPropertyChanged
{
+ ///
+ /// 菜单 Guid 号
+ ///
+ public Guid MenuGuid { get; set; }
+
+ ///
+ /// 菜单类型
+ ///
+ public MenuType MenuType { get; set; }
+
+ private bool _isSelected;
+
+ public bool IsSelected
+ {
+ get { return _isSelected; }
+
+ set
+ {
+ if (!Equals(_isSelected, value))
+ {
+ _isSelected = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsSelected)));
+ }
+ }
+ }
+
///
/// 菜单项索引
///
@@ -19,7 +48,7 @@ public int MenuIndex
set
{
- if (!Equals(value, _menuIndex))
+ if (!Equals(_menuIndex, value))
{
_menuIndex = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuIndex)));
@@ -103,21 +132,10 @@ public string ProgramPath
}
}
- private string _param;
-
- public string Param
- {
- get { return _param; }
-
- set
- {
- if (!Equals(_param, value))
- {
- _param = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Param)));
- }
- }
- }
+ ///
+ /// 子菜单
+ ///
+ public ObservableCollection SubMenuItemCollection { get; set; } = [];
public event PropertyChangedEventHandler PropertyChanged;
}
diff --git a/WindowsTools/Program.cs b/WindowsTools/Program.cs
index 71f6724..a182729 100644
--- a/WindowsTools/Program.cs
+++ b/WindowsTools/Program.cs
@@ -1,5 +1,4 @@
using System;
-using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Globalization;
using System.Threading;
@@ -10,6 +9,7 @@
using WindowsTools.Services.Root;
using WindowsTools.Services.Shell;
using WindowsTools.Views.Windows;
+using WindowsTools.WindowsAPI.ComTypes;
namespace WindowsTools
{
@@ -18,6 +18,8 @@ namespace WindowsTools
///
public class Program
{
+ private static Guid applicationActivationManagerCLSID = new("45BA127D-10A8-46EA-8AB7-56EA9078943C");
+
///
/// 应用程序的主入口点
///
@@ -26,7 +28,8 @@ public static void Main()
{
if (!RuntimeHelper.IsMSIX)
{
- Process.Start("explorer.exe", "shell:AppsFolder\\055B5CA4.WindowsTools_zp2hc899bs298!WindowsTools");
+ IApplicationActivationManager applicationActivationManager = (IApplicationActivationManager)Activator.CreateInstance(Type.GetTypeFromCLSID(applicationActivationManagerCLSID));
+ applicationActivationManager.ActivateApplication("Gaoyifei1011.WindowsTools_pystbwmrmew8c!WindowsTools", string.Empty, ACTIVATEOPTIONS.AO_NONE, out uint _);
return;
}
diff --git a/WindowsTools/Properties/AssemblyInfo.cs b/WindowsTools/Properties/AssemblyInfo.cs
index 88a6c83..fc63211 100644
--- a/WindowsTools/Properties/AssemblyInfo.cs
+++ b/WindowsTools/Properties/AssemblyInfo.cs
@@ -4,8 +4,8 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("Windows 工具箱")]
-[assembly: AssemblyFileVersion("2.7.801.0")]
-[assembly: AssemblyInformationalVersion("2.7.801.0")]
+[assembly: AssemblyFileVersion("2.7.804.0")]
+[assembly: AssemblyInformationalVersion("2.7.804.0")]
[assembly: AssemblyProduct("Windows 工具箱")]
[assembly: AssemblyTitle("Windows 工具箱")]
-[assembly: AssemblyVersion("2.7.801.0")]
+[assembly: AssemblyVersion("2.7.804.0")]
diff --git a/WindowsTools/Strings/ShellMenu.Designer.cs b/WindowsTools/Strings/ShellMenu.Designer.cs
index 81533a5..c6e1959 100644
--- a/WindowsTools/Strings/ShellMenu.Designer.cs
+++ b/WindowsTools/Strings/ShellMenu.Designer.cs
@@ -169,29 +169,11 @@ public static string Drive {
}
///
- /// 查找类似 Edit 的本地化字符串。
+ /// 查找类似 Edit menu 的本地化字符串。
///
- public static string Edit {
+ public static string EditMenu {
get {
- return ResourceManager.GetString("Edit", resourceCulture);
- }
- }
-
- ///
- /// 查找类似 There's no menu items 的本地化字符串。
- ///
- public static string EmptyDescription {
- get {
- return ResourceManager.GetString("EmptyDescription", resourceCulture);
- }
- }
-
- ///
- /// 查找类似 The content of the secondary menu is empty 的本地化字符串。
- ///
- public static string EmptySecondLevelMenu {
- get {
- return ResourceManager.GetString("EmptySecondLevelMenu", resourceCulture);
+ return ResourceManager.GetString("EditMenu", resourceCulture);
}
}
@@ -204,15 +186,6 @@ public static string Extension {
}
}
- ///
- /// 查找类似 First level menu 的本地化字符串。
- ///
- public static string FirstLevelMenu {
- get {
- return ResourceManager.GetString("FirstLevelMenu", resourceCulture);
- }
- }
-
///
/// 查找类似 Icon file(*.ico)|*.ico 的本地化字符串。
///
@@ -321,15 +294,6 @@ public static string MenuList {
}
}
- ///
- /// 查找类似 Menu order 的本地化字符串。
- ///
- public static string MenuOrder {
- get {
- return ResourceManager.GetString("MenuOrder", resourceCulture);
- }
- }
-
///
/// 查找类似 Menu parameter 的本地化字符串。
///
@@ -366,15 +330,6 @@ public static string MenuProgramPathPHText {
}
}
- ///
- /// 查找类似 Menu program path: 的本地化字符串。
- ///
- public static string MenuProgramPathToolTip {
- get {
- return ResourceManager.GetString("MenuProgramPathToolTip", resourceCulture);
- }
- }
-
///
/// 查找类似 Menu settings 的本地化字符串。
///
@@ -465,15 +420,6 @@ public static string None {
}
}
- ///
- /// 查找类似 Operation 的本地化字符串。
- ///
- public static string Operation {
- get {
- return ResourceManager.GetString("Operation", resourceCulture);
- }
- }
-
///
/// 查找类似 Precautions 的本地化字符串。
///
@@ -573,15 +519,6 @@ public static string Save {
}
}
- ///
- /// 查找类似 Second level menu 的本地化字符串。
- ///
- public static string SecondLevelMenu {
- get {
- return ResourceManager.GetString("SecondLevelMenu", resourceCulture);
- }
- }
-
///
/// 查找类似 Select icon 的本地化字符串。
///
@@ -663,33 +600,6 @@ public static string ShouldUseProgramIconOnContent {
}
}
- ///
- /// 查找类似 Should use second level menu 的本地化字符串。
- ///
- public static string ShouldUseSecondLevelMenu {
- get {
- return ResourceManager.GetString("ShouldUseSecondLevelMenu", resourceCulture);
- }
- }
-
- ///
- /// 查找类似 No 的本地化字符串。
- ///
- public static string ShouldUseSecondLevelMenuOffContent {
- get {
- return ResourceManager.GetString("ShouldUseSecondLevelMenuOffContent", resourceCulture);
- }
- }
-
- ///
- /// 查找类似 Yes 的本地化字符串。
- ///
- public static string ShouldUseSecondLevelMenuOnContent {
- get {
- return ResourceManager.GetString("ShouldUseSecondLevelMenuOnContent", resourceCulture);
- }
- }
-
///
/// 查找类似 Custom shell menu 的本地化字符串。
///
diff --git a/WindowsTools/Strings/ShellMenu.en-us.resx b/WindowsTools/Strings/ShellMenu.en-us.resx
index cf0b14c..7439f6b 100644
--- a/WindowsTools/Strings/ShellMenu.en-us.resx
+++ b/WindowsTools/Strings/ShellMenu.en-us.resx
@@ -153,21 +153,12 @@
Drive
-
- Edit
-
-
- There's no menu items
-
-
- The content of the secondary menu is empty
+
+ Edit menu
Extension name
-
- First level menu
-
Icon file(*.ico)|*.ico
@@ -204,9 +195,6 @@
Menu list
-
- Menu order
-
Menu parameter
@@ -219,9 +207,6 @@
The application path is not set
-
- Menu program path:
-
Menu settings
@@ -252,9 +237,6 @@
None
-
- Operation
-
Precautions
@@ -288,9 +270,6 @@
Save
-
- Second level menu
-
Select icon
@@ -318,15 +297,6 @@
Yes
-
- Should use second level menu
-
-
- No
-
-
- Yes
-
Custom shell menu
diff --git a/WindowsTools/Strings/ShellMenu.resx b/WindowsTools/Strings/ShellMenu.resx
index cf0b14c..7439f6b 100644
--- a/WindowsTools/Strings/ShellMenu.resx
+++ b/WindowsTools/Strings/ShellMenu.resx
@@ -153,21 +153,12 @@
Drive
-
- Edit
-
-
- There's no menu items
-
-
- The content of the secondary menu is empty
+
+ Edit menu
Extension name
-
- First level menu
-
Icon file(*.ico)|*.ico
@@ -204,9 +195,6 @@
Menu list
-
- Menu order
-
Menu parameter
@@ -219,9 +207,6 @@
The application path is not set
-
- Menu program path:
-
Menu settings
@@ -252,9 +237,6 @@
None
-
- Operation
-
Precautions
@@ -288,9 +270,6 @@
Save
-
- Second level menu
-
Select icon
@@ -318,15 +297,6 @@
Yes
-
- Should use second level menu
-
-
- No
-
-
- Yes
-
Custom shell menu
diff --git a/WindowsTools/Strings/ShellMenu.zh-hans.resx b/WindowsTools/Strings/ShellMenu.zh-hans.resx
index 42970c1..d410f52 100644
--- a/WindowsTools/Strings/ShellMenu.zh-hans.resx
+++ b/WindowsTools/Strings/ShellMenu.zh-hans.resx
@@ -153,21 +153,15 @@
驱动器
-
- 编辑
+
+ 编辑菜单
菜单没有任何内容
-
- 二级菜单内容为空
-
扩展名称
-
- 一级菜单
-
图标文件(*.ico)|*.ico
@@ -204,9 +198,6 @@
菜单列表
-
- 菜单顺序
-
菜单参数
@@ -219,9 +210,6 @@
未设置应用程序路径
-
- 菜单程序文件路径:
-
菜单设置
@@ -252,9 +240,6 @@
不匹配
-
- 操作
-
注意事项
@@ -288,9 +273,6 @@
保存
-
- 二级菜单
-
选择图标
@@ -318,15 +300,6 @@
是
-
- 是否启用二级菜单
-
-
- 否
-
-
- 是
-
自定义扩展菜单
diff --git a/WindowsTools/UI/Backdrop/DesktopAcrylicBackdrop.cs b/WindowsTools/UI/Backdrop/DesktopAcrylicBackdrop.cs
index 3858a4e..c732b61 100644
--- a/WindowsTools/UI/Backdrop/DesktopAcrylicBackdrop.cs
+++ b/WindowsTools/UI/Backdrop/DesktopAcrylicBackdrop.cs
@@ -2,6 +2,7 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
+using System.Threading;
using System.Windows.Forms;
using Windows.UI;
using Windows.UI.Composition;
@@ -33,6 +34,7 @@ public class DesktopAcrylicBackdrop : SystemBackdrop
private readonly Form formRoot;
private readonly FrameworkElement rootElement;
private readonly CompositionCapabilities compositionCapabilities = CompositionCapabilities.GetForCurrentView();
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly float defaultDesktopAcrylicDefaultLightTintOpacity = 0;
private readonly float defaultDesktopAcrylicDefaultLightLuminosityOpacity = 0.85f;
@@ -478,7 +480,10 @@ public override void Dispose()
///
private void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventArgs args)
{
- formRoot.BeginInvoke(UpdateBrush);
+ synchronizationContext.Post(_ =>
+ {
+ UpdateBrush();
+ }, null);
}
///
@@ -486,14 +491,14 @@ private void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventAr
///
private void OnSizeChanged(object sender, EventArgs args)
{
- formRoot.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
SpriteVisual spriteVisual = DesktopWindowTarget.Root as SpriteVisual;
if (spriteVisual is not null)
{
spriteVisual.Size = new Vector2(formRoot.Width, formRoot.Height);
}
- });
+ }, null);
}
///
@@ -501,14 +506,14 @@ private void OnSizeChanged(object sender, EventArgs args)
///
private void OnDpiChanged(object sender, DpiChangedEventArgs args)
{
- formRoot.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
SpriteVisual spriteVisual = DesktopWindowTarget.Root as SpriteVisual;
if (spriteVisual is not null)
{
spriteVisual.Size = new Vector2(formRoot.Width, formRoot.Height);
}
- });
+ }, null);
}
///
@@ -546,7 +551,10 @@ private void OnDeactivated(object sender, EventArgs args)
///
private void OnCompositionCapabilitiesChanged(CompositionCapabilities sender, object args)
{
- formRoot.BeginInvoke(UpdateBrush);
+ synchronizationContext.Post(_ =>
+ {
+ UpdateBrush();
+ }, null);
}
///
@@ -808,10 +816,10 @@ private IntPtr OnFormSubClassProc(IntPtr hWnd, WindowMessage Msg, UIntPtr wParam
if (isInitialized)
{
- formRoot.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
UpdateBrush();
- });
+ }, null);
}
}
}
diff --git a/WindowsTools/UI/Backdrop/MicaBackdrop.cs b/WindowsTools/UI/Backdrop/MicaBackdrop.cs
index 218d0f3..04b45e7 100644
--- a/WindowsTools/UI/Backdrop/MicaBackdrop.cs
+++ b/WindowsTools/UI/Backdrop/MicaBackdrop.cs
@@ -2,6 +2,7 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
+using System.Threading;
using System.Windows.Forms;
using Windows.UI;
using Windows.UI.Composition;
@@ -32,6 +33,7 @@ public class MicaBackdrop : SystemBackdrop
private readonly Form formRoot;
private readonly FrameworkElement rootElement;
private readonly CompositionCapabilities compositionCapabilities = CompositionCapabilities.GetForCurrentView();
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly float defaultMicaBaseLightTintOpacity = 0.5f;
private readonly float defaultMicaBaseLightLuminosityOpacity = 1;
@@ -397,7 +399,10 @@ public override void Dispose()
///
private void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventArgs args)
{
- formRoot.BeginInvoke(UpdateBrush);
+ synchronizationContext.Post(_ =>
+ {
+ UpdateBrush();
+ }, null);
}
///
@@ -405,14 +410,14 @@ private void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventAr
///
private void OnSizeChanged(object sender, EventArgs args)
{
- formRoot.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
SpriteVisual spriteVisual = DesktopWindowTarget.Root as SpriteVisual;
if (spriteVisual is not null)
{
spriteVisual.Size = new Vector2(formRoot.Width, formRoot.Height);
}
- });
+ }, null);
}
///
@@ -420,14 +425,14 @@ private void OnSizeChanged(object sender, EventArgs args)
///
private void OnDpiChanged(object sender, DpiChangedEventArgs args)
{
- formRoot.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
SpriteVisual spriteVisual = DesktopWindowTarget.Root as SpriteVisual;
if (spriteVisual is not null)
{
spriteVisual.Size = new Vector2(formRoot.Width, formRoot.Height);
}
- });
+ }, null);
}
///
@@ -465,7 +470,10 @@ private void OnDeactivated(object sender, EventArgs args)
///
private void OnCompositionCapabilitiesChanged(CompositionCapabilities sender, object args)
{
- formRoot.BeginInvoke(UpdateBrush);
+ synchronizationContext.Post(_ =>
+ {
+ UpdateBrush();
+ }, null);
}
///
@@ -674,10 +682,10 @@ private IntPtr OnFormSubClassProc(IntPtr hWnd, WindowMessage Msg, UIntPtr wParam
if (isInitialized)
{
- formRoot.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
UpdateBrush();
- });
+ }, null);
}
}
}
diff --git a/WindowsTools/UI/Controls/FirstLevelMenuEditControl.xaml b/WindowsTools/UI/Controls/FirstLevelMenuEditControl.xaml
deleted file mode 100644
index ce7b5a1..0000000
--- a/WindowsTools/UI/Controls/FirstLevelMenuEditControl.xaml
+++ /dev/null
@@ -1,1082 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/WindowsTools/UI/Controls/FirstLevelMenuEditControl.xaml.cs b/WindowsTools/UI/Controls/FirstLevelMenuEditControl.xaml.cs
deleted file mode 100644
index a6397ef..0000000
--- a/WindowsTools/UI/Controls/FirstLevelMenuEditControl.xaml.cs
+++ /dev/null
@@ -1,681 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.Diagnostics.Tracing;
-using System.Drawing;
-using System.Drawing.Imaging;
-using System.IO;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Input;
-using Windows.UI.Xaml.Media.Imaging;
-using WindowsTools.Models;
-using WindowsTools.Services.Root;
-using WindowsTools.Strings;
-using WindowsTools.WindowsAPI.PInvoke.Shell32;
-
-// 抑制 IDE0060 警告
-#pragma warning disable IDE0060
-
-namespace WindowsTools.UI.Controls
-{
- ///
- /// 一级菜单编辑控件
- ///
- public sealed partial class FirstLevelMenuEditControl : Grid, INotifyPropertyChanged
- {
- private Guid firstLevelMenuGuid = Guid.Empty;
-
- private string _menuTitleText;
-
- public string MenuTitleText
- {
- get { return _menuTitleText; }
-
- set
- {
- if (!Equals(_menuTitleText, value))
- {
- _menuTitleText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuTitleText)));
- }
- }
- }
-
- private bool _shouldUseProgramIcon;
-
- public bool ShouldUseProgramIcon
- {
- get { return _shouldUseProgramIcon; }
-
- set
- {
- if (!Equals(_shouldUseProgramIcon, value))
- {
- _shouldUseProgramIcon = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShouldUseProgramIcon)));
- }
- }
- }
-
- private bool _shouldEnableThemeIcon;
-
- public bool ShouldEnableThemeIcon
- {
- get { return _shouldEnableThemeIcon; }
-
- set
- {
- if (!Equals(_shouldEnableThemeIcon, value))
- {
- _shouldEnableThemeIcon = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShouldEnableThemeIcon)));
- }
- }
- }
-
- private BitmapImage _defaultIconImage = new();
-
- public BitmapImage DefaultIconImage
- {
- get { return _defaultIconImage; }
-
- set
- {
- if (!Equals(_defaultIconImage, value))
- {
- _defaultIconImage = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DefaultIconImage)));
- }
- }
- }
-
- private string _defaultIconPath;
-
- public string DefaultIconPath
- {
- get { return _defaultIconPath; }
-
- set
- {
- if (!Equals(_defaultIconPath, value))
- {
- _defaultIconPath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DefaultIconPath)));
- }
- }
- }
-
- private BitmapImage _lightThemeIconImage = new();
-
- public BitmapImage LightThemeIconImage
- {
- get { return _lightThemeIconImage; }
-
- set
- {
- if (!Equals(_lightThemeIconImage, value))
- {
- _lightThemeIconImage = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LightThemeIconImage)));
- }
- }
- }
-
- private string _lightThemeIconPath;
-
- public string LightThemeIconPath
- {
- get { return _lightThemeIconPath; }
-
- set
- {
- if (!Equals(_lightThemeIconPath, value))
- {
- _lightThemeIconPath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LightThemeIconPath)));
- }
- }
- }
-
- private BitmapImage _darkThemeIconImage = new();
-
- public BitmapImage DarkThemeIconImage
- {
- get { return _darkThemeIconImage; }
-
- set
- {
- if (!Equals(_darkThemeIconImage, value))
- {
- _darkThemeIconImage = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DarkThemeIconImage)));
- }
- }
- }
-
- private string _darkThemeIconPath;
-
- public string DarkThemeIconPath
- {
- get { return _darkThemeIconPath; }
-
- set
- {
- if (!Equals(_darkThemeIconPath, value))
- {
- _darkThemeIconPath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DarkThemeIconPath)));
- }
- }
- }
-
- private string _menuProgramPathText;
-
- public string MenuProgramPathText
- {
- get { return _menuProgramPathText; }
-
- set
- {
- if (!Equals(_menuProgramPathText, value))
- {
- _menuProgramPathText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuProgramPathText)));
- }
- }
- }
-
- private string _menuParameterText;
-
- public string MenuParameterText
- {
- get { return _menuParameterText; }
-
- set
- {
- if (!Equals(_menuParameterText, value))
- {
- _menuParameterText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuParameterText)));
- }
- }
- }
-
- private bool _folderBackgroundMatch;
-
- public bool FolderBackgroundMatch
- {
- get { return _folderBackgroundMatch; }
-
- set
- {
- if (!Equals(_folderBackgroundMatch, value))
- {
- _folderBackgroundMatch = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderBackgroundMatch)));
- }
- }
- }
-
- private bool _folderDesktopMatch;
-
- public bool FolderDesktopMatch
- {
- get { return _folderDesktopMatch; }
-
- set
- {
- if (!Equals(_folderDesktopMatch, value))
- {
- _folderDesktopMatch = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDesktopMatch)));
- }
- }
- }
-
- private bool _folderDirectoryMatch;
-
- public bool FolderDirectoryMatch
- {
- get { return _folderDirectoryMatch; }
-
- set
- {
- if (!Equals(_folderDirectoryMatch, value))
- {
- _folderDirectoryMatch = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDirectoryMatch)));
- }
- }
- }
-
- private bool _folderDriveMatch;
-
- public bool FolderDriveMatch
- {
- get { return _folderDriveMatch; }
-
- set
- {
- if (!Equals(_folderDriveMatch, value))
- {
- _folderDriveMatch = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDriveMatch)));
- }
- }
- }
-
- private DictionaryEntry _selectedFileMatchRule;
-
- public DictionaryEntry SelectedFileMatchRule
- {
- get { return _selectedFileMatchRule; }
-
- set
- {
- if (!Equals(_selectedFileMatchRule, value))
- {
- _selectedFileMatchRule = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedFileMatchRule)));
- }
- }
- }
-
- private bool _needInputMatchFormat;
-
- public bool NeedInputMatchFormat
- {
- get { return _needInputMatchFormat; }
-
- set
- {
- if (!Equals(_needInputMatchFormat, value))
- {
- _needInputMatchFormat = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NeedInputMatchFormat)));
- }
- }
- }
-
- private string _menuFileMatchFormatPHText;
-
- public string MenuFileMatchFormatPHText
- {
- get { return _menuFileMatchFormatPHText; }
-
- set
- {
- if (!Equals(_menuFileMatchFormatPHText, value))
- {
- _menuFileMatchFormatPHText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuFileMatchFormatPHText)));
- }
- }
- }
-
- private string _menuFileMatchFormatText;
-
- public string MenuFileMatchFormatText
- {
- get { return _menuFileMatchFormatText; }
-
- set
- {
- if (!Equals(_menuFileMatchFormatText, value))
- {
- _menuFileMatchFormatText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuFileMatchFormatText)));
- }
- }
- }
-
- private bool _shouldUseSecondLevelMenu;
-
- public bool ShouldUseSecondLevelMenu
- {
- get { return _shouldUseSecondLevelMenu; }
-
- set
- {
- if (!Equals(_shouldUseSecondLevelMenu, value))
- {
- _shouldUseSecondLevelMenu = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShouldUseSecondLevelMenu)));
- }
- }
- }
-
- private List FileMatchRuleList { get; } =
- [
- new DictionaryEntry(ShellMenu.None,"None"),
- new DictionaryEntry(ShellMenu.Name,"Name"),
- new DictionaryEntry(ShellMenu.NameRegex,"NameRegex"),
- new DictionaryEntry(ShellMenu.Extension,"Extension"),
- new DictionaryEntry(ShellMenu.All,"All")
- ];
-
- private ObservableCollection MenuOrderCollection { get; } = [];
-
- private ObservableCollection SecondLevelMenuCollection { get; } = [];
-
- public event PropertyChangedEventHandler PropertyChanged;
-
- public FirstLevelMenuEditControl()
- {
- InitializeComponent();
- ShouldUseProgramIcon = false;
- SelectedFileMatchRule = FileMatchRuleList[0];
-
- MenuOrderCollection.Add(new ShellMenuItemModel()
- {
- Title = "Windows 工具箱",
- MenuIndex = 0,
- ProgramPath = System.Windows.Forms.Application.ExecutablePath,
- });
- }
-
- #region 第二部分:XamlUICommand 命令调用时挂载的事件
-
- ///
- /// 菜单顺序上移
- ///
- private void OnMoveUpExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
- {
- int menuIndex = Convert.ToInt32(args.Parameter);
- }
-
- ///
- /// 菜单顺序下移
- ///
- private void OnMoveDownExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
- {
- int menuIndex = Convert.ToInt32(args.Parameter);
- }
-
- ///
- /// 编辑菜单项
- ///
- private void OnEditExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
- {
- int menuIndex = Convert.ToInt32(args.Parameter);
-
- //if (BreadCollection.Count is 2)
- //{
- // BreadCollection.Add(new DictionaryEntry(ShellMenu.SecondLevelMenu, "SecondLevelMenu"));
- //}
- }
-
- ///
- /// 定位菜单项
- ///
- private void OnOpenProgramPathRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
- {
- string filePath = args.Parameter as string;
-
- if (!string.IsNullOrEmpty(filePath))
- {
- Task.Run(() =>
- {
- if (!string.IsNullOrEmpty(filePath))
- {
- if (File.Exists(filePath))
- {
- IntPtr pidlList = Shell32Library.ILCreateFromPath(filePath);
- if (pidlList != IntPtr.Zero)
- {
- Shell32Library.SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0);
- Shell32Library.ILFree(pidlList);
- }
- }
- else
- {
- string directoryPath = Path.GetDirectoryName(filePath);
-
- if (Directory.Exists(directoryPath))
- {
- Process.Start(directoryPath);
- }
- else
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
- }
- }
- }
- });
- }
- }
-
- #endregion 第二部分:XamlUICommand 命令调用时挂载的事件
-
- ///
- /// 菜单标题内容发生更改时的事件
- ///
- private void OnTitleTextChanged(object sender, TextChangedEventArgs args)
- {
- MenuTitleText = (sender as Windows.UI.Xaml.Controls.TextBox).Text;
- }
-
- ///
- /// 是否启用主题图标按钮修改时触发的事件
- ///
- private void OnShouldEnableThemeIconToggled(object sender, RoutedEventArgs args)
- {
- ToggleSwitch toggleSwitch = sender as ToggleSwitch;
-
- if (toggleSwitch is not null)
- {
- ShouldEnableThemeIcon = toggleSwitch.IsOn;
- }
- }
-
- ///
- /// 是否使用应用程序图标修改时触发的事件
- ///
- private void OnShouldUseProgramIconToggled(object sender, RoutedEventArgs args)
- {
- ToggleSwitch toggleSwitch = sender as ToggleSwitch;
-
- if (toggleSwitch is not null)
- {
- ShouldUseProgramIcon = toggleSwitch.IsOn;
- }
- }
-
- ///
- /// 默认图标修改
- ///
- private void OnDefaultIconModifyClicked(object sender, RoutedEventArgs args)
- {
- OpenFileDialog dialog = new()
- {
- Multiselect = false,
- Filter = ShellMenu.IconFilterCondition,
- Title = ShellMenu.SelectIcon
- };
- if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
- {
- try
- {
- DefaultIconPath = dialog.FileName;
- Icon icon = Icon.ExtractAssociatedIcon(dialog.FileName);
- MemoryStream memoryStream = new();
- icon.ToBitmap().Save(memoryStream, ImageFormat.Png);
- memoryStream.Seek(0, SeekOrigin.Begin);
- DefaultIconImage.SetSource(memoryStream.AsRandomAccessStream());
- memoryStream.Dispose();
- }
- catch (Exception e)
- {
- LogService.WriteLog(EventLevel.Error, "Set Default icon failed", e);
- }
- }
- }
-
- ///
- /// 浅色主题图标修改
- ///
- private void OnLightThemeIconModifyClicked(object sender, RoutedEventArgs args)
- {
- OpenFileDialog dialog = new()
- {
- Multiselect = false,
- Filter = ShellMenu.IconFilterCondition,
- Title = ShellMenu.SelectIcon
- };
- if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
- {
- try
- {
- LightThemeIconPath = dialog.FileName;
- Icon icon = Icon.ExtractAssociatedIcon(dialog.FileName);
- MemoryStream memoryStream = new();
- icon.ToBitmap().Save(memoryStream, ImageFormat.Png);
- memoryStream.Seek(0, SeekOrigin.Begin);
- LightThemeIconImage.SetSource(memoryStream.AsRandomAccessStream());
- memoryStream.Dispose();
- }
- catch (Exception e)
- {
- LogService.WriteLog(EventLevel.Error, "Set light theme icon failed", e);
- }
- }
- }
-
- ///
- /// 深色主题图标修改
- ///
- private void OnDarkThemeIconModifyClicked(object sender, RoutedEventArgs args)
- {
- OpenFileDialog dialog = new()
- {
- Multiselect = false,
- Filter = ShellMenu.IconFilterCondition,
- Title = ShellMenu.SelectIcon
- };
- if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
- {
- try
- {
- DarkThemeIconPath = dialog.FileName;
- Icon icon = Icon.ExtractAssociatedIcon(dialog.FileName);
- MemoryStream memoryStream = new();
- icon.ToBitmap().Save(memoryStream, ImageFormat.Png);
- memoryStream.Seek(0, SeekOrigin.Begin);
- DarkThemeIconImage.SetSource(memoryStream.AsRandomAccessStream());
- memoryStream.Dispose();
- }
- catch (Exception e)
- {
- LogService.WriteLog(EventLevel.Error, "Set dark theme icon failed", e);
- }
- }
- }
-
- ///
- /// 修改菜单程序文件路径
- ///
- private void OnMenuProgramPathModifyClicked(object sender, RoutedEventArgs args)
- {
- OpenFileDialog dialog = new()
- {
- Multiselect = false,
- Filter = ShellMenu.ProgramFilterCondition,
- Title = ShellMenu.SelectProgram
- };
- if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
- {
- MenuProgramPathText = dialog.FileName;
- }
- }
-
- ///
- /// 菜单参数内容发生更改时的事件
- ///
- private void OnMenuParameterTextChanged(object sender, TextChangedEventArgs args)
- {
- MenuParameterText = (sender as Windows.UI.Xaml.Controls.TextBox).Text;
- }
-
- ///
- /// 修改菜单文件匹配规则
- ///
- private void OnFileMatchRuleClicked(object sender, RoutedEventArgs args)
- {
- ToggleMenuFlyoutItem item = sender as ToggleMenuFlyoutItem;
- if (item.Tag is not null)
- {
- SelectedFileMatchRule = FileMatchRuleList[Convert.ToInt32(item.Tag)];
- NeedInputMatchFormat = SelectedFileMatchRule.Equals(FileMatchRuleList[1]) || SelectedFileMatchRule.Equals(FileMatchRuleList[2]) || SelectedFileMatchRule.Equals(FileMatchRuleList[3]);
-
- if (SelectedFileMatchRule.Equals(FileMatchRuleList[0]) || SelectedFileMatchRule.Equals(4))
- {
- NeedInputMatchFormat = false;
- MenuFileMatchFormatPHText = string.Empty;
- }
- else if (SelectedFileMatchRule.Equals(FileMatchRuleList[1]))
- {
- NeedInputMatchFormat = true;
- MenuFileMatchFormatPHText = ShellMenu.MenuFileNameFormat;
- }
- else if (SelectedFileMatchRule.Equals(FileMatchRuleList[2]))
- {
- NeedInputMatchFormat = true;
- MenuFileMatchFormatPHText = ShellMenu.MenuFileNameRegexFormat;
- }
- else if (SelectedFileMatchRule.Equals(FileMatchRuleList[3]))
- {
- NeedInputMatchFormat = true;
- MenuFileMatchFormatPHText = ShellMenu.MenuFileExtensionFormat;
- }
- }
- }
-
- ///
- /// 菜单文件匹配格式内容发生更改时的事件
- ///
- private void OnMenuFileMatchFormatTextChanged(object sender, TextChangedEventArgs args)
- {
- MenuFileMatchFormatText = (sender as Windows.UI.Xaml.Controls.TextBox).Text;
- }
-
- ///
- /// 是否启用二级菜单
- ///
- private void OnShouldUseSecondLevelMenuToggled(object sender, RoutedEventArgs args)
- {
- ToggleSwitch toggleSwitch = sender as ToggleSwitch;
-
- if (toggleSwitch is not null)
- {
- ShouldUseSecondLevelMenu = toggleSwitch.IsOn;
- }
- }
-
- ///
- /// 添加菜单
- ///
- private void OnAddMenuClicked(object sender, RoutedEventArgs args)
- {
- }
-
- ///
- /// 清空菜单项
- ///
- private void OnClearMenuClicked(object sender, RoutedEventArgs args)
- {
- }
-
- ///
- /// 刷新列表
- ///
- private void OnRefreshClicked(object sender, RoutedEventArgs args)
- {
- }
- }
-}
diff --git a/WindowsTools/UI/Controls/SecondLevelMenuEditControl.xaml b/WindowsTools/UI/Controls/SecondLevelMenuEditControl.xaml
deleted file mode 100644
index e6a40cd..0000000
--- a/WindowsTools/UI/Controls/SecondLevelMenuEditControl.xaml
+++ /dev/null
@@ -1,779 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/WindowsTools/UI/Controls/SecondLevelMenuEditControl.xaml.cs b/WindowsTools/UI/Controls/SecondLevelMenuEditControl.xaml.cs
deleted file mode 100644
index 0efc198..0000000
--- a/WindowsTools/UI/Controls/SecondLevelMenuEditControl.xaml.cs
+++ /dev/null
@@ -1,573 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.Diagnostics.Tracing;
-using System.Drawing;
-using System.Drawing.Imaging;
-using System.IO;
-using System.Windows.Forms;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Input;
-using Windows.UI.Xaml.Media.Imaging;
-using WindowsTools.Models;
-using WindowsTools.Services.Root;
-using WindowsTools.Strings;
-
-// 抑制 IDE0060 警告
-#pragma warning disable IDE0060
-
-namespace WindowsTools.UI.Controls
-{
- ///
- /// 二级菜单编辑控件
- ///
- public sealed partial class SecondLevelMenuEditControl : Grid, INotifyPropertyChanged
- {
- private Guid firstLevelMenuGuid = Guid.Empty;
-
- private string _menuTitleText;
-
- public string MenuTitleText
- {
- get { return _menuTitleText; }
-
- set
- {
- if (!Equals(_menuTitleText, value))
- {
- _menuTitleText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuTitleText)));
- }
- }
- }
-
- private bool _shouldUseProgramIcon;
-
- public bool ShouldUseProgramIcon
- {
- get { return _shouldUseProgramIcon; }
-
- set
- {
- if (!Equals(_shouldUseProgramIcon, value))
- {
- _shouldUseProgramIcon = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShouldUseProgramIcon)));
- }
- }
- }
-
- private bool _shouldEnableThemeIcon;
-
- public bool ShouldEnableThemeIcon
- {
- get { return _shouldEnableThemeIcon; }
-
- set
- {
- if (!Equals(_shouldEnableThemeIcon, value))
- {
- _shouldEnableThemeIcon = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShouldEnableThemeIcon)));
- }
- }
- }
-
- private BitmapImage _defaultIconImage = new();
-
- public BitmapImage DefaultIconImage
- {
- get { return _defaultIconImage; }
-
- set
- {
- if (!Equals(_defaultIconImage, value))
- {
- _defaultIconImage = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DefaultIconImage)));
- }
- }
- }
-
- private string _defaultIconPath;
-
- public string DefaultIconPath
- {
- get { return _defaultIconPath; }
-
- set
- {
- if (!Equals(_defaultIconPath, value))
- {
- _defaultIconPath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DefaultIconPath)));
- }
- }
- }
-
- private BitmapImage _lightThemeIconImage = new();
-
- public BitmapImage LightThemeIconImage
- {
- get { return _lightThemeIconImage; }
-
- set
- {
- if (!Equals(_lightThemeIconImage, value))
- {
- _lightThemeIconImage = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LightThemeIconImage)));
- }
- }
- }
-
- private string _lightThemeIconPath;
-
- public string LightThemeIconPath
- {
- get { return _lightThemeIconPath; }
-
- set
- {
- if (!Equals(_lightThemeIconPath, value))
- {
- _lightThemeIconPath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LightThemeIconPath)));
- }
- }
- }
-
- private BitmapImage _darkThemeIconImage = new();
-
- public BitmapImage DarkThemeIconImage
- {
- get { return _darkThemeIconImage; }
-
- set
- {
- if (!Equals(_darkThemeIconImage, value))
- {
- _darkThemeIconImage = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DarkThemeIconImage)));
- }
- }
- }
-
- private string _darkThemeIconPath;
-
- public string DarkThemeIconPath
- {
- get { return _darkThemeIconPath; }
-
- set
- {
- if (!Equals(_darkThemeIconPath, value))
- {
- _darkThemeIconPath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DarkThemeIconPath)));
- }
- }
- }
-
- private string _menuProgramPathText;
-
- public string MenuProgramPathText
- {
- get { return _menuProgramPathText; }
-
- set
- {
- if (!Equals(_menuProgramPathText, value))
- {
- _menuProgramPathText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuProgramPathText)));
- }
- }
- }
-
- private string _menuParameterText;
-
- public string MenuParameterText
- {
- get { return _menuParameterText; }
-
- set
- {
- if (!Equals(_menuParameterText, value))
- {
- _menuParameterText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuParameterText)));
- }
- }
- }
-
- private bool _folderBackgroundMatch;
-
- public bool FolderBackgroundMatch
- {
- get { return _folderBackgroundMatch; }
-
- set
- {
- if (!Equals(_folderBackgroundMatch, value))
- {
- _folderBackgroundMatch = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderBackgroundMatch)));
- }
- }
- }
-
- private bool _folderDesktopMatch;
-
- public bool FolderDesktopMatch
- {
- get { return _folderDesktopMatch; }
-
- set
- {
- if (!Equals(_folderDesktopMatch, value))
- {
- _folderDesktopMatch = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDesktopMatch)));
- }
- }
- }
-
- private bool _folderDirectoryMatch;
-
- public bool FolderDirectoryMatch
- {
- get { return _folderDirectoryMatch; }
-
- set
- {
- if (!Equals(_folderDirectoryMatch, value))
- {
- _folderDirectoryMatch = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDirectoryMatch)));
- }
- }
- }
-
- private bool _folderDriveMatch;
-
- public bool FolderDriveMatch
- {
- get { return _folderDriveMatch; }
-
- set
- {
- if (!Equals(_folderDriveMatch, value))
- {
- _folderDriveMatch = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDriveMatch)));
- }
- }
- }
-
- private DictionaryEntry _selectedFileMatchRule;
-
- public DictionaryEntry SelectedFileMatchRule
- {
- get { return _selectedFileMatchRule; }
-
- set
- {
- if (!Equals(_selectedFileMatchRule, value))
- {
- _selectedFileMatchRule = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedFileMatchRule)));
- }
- }
- }
-
- private bool _needInputMatchFormat;
-
- public bool NeedInputMatchFormat
- {
- get { return _needInputMatchFormat; }
-
- set
- {
- if (!Equals(_needInputMatchFormat, value))
- {
- _needInputMatchFormat = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NeedInputMatchFormat)));
- }
- }
- }
-
- private string _menuFileMatchFormatPHText;
-
- public string MenuFileMatchFormatPHText
- {
- get { return _menuFileMatchFormatPHText; }
-
- set
- {
- if (!Equals(_menuFileMatchFormatPHText, value))
- {
- _menuFileMatchFormatPHText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuFileMatchFormatPHText)));
- }
- }
- }
-
- private string _menuFileMatchFormatText;
-
- public string MenuFileMatchFormatText
- {
- get { return _menuFileMatchFormatText; }
-
- set
- {
- if (!Equals(_menuFileMatchFormatText, value))
- {
- _menuFileMatchFormatText = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuFileMatchFormatText)));
- }
- }
- }
-
- private List FileMatchRuleList { get; } =
- [
- new DictionaryEntry(ShellMenu.None,"None"),
- new DictionaryEntry(ShellMenu.Name,"Name"),
- new DictionaryEntry(ShellMenu.NameRegex,"NameRegex"),
- new DictionaryEntry(ShellMenu.Extension,"Extension"),
- new DictionaryEntry(ShellMenu.All,"All")
- ];
-
- private ObservableCollection MenuOrderCollection { get; } = [];
-
- public event PropertyChangedEventHandler PropertyChanged;
-
- public SecondLevelMenuEditControl()
- {
- InitializeComponent();
- ShouldUseProgramIcon = false;
- SelectedFileMatchRule = FileMatchRuleList[0];
-
- MenuOrderCollection.Add(new ShellMenuItemModel()
- {
- Title = "Windows 工具箱",
- MenuIndex = 0,
- ProgramPath = System.Windows.Forms.Application.ExecutablePath,
- });
- }
-
- #region 第二部分:XamlUICommand 命令调用时挂载的事件
-
- ///
- /// 菜单顺序上移
- ///
- private void OnMoveUpExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
- {
- int menuIndex = Convert.ToInt32(args.Parameter);
- }
-
- ///
- /// 菜单顺序下移
- ///
- private void OnMoveDownExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
- {
- int menuIndex = Convert.ToInt32(args.Parameter);
- }
-
- #endregion 第二部分:XamlUICommand 命令调用时挂载的事件
-
- ///
- /// 菜单标题内容发生更改时的事件
- ///
- private void OnTitleTextChanged(object sender, TextChangedEventArgs args)
- {
- MenuTitleText = (sender as Windows.UI.Xaml.Controls.TextBox).Text;
- }
-
- ///
- /// 是否启用主题图标按钮修改时触发的事件
- ///
- private void OnShouldEnableThemeIconToggled(object sender, RoutedEventArgs args)
- {
- ToggleSwitch toggleSwitch = sender as ToggleSwitch;
-
- if (toggleSwitch is not null)
- {
- ShouldEnableThemeIcon = toggleSwitch.IsOn;
- }
- }
-
- ///
- /// 是否使用应用程序图标修改时触发的事件
- ///
- private void OnShouldUseProgramIconToggled(object sender, RoutedEventArgs args)
- {
- ToggleSwitch toggleSwitch = sender as ToggleSwitch;
-
- if (toggleSwitch is not null)
- {
- ShouldUseProgramIcon = toggleSwitch.IsOn;
- }
- }
-
- ///
- /// 默认图标修改
- ///
- private void OnDefaultIconModifyClicked(object sender, RoutedEventArgs args)
- {
- OpenFileDialog dialog = new()
- {
- Multiselect = false,
- Filter = ShellMenu.IconFilterCondition,
- Title = ShellMenu.SelectIcon
- };
- if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
- {
- try
- {
- DefaultIconPath = dialog.FileName;
- Icon icon = Icon.ExtractAssociatedIcon(dialog.FileName);
- MemoryStream memoryStream = new();
- icon.ToBitmap().Save(memoryStream, ImageFormat.Png);
- memoryStream.Seek(0, SeekOrigin.Begin);
- DefaultIconImage.SetSource(memoryStream.AsRandomAccessStream());
- memoryStream.Dispose();
- }
- catch (Exception e)
- {
- LogService.WriteLog(EventLevel.Error, "Set Default icon failed", e);
- }
- }
- }
-
- ///
- /// 浅色主题图标修改
- ///
- private void OnLightThemeIconModifyClicked(object sender, RoutedEventArgs args)
- {
- OpenFileDialog dialog = new()
- {
- Multiselect = false,
- Filter = ShellMenu.IconFilterCondition,
- Title = ShellMenu.SelectIcon
- };
- if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
- {
- try
- {
- LightThemeIconPath = dialog.FileName;
- Icon icon = Icon.ExtractAssociatedIcon(dialog.FileName);
- MemoryStream memoryStream = new();
- icon.ToBitmap().Save(memoryStream, ImageFormat.Png);
- memoryStream.Seek(0, SeekOrigin.Begin);
- LightThemeIconImage.SetSource(memoryStream.AsRandomAccessStream());
- memoryStream.Dispose();
- }
- catch (Exception e)
- {
- LogService.WriteLog(EventLevel.Error, "Set light theme icon failed", e);
- }
- }
- }
-
- ///
- /// 深色主题图标修改
- ///
- private void OnDarkThemeIconModifyClicked(object sender, RoutedEventArgs args)
- {
- OpenFileDialog dialog = new()
- {
- Multiselect = false,
- Filter = ShellMenu.IconFilterCondition,
- Title = ShellMenu.SelectIcon
- };
- if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
- {
- try
- {
- DarkThemeIconPath = dialog.FileName;
- Icon icon = Icon.ExtractAssociatedIcon(dialog.FileName);
- MemoryStream memoryStream = new();
- icon.ToBitmap().Save(memoryStream, ImageFormat.Png);
- memoryStream.Seek(0, SeekOrigin.Begin);
- DarkThemeIconImage.SetSource(memoryStream.AsRandomAccessStream());
- memoryStream.Dispose();
- }
- catch (Exception e)
- {
- LogService.WriteLog(EventLevel.Error, "Set dark theme icon failed", e);
- }
- }
- }
-
- ///
- /// 修改菜单程序文件路径
- ///
- private void OnMenuProgramPathModifyClicked(object sender, RoutedEventArgs args)
- {
- OpenFileDialog dialog = new()
- {
- Multiselect = false,
- Filter = ShellMenu.ProgramFilterCondition,
- Title = ShellMenu.SelectProgram
- };
- if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
- {
- MenuProgramPathText = dialog.FileName;
- }
- }
-
- ///
- /// 菜单参数内容发生更改时的事件
- ///
- private void OnMenuParameterTextChanged(object sender, TextChangedEventArgs args)
- {
- MenuParameterText = (sender as Windows.UI.Xaml.Controls.TextBox).Text;
- }
-
- ///
- /// 修改菜单文件匹配规则
- ///
- private void OnFileMatchRuleClicked(object sender, RoutedEventArgs args)
- {
- ToggleMenuFlyoutItem item = sender as ToggleMenuFlyoutItem;
- if (item.Tag is not null)
- {
- SelectedFileMatchRule = FileMatchRuleList[Convert.ToInt32(item.Tag)];
- NeedInputMatchFormat = SelectedFileMatchRule.Equals(FileMatchRuleList[1]) || SelectedFileMatchRule.Equals(FileMatchRuleList[2]) || SelectedFileMatchRule.Equals(FileMatchRuleList[3]);
-
- if (SelectedFileMatchRule.Equals(FileMatchRuleList[0]) || SelectedFileMatchRule.Equals(4))
- {
- NeedInputMatchFormat = false;
- MenuFileMatchFormatPHText = string.Empty;
- }
- else if (SelectedFileMatchRule.Equals(FileMatchRuleList[1]))
- {
- NeedInputMatchFormat = true;
- MenuFileMatchFormatPHText = ShellMenu.MenuFileNameFormat;
- }
- else if (SelectedFileMatchRule.Equals(FileMatchRuleList[2]))
- {
- NeedInputMatchFormat = true;
- MenuFileMatchFormatPHText = ShellMenu.MenuFileNameRegexFormat;
- }
- else if (SelectedFileMatchRule.Equals(FileMatchRuleList[3]))
- {
- NeedInputMatchFormat = true;
- MenuFileMatchFormatPHText = ShellMenu.MenuFileExtensionFormat;
- }
- }
- }
-
- ///
- /// 菜单文件匹配格式内容发生更改时的事件
- ///
- private void OnMenuFileMatchFormatTextChanged(object sender, TextChangedEventArgs args)
- {
- MenuFileMatchFormatText = (sender as Windows.UI.Xaml.Controls.TextBox).Text;
- }
- }
-}
diff --git a/WindowsTools/UI/Dialogs/AppInformationDialog.xaml b/WindowsTools/UI/Dialogs/AppInformationDialog.xaml
index 1a078b2..c5abb90 100644
--- a/WindowsTools/UI/Dialogs/AppInformationDialog.xaml
+++ b/WindowsTools/UI/Dialogs/AppInformationDialog.xaml
@@ -8,7 +8,6 @@
Title="{x:Bind string:Dialog.AppInformationTitle}"
BorderBrush="{ThemeResource ContentDialogBorderThemeBrush}"
CloseButtonText="{x:Bind string:Dialog.CloseDialog}"
- Loaded="{x:Bind OnLoaded}"
PrimaryButtonClick="{x:Bind OnCopyAppInformationClicked}"
PrimaryButtonStyle="{ThemeResource AccentButtonStyle}"
PrimaryButtonText="{x:Bind string:Dialog.CopyAppInformation}"
diff --git a/WindowsTools/UI/Dialogs/AppInformationDialog.xaml.cs b/WindowsTools/UI/Dialogs/AppInformationDialog.xaml.cs
index 651febf..3f90af8 100644
--- a/WindowsTools/UI/Dialogs/AppInformationDialog.xaml.cs
+++ b/WindowsTools/UI/Dialogs/AppInformationDialog.xaml.cs
@@ -5,16 +5,15 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel;
-using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using WindowsTools.Extensions.DataType.Enums;
using WindowsTools.Helpers.Controls.Extensions;
using WindowsTools.Helpers.Root;
using WindowsTools.Strings;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
// 抑制 IDE0060 警告
#pragma warning disable IDE0060
@@ -26,6 +25,8 @@ namespace WindowsTools.UI.Dialogs.About
///
public sealed partial class AppInformationDialog : ContentDialog, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+
private string _windowsAppSDKVersion;
public string WindowsAppSDKVersion
@@ -111,13 +112,7 @@ public string DoNetVersion
public AppInformationDialog()
{
InitializeComponent();
- }
- ///
- /// 初始化应用信息
- ///
- private void OnLoaded(object sender, RoutedEventArgs args)
- {
Task.Run(() =>
{
IReadOnlyList dependencyList = Package.Current.Dependencies;
@@ -127,14 +122,14 @@ private void OnLoaded(object sender, RoutedEventArgs args)
if (dependency.DisplayName.Contains("WindowsAppRuntime"))
{
// Windows 应用 SDK 版本信息
- MainWindow.Current.Invoke(() =>
+ synchronizationContext.Post(_ =>
{
WindowsAppSDKVersion = string.Format("{0}.{1}.{2}.{3}",
dependency.Id.Version.Major,
dependency.Id.Version.Minor,
dependency.Id.Version.Build,
dependency.Id.Version.Revision);
- });
+ }, null);
}
// WinUI 2 版本信息
@@ -142,14 +137,14 @@ private void OnLoaded(object sender, RoutedEventArgs args)
{
FileVersionInfo winUI2File = FileVersionInfo.GetVersionInfo(Path.Combine(dependency.InstalledPath, "Microsoft.UI.Xaml.dll"));
- MainWindow.Current.Invoke(() =>
+ synchronizationContext.Post(_ =>
{
WinUI2Version = string.Format("{0}.{1}.{2}.{3}",
winUI2File.ProductMajorPart,
winUI2File.ProductMinorPart,
winUI2File.ProductBuildPart,
winUI2File.ProductPrivatePart);
- });
+ }, null);
}
}
@@ -157,7 +152,7 @@ private void OnLoaded(object sender, RoutedEventArgs args)
FileVersionInfo mileXamlFile = FileVersionInfo.GetVersionInfo(Path.Combine(AppContext.BaseDirectory, @"Mile.Xaml.Managed.dll"));
- MainWindow.Current.Invoke(() =>
+ synchronizationContext.Post(_ =>
{
WindowsUIVersion = string.Format("{0}.{1}.{2}.{3}",
windowsUIFile.ProductMajorPart,
@@ -170,7 +165,7 @@ private void OnLoaded(object sender, RoutedEventArgs args)
// .NET 版本信息
DoNetVersion = Convert.ToString(RuntimeInformation.FrameworkDescription.Remove(0, 15));
- });
+ }, null);
});
}
diff --git a/WindowsTools/UI/Dialogs/FileCheckDialog.xaml.cs b/WindowsTools/UI/Dialogs/FileCheckDialog.xaml.cs
index 5fbc7bf..dad5557 100644
--- a/WindowsTools/UI/Dialogs/FileCheckDialog.xaml.cs
+++ b/WindowsTools/UI/Dialogs/FileCheckDialog.xaml.cs
@@ -1,13 +1,13 @@
using System;
using System.Diagnostics;
using System.IO;
+using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using WindowsTools.Extensions.DataType.Enums;
using WindowsTools.Helpers.Controls.Extensions;
using WindowsTools.Services.Controls.Download;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
// 抑制 IDE0060 警告
#pragma warning disable IDE0060
@@ -21,6 +21,7 @@ public sealed partial class FileCheckDialog : ContentDialog
{
private readonly string downloadUrl;
private readonly string downloadFilePath;
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
public FileCheckDialog(string url, string saveFilePath)
{
@@ -43,10 +44,10 @@ private void OnPrimaryButtonClicked(object sender, ContentDialogButtonClickEvent
}
catch (Exception)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new OperationResultTip(OperationKind.DeleteFileFailed));
- });
+ }, null);
Process.Start(Path.GetDirectoryName(downloadFilePath));
}
});
diff --git a/WindowsTools/UI/Dialogs/RestartAppsDialog.xaml.cs b/WindowsTools/UI/Dialogs/RestartAppsDialog.xaml.cs
index 88c1f59..27ec5af 100644
--- a/WindowsTools/UI/Dialogs/RestartAppsDialog.xaml.cs
+++ b/WindowsTools/UI/Dialogs/RestartAppsDialog.xaml.cs
@@ -1,8 +1,8 @@
using System.Diagnostics;
+using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
-using WindowsTools.Views.Windows;
// 抑制 IDE0060 警告
#pragma warning disable IDE0060
@@ -14,6 +14,8 @@ namespace WindowsTools.UI.Dialogs
///
public sealed partial class RestartAppsDialog : ContentDialog
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+
public RestartAppsDialog()
{
InitializeComponent();
@@ -27,10 +29,10 @@ private void OnRestartAppsClicked(ContentDialog sender, ContentDialogButtonClick
Task.Run(() =>
{
Process.Start(Process.GetCurrentProcess().MainModule.FileName, "Restart");
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
(Application.Current as App).Dispose();
- });
+ }, null);
});
}
}
diff --git a/WindowsTools/Views/Pages/AboutPage.xaml.cs b/WindowsTools/Views/Pages/AboutPage.xaml.cs
index b836d4b..4ad3cd3 100644
--- a/WindowsTools/Views/Pages/AboutPage.xaml.cs
+++ b/WindowsTools/Views/Pages/AboutPage.xaml.cs
@@ -9,6 +9,7 @@
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
+using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Core;
@@ -24,7 +25,6 @@
using WindowsTools.UI.Dialogs;
using WindowsTools.UI.Dialogs.About;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
using WindowsTools.WindowsAPI.ComTypes;
using WindowsTools.WindowsAPI.PInvoke.Kernel32;
@@ -38,6 +38,11 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class AboutPage : Page, INotifyPropertyChanged
{
+ private static Guid taskbarPinCLSID = new("90AA3A4E-1CBA-4233-B8BB-535773D48449");
+ private static Guid ishellLinkCLSID = new("00021401-0000-0000-C000-000000000046");
+
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+
private bool _isChecking;
public bool IsChecking
@@ -54,9 +59,6 @@ public bool IsChecking
}
}
- private static Guid taskbarPinCLSID = new("90AA3A4E-1CBA-4233-B8BB-535773D48449");
- private static Guid ishellLinkCLSID = new("00021401-0000-0000-C000-000000000046");
-
//项目引用信息
private List ReferenceDict { get; } =
[
@@ -112,10 +114,10 @@ private void OnPinToDesktopClicked(object sender, RoutedEventArgs args)
}
finally
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new QuickOperationTip(QuickOperationKind.Desktop, isCreatedSuccessfully));
- });
+ }, null);
}
});
}
@@ -153,10 +155,10 @@ private async void OnPinToStartScreenClicked(object sender, RoutedEventArgs args
}
finally
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new QuickOperationTip(QuickOperationKind.StartScreen, isPinnedSuccessfully));
- });
+ }, null);
}
}
@@ -303,10 +305,10 @@ private void OnCheckUpdateClicked(object sender, RoutedEventArgs args)
{
bool isNewest = InfoHelper.AppVersion >= tagVersion;
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new OperationResultTip(OperationKind.CheckUpdate, isNewest));
- });
+ }, null);
}
}
}
@@ -336,10 +338,10 @@ private void OnCheckUpdateClicked(object sender, RoutedEventArgs args)
}
finally
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsChecking = false;
- });
+ }, null);
}
});
}
diff --git a/WindowsTools/Views/Pages/CodeScannerPage.xaml.cs b/WindowsTools/Views/Pages/CodeScannerPage.xaml.cs
index 17cf557..88219f2 100644
--- a/WindowsTools/Views/Pages/CodeScannerPage.xaml.cs
+++ b/WindowsTools/Views/Pages/CodeScannerPage.xaml.cs
@@ -9,6 +9,7 @@
using System.Drawing.Printing;
using System.IO;
using System.Reflection;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -22,7 +23,6 @@
using WindowsTools.Services.Root;
using WindowsTools.Strings;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
using ZXing;
using ZXing.Common;
using ZXing.QrCode;
@@ -38,6 +38,7 @@ namespace WindowsTools.Views.Pages
public sealed partial class CodeScannerPage : Page, INotifyPropertyChanged
{
private readonly BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Static;
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private PrintPreviewDialog printPreviewDialog;
private PrintDialog printDialog;
private PrintDocument printDocument;
@@ -465,7 +466,7 @@ private void OnGeneratePhotoClicked(object sender, RoutedEventArgs args)
barCodeBitmap.Save(memoryStream, ImageFormat.Png);
memoryStream.Position = 0;
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
try
{
@@ -477,13 +478,10 @@ private void OnGeneratePhotoClicked(object sender, RoutedEventArgs args)
}
catch (Exception e)
{
- MainWindow.Current.BeginInvoke(() =>
- {
- TeachingTipHelper.Show(new OperationResultTip(OperationKind.GenerateBarCodeFailed));
- });
+ TeachingTipHelper.Show(new OperationResultTip(OperationKind.GenerateBarCodeFailed));
LogService.WriteLog(EventLevel.Error, "Display generated bar code photo failed", e);
}
- });
+ }, null);
}
}
// 二维码
@@ -497,7 +495,7 @@ private void OnGeneratePhotoClicked(object sender, RoutedEventArgs args)
qrCodeBitmap.Save(memoryStream, ImageFormat.Png);
memoryStream.Position = 0;
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
try
{
@@ -509,13 +507,10 @@ private void OnGeneratePhotoClicked(object sender, RoutedEventArgs args)
}
catch (Exception e)
{
- MainWindow.Current.BeginInvoke(() =>
- {
- TeachingTipHelper.Show(new OperationResultTip(OperationKind.GenerateQRCodeFailed));
- });
+ TeachingTipHelper.Show(new OperationResultTip(OperationKind.GenerateQRCodeFailed));
LogService.WriteLog(EventLevel.Error, "Display generated qr code photo failed", e);
}
- });
+ }, null);
}
}
});
@@ -752,25 +747,25 @@ public void ParseCodeImage(System.Drawing.Image image)
if (result is not null)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
RecognizeText = result.Text;
- });
+ }, null);
}
else
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new OperationResultTip(OperationKind.ParsePhotoFailed));
- });
+ }, null);
}
}
catch (Exception e)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new OperationResultTip(OperationKind.ParsePhotoFailed));
- });
+ }, null);
LogService.WriteLog(EventLevel.Error, string.Format("Parse code file failed"), e);
}
});
diff --git a/WindowsTools/Views/Pages/DownloadManagerPage.xaml.cs b/WindowsTools/Views/Pages/DownloadManagerPage.xaml.cs
index 3833f8f..584f274 100644
--- a/WindowsTools/Views/Pages/DownloadManagerPage.xaml.cs
+++ b/WindowsTools/Views/Pages/DownloadManagerPage.xaml.cs
@@ -8,6 +8,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -40,6 +41,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class DownloadManagerPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private bool isAllowClosed = false;
private string _searchDownloadText;
@@ -297,7 +299,7 @@ private void OnDeleteWithFileExecuteRequested(XamlUICommand sender, ExecuteReque
}
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (DownloadModel item in DownloadCollection)
{
@@ -307,7 +309,7 @@ private void OnDeleteWithFileExecuteRequested(XamlUICommand sender, ExecuteReque
break;
}
}
- });
+ }, null);
}
});
}
@@ -325,8 +327,7 @@ private void OnShareFileExecuteRequested(XamlUICommand sender, ExecuteRequestedE
{
IDataTransferManagerInterop dataTransferManagerInterop = (IDataTransferManagerInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(DataTransferManager));
- DataTransferManager dataTransferManager = dataTransferManagerInterop.GetForWindow(MainWindow.Current.Handle, new("A5CAEE9B-8708-49D1-8D36-67D25A8DA00C"));
-
+ dataTransferManagerInterop.GetForWindow(MainWindow.Current.Handle, new("A5CAEE9B-8708-49D1-8D36-67D25A8DA00C"), out DataTransferManager dataTransferManager);
dataTransferManager.DataRequested += async (sender, args) =>
{
DataRequestDeferral deferral = args.Request.GetDeferral();
@@ -336,7 +337,7 @@ private void OnShareFileExecuteRequested(XamlUICommand sender, ExecuteRequestedE
deferral.Complete();
};
- dataTransferManagerInterop.ShowShareUIForWindow((IntPtr)MainWindow.Current.Handle);
+ dataTransferManagerInterop.ShowShareUIForWindow(MainWindow.Current.Handle);
}
catch (Exception e)
{
@@ -520,7 +521,7 @@ private void OnDownloadSettingsClicked(object sender, RoutedEventArgs args)
///
private void OnDownloadCreated(Guid downloadID, DownloadSchedulerModel downloadSchedulerItem)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
DownloadCollection.Add(new DownloadModel()
{
@@ -534,7 +535,7 @@ private void OnDownloadCreated(Guid downloadID, DownloadSchedulerModel downloadS
CurrentSpeed = 0,
TotalSize = downloadSchedulerItem.TotalSize
});
- });
+ }, null);
}
///
@@ -542,7 +543,7 @@ private void OnDownloadCreated(Guid downloadID, DownloadSchedulerModel downloadS
///
private void OnDownloadContinued(Guid downloadID)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (DownloadModel downloadItem in DownloadCollection)
{
@@ -552,7 +553,7 @@ private void OnDownloadContinued(Guid downloadID)
downloadItem.DownloadStatus = DownloadStatus.Downloading;
}
}
- });
+ }, null);
}
///
@@ -560,7 +561,7 @@ private void OnDownloadContinued(Guid downloadID)
///
private void OnDownloadPaused(Guid downloadID)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (DownloadModel downloadItem in DownloadCollection)
{
@@ -570,7 +571,7 @@ private void OnDownloadPaused(Guid downloadID)
downloadItem.DownloadStatus = DownloadStatus.Pause;
}
}
- });
+ }, null);
}
///
@@ -578,7 +579,7 @@ private void OnDownloadPaused(Guid downloadID)
///
private void OnDownloadDeleted(Guid downloadID)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (DownloadModel downloadItem in DownloadCollection)
{
@@ -588,7 +589,7 @@ private void OnDownloadDeleted(Guid downloadID)
break;
}
}
- });
+ }, null);
}
///
@@ -596,7 +597,7 @@ private void OnDownloadDeleted(Guid downloadID)
///
private void OnDownloadProgressing(Guid downloadID, DownloadSchedulerModel downloadSchedulerItem)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (DownloadModel downloadItem in DownloadCollection)
{
@@ -610,7 +611,7 @@ private void OnDownloadProgressing(Guid downloadID, DownloadSchedulerModel downl
break;
}
}
- });
+ }, null);
}
///
@@ -618,7 +619,7 @@ private void OnDownloadProgressing(Guid downloadID, DownloadSchedulerModel downl
///
private void OnDownloadCompleted(Guid downloadID, DownloadSchedulerModel downloadSchedulerItem)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (DownloadModel downloadItem in DownloadCollection)
{
@@ -632,7 +633,7 @@ private void OnDownloadCompleted(Guid downloadID, DownloadSchedulerModel downloa
break;
}
}
- });
+ }, null);
}
///
@@ -689,11 +690,11 @@ private void OnDownloadLinkTextChanged(object sender, TextChangedEventArgs args)
string fileName = uri.Segments[uri.Segments.Length - 1];
if (fileName is not "/")
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
DownloadFileNameText = fileName;
IsPrimaryButtonEnabled = !string.IsNullOrEmpty(DownloadLinkText) && !string.IsNullOrEmpty(DownloadFolderText);
- });
+ }, null);
}
}
}
@@ -762,10 +763,10 @@ private void OnDownloadClicked(object sender, RoutedEventArgs args)
// 检查本地文件是否存在
if (File.Exists(filePath))
{
- MainWindow.Current.BeginInvoke(async () =>
+ synchronizationContext.Post(async (_) =>
{
await ContentDialogHelper.ShowAsync(new FileCheckDialog(DownloadLinkText, filePath), MainWindow.Current.Content as FrameworkElement);
- });
+ }, null);
}
else
{
diff --git a/WindowsTools/Views/Pages/ExtensionNamePage.xaml.cs b/WindowsTools/Views/Pages/ExtensionNamePage.xaml.cs
index 1e6c973..c6c5253 100644
--- a/WindowsTools/Views/Pages/ExtensionNamePage.xaml.cs
+++ b/WindowsTools/Views/Pages/ExtensionNamePage.xaml.cs
@@ -4,6 +4,7 @@
using System.ComponentModel;
using System.Diagnostics.Tracing;
using System.IO;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -21,7 +22,6 @@
using WindowsTools.Strings;
using WindowsTools.UI.Dialogs;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
// 抑制 IDE0060 警告
#pragma warning disable IDE0060
@@ -33,6 +33,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class ExtensionNamePage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly object extensionNameLock = new();
private bool _isModifyingNow = false;
@@ -518,7 +519,7 @@ private async void OnViewErrorInformationClicked(object sender, RoutedEventArgs
///
public void AddToExtensionNamePage(List extensionNameList)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
lock (extensionNameLock)
{
@@ -527,7 +528,7 @@ public void AddToExtensionNamePage(List extensionNameList)
ExtensionNameCollection.Add(oldAndNewNameItem);
}
}
- });
+ }, null);
}
///
@@ -621,7 +622,7 @@ private void ChangeFileName()
await Task.Delay(300);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsModifyingNow = false;
foreach (OperationFailedModel operationFailedItem in operationFailedList)
@@ -635,7 +636,7 @@ private void ChangeFileName()
ExtensionNameCollection.Clear();
}
- });
+ }, null);
});
}
}
diff --git a/WindowsTools/Views/Pages/FileCertificatePage.xaml.cs b/WindowsTools/Views/Pages/FileCertificatePage.xaml.cs
index 72fc315..2f19ad2 100644
--- a/WindowsTools/Views/Pages/FileCertificatePage.xaml.cs
+++ b/WindowsTools/Views/Pages/FileCertificatePage.xaml.cs
@@ -5,6 +5,7 @@
using System.Diagnostics.Tracing;
using System.IO;
using System.Runtime.InteropServices;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -22,7 +23,6 @@
using WindowsTools.Strings;
using WindowsTools.UI.Dialogs;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
using WindowsTools.WindowsAPI.PInvoke.Imagehlp;
// 抑制 IDE0060 警告
@@ -35,6 +35,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class FileCertificatePage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly object fileCertificateLock = new();
private bool _isModifyingNow = false;
@@ -312,7 +313,7 @@ private async void OnViewErrorInformationClicked(object sender, RoutedEventArgs
///
public void AddToFileCertificatePage(List fileCertificateList)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
lock (fileCertificateLock)
{
@@ -321,7 +322,7 @@ public void AddToFileCertificatePage(List fileCertificat
FileCertificateCollection.Add(certificateResultItem);
}
}
- });
+ }, null);
}
///
@@ -369,7 +370,7 @@ private void RemoveFileCertificates()
await Task.Delay(300);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsModifyingNow = false;
foreach (OperationFailedModel operationFailedItem in operationFailedList)
@@ -383,7 +384,7 @@ private void RemoveFileCertificates()
FileCertificateCollection.Clear();
}
- });
+ }, null);
});
}
}
diff --git a/WindowsTools/Views/Pages/FileNamePage.xaml.cs b/WindowsTools/Views/Pages/FileNamePage.xaml.cs
index 1b851c7..9b4208d 100644
--- a/WindowsTools/Views/Pages/FileNamePage.xaml.cs
+++ b/WindowsTools/Views/Pages/FileNamePage.xaml.cs
@@ -5,6 +5,7 @@
using System.ComponentModel;
using System.Diagnostics.Tracing;
using System.IO;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -22,7 +23,6 @@
using WindowsTools.Strings;
using WindowsTools.UI.Dialogs;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
// 抑制 IDE0060 警告
#pragma warning disable IDE0060
@@ -34,6 +34,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class FileNamePage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly object fileNameLock = new();
private bool _isChecked = false;
@@ -700,7 +701,7 @@ private async void OnViewErrorInformationClicked(object sender, RoutedEventArgs
///
public void AddToFileNamePage(List filenameList)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
lock (fileNameLock)
{
@@ -709,7 +710,7 @@ public void AddToFileNamePage(List filenameList)
FileNameCollection.Add(oldAndNewNameItem);
}
}
- });
+ }, null);
}
private string GetChangeRule(int index)
@@ -903,7 +904,7 @@ private void ChangeFileName()
await Task.Delay(300);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsModifyingNow = false;
foreach (OperationFailedModel operationFailedItem in operationFailedList)
@@ -917,7 +918,7 @@ private void ChangeFileName()
FileNameCollection.Clear();
}
- });
+ }, null);
});
}
}
diff --git a/WindowsTools/Views/Pages/FilePropertiesPage.xaml.cs b/WindowsTools/Views/Pages/FilePropertiesPage.xaml.cs
index 966fa99..582c2ca 100644
--- a/WindowsTools/Views/Pages/FilePropertiesPage.xaml.cs
+++ b/WindowsTools/Views/Pages/FilePropertiesPage.xaml.cs
@@ -5,6 +5,7 @@
using System.Diagnostics.Tracing;
using System.IO;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -21,7 +22,6 @@
using WindowsTools.Strings;
using WindowsTools.UI.Dialogs;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
// 抑制 IDE0060 警告
#pragma warning disable IDE0060
@@ -33,6 +33,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class FilePropertiesPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly object filePropertiesLock = new();
private bool _isReadOnlyChecked = false;
@@ -628,7 +629,7 @@ private async void OnViewErrorInformationClicked(object sender, RoutedEventArgs
///
public void AddToFilePropertiesPage(List filePropertiesList)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
lock (filePropertiesLock)
{
@@ -637,7 +638,7 @@ public void AddToFilePropertiesPage(List filePropertie
FilePropertiesCollection.Add(oldAndNewPropertiesItem);
}
}
- });
+ }, null);
}
///
@@ -742,7 +743,7 @@ private void ChangeFileAttributes()
await Task.Delay(300);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsModifyingNow = false;
foreach (OperationFailedModel operationFailedItem in operationFailedList)
@@ -756,7 +757,7 @@ private void ChangeFileAttributes()
FilePropertiesCollection.Clear();
}
- });
+ }, null);
});
}
}
diff --git a/WindowsTools/Views/Pages/FileUnlockPage.xaml.cs b/WindowsTools/Views/Pages/FileUnlockPage.xaml.cs
index dcb1016..701e79f 100644
--- a/WindowsTools/Views/Pages/FileUnlockPage.xaml.cs
+++ b/WindowsTools/Views/Pages/FileUnlockPage.xaml.cs
@@ -10,6 +10,7 @@
using System.IO;
using System.Linq;
using System.Management;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -24,7 +25,6 @@
using WindowsTools.Services.Root;
using WindowsTools.Strings;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
using WindowsTools.WindowsAPI.PInvoke.Rstrtmgr;
using WindowsTools.WindowsAPI.PInvoke.Shell32;
@@ -38,6 +38,8 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class FileUnlockPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+
private InfoBarSeverity _resultSeverity = InfoBarSeverity.Informational;
public InfoBarSeverity ResultSeverity
@@ -175,10 +177,10 @@ protected override void OnDrop(global::Windows.UI.Xaml.DragEventArgs args)
if (filesList.Count is 1)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ParseFile(filesList[0].Path);
- });
+ }, null);
}
}
}
@@ -210,7 +212,7 @@ private void OnTerminateProcessExecuteRequested(XamlUICommand sender, ExecuteReq
Process process = Process.GetProcessById(processid);
process?.Kill();
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (ProcessInfoModel processItem in ProcessInfoCollection)
{
@@ -222,15 +224,15 @@ private void OnTerminateProcessExecuteRequested(XamlUICommand sender, ExecuteReq
}
TeachingTipHelper.Show(new OperationResultTip(OperationKind.TerminateProcess, true));
- });
+ }, null);
}
catch (Exception e)
{
LogService.WriteLog(EventLevel.Error, string.Format("Terminate process id {0} failed", processid), e);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new OperationResultTip(OperationKind.TerminateProcess, false));
- });
+ }, null);
}
});
}
@@ -333,12 +335,12 @@ public void ParseFile(string filePath)
if (result is not 0)
{
await Task.Delay(500);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ResultSeverity = InfoBarSeverity.Error;
IsRingActive = false;
StateInfoText = string.Format(FileUnlock.ParseFileFailed, FileName);
- });
+ }, null);
}
try
@@ -353,12 +355,12 @@ public void ParseFile(string filePath)
if (result is not 0)
{
await Task.Delay(500);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ResultSeverity = InfoBarSeverity.Error;
IsRingActive = false;
StateInfoText = string.Format(FileUnlock.ParseFileFailed, FileName);
- });
+ }, null);
}
result = RstrtmgrLibrary.RmGetList(handle, out uint pnProcInfoNeeded, ref pnProcInfo, null, ref lpdwRebootReasons);
@@ -390,13 +392,13 @@ public void ParseFile(string filePath)
if (processList.Count is 0)
{
await Task.Delay(500);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ResultControlVisable = true;
ResultSeverity = InfoBarSeverity.Success;
IsRingActive = false;
StateInfoText = string.Format(FileUnlock.ParseFileSuccessfully, FileName);
- });
+ }, null);
}
else
{
@@ -408,7 +410,7 @@ public void ParseFile(string filePath)
}
await Task.Delay(500);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ResultControlVisable = true;
ResultSeverity = InfoBarSeverity.Success;
@@ -441,32 +443,32 @@ public void ParseFile(string filePath)
continue;
}
}
- });
+ }, null);
}
}
// 解析成功,文件没有被占用
else
{
await Task.Delay(500);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ResultControlVisable = true;
ResultSeverity = InfoBarSeverity.Success;
IsRingActive = false;
StateInfoText = string.Format(FileUnlock.ParseFileSuccessfully, FileName);
- });
+ }, null);
}
}
catch (Exception)
{
await Task.Delay(500);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ResultControlVisable = false;
ResultSeverity = InfoBarSeverity.Error;
IsRingActive = false;
StateInfoText = string.Format(FileUnlock.ParseFileFailed, FileName);
- });
+ }, null);
}
});
}
diff --git a/WindowsTools/Views/Pages/IconExtractPage.xaml.cs b/WindowsTools/Views/Pages/IconExtractPage.xaml.cs
index 0a0dfe3..76445d7 100644
--- a/WindowsTools/Views/Pages/IconExtractPage.xaml.cs
+++ b/WindowsTools/Views/Pages/IconExtractPage.xaml.cs
@@ -8,6 +8,7 @@
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -22,7 +23,6 @@
using WindowsTools.Services.Root;
using WindowsTools.Strings;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
using WindowsTools.WindowsAPI.PInvoke.User32;
// 抑制 IDE0060 警告
@@ -35,6 +35,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class IconExtractPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly object iconExtractLock = new();
private string filePath;
@@ -264,10 +265,10 @@ protected override void OnDrop(global::Windows.UI.Xaml.DragEventArgs args)
if (filesList.Count is 1)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ParseIconFile(filesList[0].Path);
- });
+ }, null);
}
}
}
@@ -476,11 +477,11 @@ private void OnExportSelectedIconsClicked(object sender, RoutedEventArgs args)
await Task.Delay(300);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsSaving = false;
TeachingTipHelper.Show(new OperationResultTip(OperationKind.IconExtract, selectedItemsList.Count - saveFailedCount, saveFailedCount));
- });
+ }, null);
});
}
}
@@ -555,14 +556,14 @@ private void OnExportAllIconsClicked(object sender, RoutedEventArgs args)
await Task.Delay(300);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
lock (iconExtractLock)
{
IsSaving = false;
TeachingTipHelper.Show(new OperationResultTip(OperationKind.IconExtract, IconCollection.Count - saveFailedCount, saveFailedCount));
}
- });
+ }, null);
});
}
}
@@ -610,7 +611,7 @@ public void ParseIconFile(string iconFilePath)
User32Library.DestroyIcon(phicon[index]);
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
try
{
@@ -640,17 +641,17 @@ public void ParseIconFile(string iconFilePath)
{
LogService.WriteLog(EventLevel.Error, string.Format("Display {0} icons failed", iconsList), e);
}
- });
+ }, null);
}
catch (Exception e)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
GetResults = string.Format(IconExtract.GetResults, Path.GetFileName(filePath), 0);
NoResources = string.Format(IconExtract.NoResources, Path.GetFileName(filePath));
ImageSource = null;
IsImageEmpty = true;
- });
+ }, null);
LogService.WriteLog(EventLevel.Error, string.Format("Parse {0} file icons failed", filePath), e);
}
diff --git a/WindowsTools/Views/Pages/LoafPage.xaml b/WindowsTools/Views/Pages/LoafPage.xaml
index 700ed55..2c0c494 100644
--- a/WindowsTools/Views/Pages/LoafPage.xaml
+++ b/WindowsTools/Views/Pages/LoafPage.xaml
@@ -53,7 +53,6 @@
diff --git a/WindowsTools/Views/Pages/LoafPage.xaml.cs b/WindowsTools/Views/Pages/LoafPage.xaml.cs
index df2147b..2ba56b8 100644
--- a/WindowsTools/Views/Pages/LoafPage.xaml.cs
+++ b/WindowsTools/Views/Pages/LoafPage.xaml.cs
@@ -5,6 +5,7 @@
using System.Diagnostics.Tracing;
using System.IO;
using System.Net.Http;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.Storage.Streams;
@@ -26,6 +27,8 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class LoafPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+
private bool _loadImageCompleted = false;
public bool LoadImageCompleted
@@ -150,15 +153,7 @@ public LoafPage()
{
InitializeComponent();
SelectedUpdateStyle = UpdateStyleList[0];
- }
- #region 第一部分:摸鱼页面——挂载的事件
-
- ///
- /// 加载每日必应壁纸图片
- ///
- private void OnLoaded(object sender, RoutedEventArgs args)
- {
Task.Run(async () =>
{
try
@@ -175,7 +170,7 @@ private void OnLoaded(object sender, RoutedEventArgs args)
Stream stream = await responseMessage.Content.ReadAsStreamAsync();
IRandomAccessStream randomAccessStream = stream.AsRandomAccessStream();
- MainWindow.Current.BeginInvoke(async () =>
+ synchronizationContext.Post(async (_) =>
{
try
{
@@ -192,29 +187,31 @@ private void OnLoaded(object sender, RoutedEventArgs args)
LoadImageCompleted = true;
LogService.WriteLog(EventLevel.Error, "Load bing wallpaper image failed", e);
}
- });
+ }, null);
}
else
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
LoafImage = new(new Uri("ms-appx:///Assets/Images/LoafWallpaper.jpg"));
LoadImageCompleted = true;
- });
+ }, null);
}
}
catch (Exception e)
{
LogService.WriteLog(EventLevel.Error, "Load bing wallpaper image failed", e);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
LoafImage = new(new Uri("ms-appx:///Assets/Images/LoafWallpaper.jpg"));
LoadImageCompleted = true;
- });
+ }, null);
}
});
}
+ #region 第一部分:摸鱼页面——挂载的事件
+
///
/// 开始摸鱼
///
diff --git a/WindowsTools/Views/Pages/LoopbackManagerPage.xaml.cs b/WindowsTools/Views/Pages/LoopbackManagerPage.xaml.cs
index 3ae760c..e8d4e3e 100644
--- a/WindowsTools/Views/Pages/LoopbackManagerPage.xaml.cs
+++ b/WindowsTools/Views/Pages/LoopbackManagerPage.xaml.cs
@@ -8,6 +8,7 @@
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -18,7 +19,6 @@
using WindowsTools.Services.Root;
using WindowsTools.Strings;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
using WindowsTools.WindowsAPI.PInvoke.FirewallAPI;
using WindowsTools.WindowsAPI.PInvoke.Shlwapi;
@@ -32,6 +32,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class LoopbackManagerPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private IntPtr pACs;
private bool _isLoadCompleted;
@@ -405,10 +406,10 @@ private async Task GetLoopbackDataAsync()
IsOldChecked = isEnabled,
};
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
LoopbackCollection.Add(loopbackItem);
- });
+ }, null);
}
catch (Exception)
{
@@ -417,10 +418,10 @@ private async Task GetLoopbackDataAsync()
}
await Task.Delay(500);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsLoadCompleted = true;
- });
+ }, null);
}
///
@@ -521,17 +522,17 @@ private void SetLoopbackState(List loopbackList)
if (FirewallAPILibrary.NetworkIsolationSetAppContainerConfig(loopbackList.Count, sidAndAttributesArray) is 0)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new OperationResultTip(OperationKind.LoopbackSetResult, true));
- });
+ }, null);
}
else
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
TeachingTipHelper.Show(new OperationResultTip(OperationKind.LoopbackSetResult, false));
- });
+ }, null);
}
}
}
diff --git a/WindowsTools/Views/Pages/MainPage.xaml b/WindowsTools/Views/Pages/MainPage.xaml
index e3ba44f..6277a94 100644
--- a/WindowsTools/Views/Pages/MainPage.xaml
+++ b/WindowsTools/Views/Pages/MainPage.xaml
@@ -12,6 +12,7 @@
ActualThemeChanged="{x:Bind OnActualThemeChanged}"
RequestedTheme="{x:Bind WindowTheme, Mode=OneWay}"
mc:Ignorable="d">
+
diff --git a/WindowsTools/Views/Pages/MainPage.xaml.cs b/WindowsTools/Views/Pages/MainPage.xaml.cs
index 7cdd66e1..c1642a7 100644
--- a/WindowsTools/Views/Pages/MainPage.xaml.cs
+++ b/WindowsTools/Views/Pages/MainPage.xaml.cs
@@ -4,6 +4,7 @@
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.System;
@@ -27,6 +28,8 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class MainPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+
private ElementTheme _windowTheme;
public ElementTheme WindowTheme
@@ -425,13 +428,10 @@ public void NavigationFrom()
{
ShellMenuPage shellMenuPage = (MainNavigationView.Content as Frame).Content as ShellMenuPage;
- if (shellMenuPage is not null)
+ if (shellMenuPage is not null && shellMenuPage.BreadCollection is not null && shellMenuPage.BreadCollection.Count > 1)
{
- if (shellMenuPage.BreadCollection is not null && shellMenuPage.BreadCollection.Count > 1)
- {
- shellMenuPage.BreadCollection.RemoveAt(shellMenuPage.BreadCollection.Count - 1);
- return;
- }
+ shellMenuPage.BreadCollection.RemoveAt(shellMenuPage.BreadCollection.Count - 1);
+ return;
}
if ((MainNavigationView.Content as Frame).CanGoBack)
@@ -652,10 +652,10 @@ public void SendReceivedFilesList(List filesList)
System.Drawing.Image image = System.Drawing.Image.FromFile(filesList[0]);
if (image is not null)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
page.ParseCodeImage(image);
- });
+ }, null);
}
}
catch (Exception e)
@@ -677,7 +677,7 @@ public void SendReceivedFilesList(List filesList)
private bool GetWindowMaximizeState(bool isWindowMaximized, bool isWindowMaximizeEnabled, string isReverse)
{
- return isWindowMaximizeEnabled ? isReverse == nameof(isReverse) ? isWindowMaximized.Equals(false) : isWindowMaximized : false;
+ return isWindowMaximizeEnabled && (isReverse == nameof(isReverse) ? isWindowMaximized.Equals(false) : isWindowMaximized);
}
}
}
diff --git a/WindowsTools/Views/Pages/PriExtractPage.xaml.cs b/WindowsTools/Views/Pages/PriExtractPage.xaml.cs
index 5c5938c..5a00e23 100644
--- a/WindowsTools/Views/Pages/PriExtractPage.xaml.cs
+++ b/WindowsTools/Views/Pages/PriExtractPage.xaml.cs
@@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -25,7 +26,6 @@
using WindowsTools.Services.Root;
using WindowsTools.Strings;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
using WindowsTools.WindowsAPI.PInvoke.Shell32;
// 抑制 IDE0060 警告
@@ -38,6 +38,8 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class PriExtractPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+
private bool isStringAllSelect = false;
private bool isFilePathAllSelect = false;
private bool isEmbeddedDataAllSelect = false;
@@ -298,20 +300,20 @@ protected override void OnDrop(global::Windows.UI.Xaml.DragEventArgs args)
if (filesList.Count is 1)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
ParseResourceFile(filesList[0].Path);
- });
+ }, null);
}
}
}
catch (Exception e)
{
LogService.WriteLog(EventLevel.Warning, "Drop file in pri extract page failed", e);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsProcessing = false;
- });
+ }, null);
}
});
deferral.Complete();
@@ -386,10 +388,10 @@ private void OnEmbeddedDataExecuteRequested(XamlUICommand sender, ExecuteRequest
LogService.WriteLog(EventLevel.Error, string.Format("Open saved embedded data folder {0} failed", dialog.SelectedPath), e);
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsProcessing = false;
- });
+ }, null);
});
}
}
@@ -579,13 +581,13 @@ private void OnSelectionChnaged(object sender, SelectionChangedEventArgs args)
{
List coincidentStringList = stringList.Where(item => item.Language.Equals(LanguageCollection[SelectedIndex].Value as string, StringComparison.OrdinalIgnoreCase)).ToList();
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (StringModel stringItem in coincidentStringList)
{
StringCollection.Add(stringItem);
}
- });
+ }, null);
});
}
@@ -703,10 +705,10 @@ private void OnExportSelectedEmbeddedDataClicked(object sender, RoutedEventArgs
LogService.WriteLog(EventLevel.Error, string.Format("Open saved embedded data folder {0} failed", dialog.SelectedPath), e);
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsProcessing = false;
- });
+ }, null);
});
}
else
@@ -791,10 +793,10 @@ private void OnExportAllEmbeddedDataClicked(object sender, RoutedEventArgs args)
LogService.WriteLog(EventLevel.Error, string.Format("Open saved embedded data folder {0} failed", dialog.SelectedPath), e);
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsProcessing = false;
- });
+ }, null);
});
}
}
@@ -1204,7 +1206,7 @@ public void ParseResourceFile(string filePath)
embeddedDataList.Sort((item1, item2) => item1.Key.CompareTo(item2.Key));
// 显示获取到的所有内容
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
LanguageCollection.Add(new DictionaryEntry(PriExtract.AllLanguage, "AllLanguage"));
@@ -1234,18 +1236,18 @@ public void ParseResourceFile(string filePath)
IsProcessing = false;
GetResults = string.Format(PriExtract.GetResults, Path.GetFileName(filePath), stringList.Count + filePathList.Count + embeddedDataList.Count);
isLoadCompleted = true;
- });
+ }, null);
}
catch (Exception e)
{
LogService.WriteLog(EventLevel.Error, string.Format("Parse file {0} resources failed", filePath), e);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsProcessing = false;
GetResults = string.Format(PriExtract.GetResults, Path.GetFileName(filePath), 0);
isLoadCompleted = true;
- });
+ }, null);
return;
}
diff --git a/WindowsTools/Views/Pages/ShellMenuPage.xaml b/WindowsTools/Views/Pages/ShellMenuPage.xaml
index c687f84..ed092cc 100644
--- a/WindowsTools/Views/Pages/ShellMenuPage.xaml
+++ b/WindowsTools/Views/Pages/ShellMenuPage.xaml
@@ -5,19 +5,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
+ xmlns:sys="using:System"
xmlns:collection="using:System.Collections"
xmlns:converter="using:WindowsTools.Helpers.Converters"
xmlns:model="using:WindowsTools.Models"
xmlns:string="using:WindowsTools.Strings"
- xmlns:control="using:WindowsTools.UI.Controls"
NavigationCacheMode="Enabled"
mc:Ignorable="d">
-
-
-
-
-
@@ -79,7 +74,6 @@
Visibility="{x:Bind converter:ValueCheckConverterHelper.IsCurrentControl(BreadCollection.Count, 1), Mode=OneWay}">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ BorderThickness="1"
+ CornerRadius="{StaticResource ControlCornerRadius}">
+
-
-
-
+ Glyph="" />
+ Style="{StaticResource BodyTextBlockStyle}"
+ Text="{x:Bind string:ShellMenu.MenuTitle}" />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ PlaceholderText="{x:Bind string:ShellMenu.MenuTitlePHText}"
+ Text="{x:Bind MenuTitleText, Mode=OneWay}"
+ TextChanged="{x:Bind OnTitleTextChanged}" />
-
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+ Margin="0,0,12,0"
+ FontSize="16"
+ Glyph="" />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Style="{StaticResource BodyTextBlockStyle}"
+ Text="{x:Bind string:ShellMenu.MenuIcon}" />
-
+
-
-
+
+
+
+ Height="52"
+ Padding="44,0,16,0"
+ HorizontalAlignment="Stretch"
+ VerticalAlignment="Center">
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+ Style="{StaticResource BodyTextBlockStyle}"
+ Text="{x:Bind string:ShellMenu.ShouldUseProgramIcon}" />
-
-
-
-
-
-
-
-
-
-
-
+ FlowDirection="RightToLeft"
+ IsOn="{x:Bind ShouldUseProgramIcon, Mode=OneWay}"
+ OffContent="{x:Bind string:ShellMenu.ShouldUseProgramIconOffContent}"
+ OnContent="{x:Bind string:ShellMenu.ShouldUseProgramIconOnContent}"
+ Toggled="{x:Bind OnShouldUseProgramIconToggled}" />
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ColumnSpacing="10"
+ Visibility="{x:Bind converter:ValueConverterHelper.BooleanToVisibilityReverseConvert(ShouldEnableThemeIcon), Mode=OneWay}">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Grid.Column="0"
+ VerticalAlignment="Center"
+ Style="{StaticResource BodyTextBlockStyle}"
+ Text="{x:Bind string:ShellMenu.LightThemeIcon}" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Glyph="" />
+ Style="{StaticResource BodyTextBlockStyle}"
+ Text="{x:Bind string:ShellMenu.MenuFileMatch}" />
-
+
+
+
-
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/WindowsTools/Views/Pages/ShellMenuPage.xaml.cs b/WindowsTools/Views/Pages/ShellMenuPage.xaml.cs
index d5ab40e..847d22c 100644
--- a/WindowsTools/Views/Pages/ShellMenuPage.xaml.cs
+++ b/WindowsTools/Views/Pages/ShellMenuPage.xaml.cs
@@ -1,18 +1,18 @@
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
-using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using WindowsTools.Extensions.DataType.Enums;
@@ -23,7 +23,6 @@
using WindowsTools.Strings;
using WindowsTools.UI.TeachingTips;
using WindowsTools.Views.Windows;
-using WindowsTools.WindowsAPI.PInvoke.Shell32;
// 抑制 IDE0060 警告
#pragma warning disable IDE0060
@@ -35,8 +34,13 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class ShellMenuPage : Page, INotifyPropertyChanged
{
- private Guid firstLevelMenuGuid = Guid.Empty;
- private Guid secondLevelMenuGuid = Guid.Empty;
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+ private Guid editMenuGuid = Guid.Empty;
+ private string selectedDefaultIconPath = string.Empty;
+ private string selectedLightThemeIconPath = string.Empty;
+ private string selectedDarkThemeIconPath = string.Empty;
+
+ private ShellMenuItemModel selectedItem;
private BitmapImage _rootMenuImage;
@@ -70,6 +74,351 @@ public string RootMenuText
}
}
+ private bool _isAddMenuEnabled;
+
+ public bool IsAddMenuEnabled
+ {
+ get { return _isAddMenuEnabled; }
+
+ set
+ {
+ if (!Equals(_isAddMenuEnabled, value))
+ {
+ _isAddMenuEnabled = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsAddMenuEnabled)));
+ }
+ }
+ }
+
+ private bool _isEditMenuEnabled;
+
+ public bool IsEditMenuEnabled
+ {
+ get { return _isEditMenuEnabled; }
+
+ set
+ {
+ if (!Equals(_isEditMenuEnabled, value))
+ {
+ _isEditMenuEnabled = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsEditMenuEnabled)));
+ }
+ }
+ }
+
+ private string _menuTitleText;
+
+ public string MenuTitleText
+ {
+ get { return _menuTitleText; }
+
+ set
+ {
+ if (!Equals(_menuTitleText, value))
+ {
+ _menuTitleText = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuTitleText)));
+ }
+ }
+ }
+
+ private bool _shouldUseProgramIcon;
+
+ public bool ShouldUseProgramIcon
+ {
+ get { return _shouldUseProgramIcon; }
+
+ set
+ {
+ if (!Equals(_shouldUseProgramIcon, value))
+ {
+ _shouldUseProgramIcon = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShouldUseProgramIcon)));
+ }
+ }
+ }
+
+ private bool _shouldEnableThemeIcon;
+
+ public bool ShouldEnableThemeIcon
+ {
+ get { return _shouldEnableThemeIcon; }
+
+ set
+ {
+ if (!Equals(_shouldEnableThemeIcon, value))
+ {
+ _shouldEnableThemeIcon = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ShouldEnableThemeIcon)));
+ }
+ }
+ }
+
+ private BitmapImage _defaultIconImage = new();
+
+ public BitmapImage DefaultIconImage
+ {
+ get { return _defaultIconImage; }
+
+ set
+ {
+ if (!Equals(_defaultIconImage, value))
+ {
+ _defaultIconImage = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DefaultIconImage)));
+ }
+ }
+ }
+
+ private string _defaultIconPath;
+
+ public string DefaultIconPath
+ {
+ get { return _defaultIconPath; }
+
+ set
+ {
+ if (!Equals(_defaultIconPath, value))
+ {
+ _defaultIconPath = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DefaultIconPath)));
+ }
+ }
+ }
+
+ private BitmapImage _lightThemeIconImage = new();
+
+ public BitmapImage LightThemeIconImage
+ {
+ get { return _lightThemeIconImage; }
+
+ set
+ {
+ if (!Equals(_lightThemeIconImage, value))
+ {
+ _lightThemeIconImage = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LightThemeIconImage)));
+ }
+ }
+ }
+
+ private string _lightThemeIconPath;
+
+ public string LightThemeIconPath
+ {
+ get { return _lightThemeIconPath; }
+
+ set
+ {
+ if (!Equals(_lightThemeIconPath, value))
+ {
+ _lightThemeIconPath = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(LightThemeIconPath)));
+ }
+ }
+ }
+
+ private BitmapImage _darkThemeIconImage = new();
+
+ public BitmapImage DarkThemeIconImage
+ {
+ get { return _darkThemeIconImage; }
+
+ set
+ {
+ if (!Equals(_darkThemeIconImage, value))
+ {
+ _darkThemeIconImage = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DarkThemeIconImage)));
+ }
+ }
+ }
+
+ private string _darkThemeIconPath;
+
+ public string DarkThemeIconPath
+ {
+ get { return _darkThemeIconPath; }
+
+ set
+ {
+ if (!Equals(_darkThemeIconPath, value))
+ {
+ _darkThemeIconPath = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DarkThemeIconPath)));
+ }
+ }
+ }
+
+ private string _menuProgramPathText;
+
+ public string MenuProgramPathText
+ {
+ get { return _menuProgramPathText; }
+
+ set
+ {
+ if (!Equals(_menuProgramPathText, value))
+ {
+ _menuProgramPathText = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuProgramPathText)));
+ }
+ }
+ }
+
+ private string _menuParameterText;
+
+ public string MenuParameterText
+ {
+ get { return _menuParameterText; }
+
+ set
+ {
+ if (!Equals(_menuParameterText, value))
+ {
+ _menuParameterText = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuParameterText)));
+ }
+ }
+ }
+
+ private bool _folderBackgroundMatch;
+
+ public bool FolderBackgroundMatch
+ {
+ get { return _folderBackgroundMatch; }
+
+ set
+ {
+ if (!Equals(_folderBackgroundMatch, value))
+ {
+ _folderBackgroundMatch = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderBackgroundMatch)));
+ }
+ }
+ }
+
+ private bool _folderDesktopMatch;
+
+ public bool FolderDesktopMatch
+ {
+ get { return _folderDesktopMatch; }
+
+ set
+ {
+ if (!Equals(_folderDesktopMatch, value))
+ {
+ _folderDesktopMatch = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDesktopMatch)));
+ }
+ }
+ }
+
+ private bool _folderDirectoryMatch;
+
+ public bool FolderDirectoryMatch
+ {
+ get { return _folderDirectoryMatch; }
+
+ set
+ {
+ if (!Equals(_folderDirectoryMatch, value))
+ {
+ _folderDirectoryMatch = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDirectoryMatch)));
+ }
+ }
+ }
+
+ private bool _folderDriveMatch;
+
+ public bool FolderDriveMatch
+ {
+ get { return _folderDriveMatch; }
+
+ set
+ {
+ if (!Equals(_folderDriveMatch, value))
+ {
+ _folderDriveMatch = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(FolderDriveMatch)));
+ }
+ }
+ }
+
+ private DictionaryEntry _selectedFileMatchRule;
+
+ public DictionaryEntry SelectedFileMatchRule
+ {
+ get { return _selectedFileMatchRule; }
+
+ set
+ {
+ if (!Equals(_selectedFileMatchRule, value))
+ {
+ _selectedFileMatchRule = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedFileMatchRule)));
+ }
+ }
+ }
+
+ private bool _needInputMatchFormat;
+
+ public bool NeedInputMatchFormat
+ {
+ get { return _needInputMatchFormat; }
+
+ set
+ {
+ if (!Equals(_needInputMatchFormat, value))
+ {
+ _needInputMatchFormat = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NeedInputMatchFormat)));
+ }
+ }
+ }
+
+ private string _menuFileMatchFormatPHText;
+
+ public string MenuFileMatchFormatPHText
+ {
+ get { return _menuFileMatchFormatPHText; }
+
+ set
+ {
+ if (!Equals(_menuFileMatchFormatPHText, value))
+ {
+ _menuFileMatchFormatPHText = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuFileMatchFormatPHText)));
+ }
+ }
+ }
+
+ private string _menuFileMatchFormatText;
+
+ public string MenuFileMatchFormatText
+ {
+ get { return _menuFileMatchFormatText; }
+
+ set
+ {
+ if (!Equals(_menuFileMatchFormatText, value))
+ {
+ _menuFileMatchFormatText = value;
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MenuFileMatchFormatText)));
+ }
+ }
+ }
+
+ private List FileMatchRuleList { get; } =
+ [
+ new DictionaryEntry(ShellMenu.None,"None"),
+ new DictionaryEntry(ShellMenu.Name,"Name"),
+ new DictionaryEntry(ShellMenu.NameRegex,"NameRegex"),
+ new DictionaryEntry(ShellMenu.Extension,"Extension"),
+ new DictionaryEntry(ShellMenu.All,"All")
+ ];
+
public ObservableCollection BreadCollection { get; } =
[
new DictionaryEntry(ShellMenu.Title, "Title")
@@ -100,14 +449,99 @@ public ShellMenuPage()
memoryStream.Seek(0, SeekOrigin.Begin);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(memoryStream.AsRandomAccessStream());
- ShellMenuItemCollection.Add(new ShellMenuItemModel()
+
+ ShellMenuItemModel shellMenuItemModel = new ShellMenuItemModel()
{
Title = "Windows 工具箱",
MenuIndex = 0,
+ IsSelected = true,
+ MenuGuid = Guid.Empty,
+ MenuType = MenuType.RootMenu,
ProgramPath = System.Windows.Forms.Application.ExecutablePath,
IconPath = System.Windows.Forms.Application.ExecutablePath,
- Icon = bitmapImage
- });
+ Icon = bitmapImage,
+ };
+
+ ShellMenuItemModel secondMenuItemModel1 = new ShellMenuItemModel()
+ {
+ Title = "Windows 工具箱21",
+ MenuIndex = 0,
+ MenuGuid = Guid.Empty,
+ IsSelected = false,
+ MenuType = MenuType.SecondLevelMenu,
+ ProgramPath = System.Windows.Forms.Application.ExecutablePath,
+ IconPath = System.Windows.Forms.Application.ExecutablePath,
+ Icon = bitmapImage,
+ };
+
+ ShellMenuItemModel secondMenuItemModel2 = new ShellMenuItemModel()
+ {
+ Title = "Windows 工具箱22",
+ MenuIndex = 0,
+ MenuGuid = Guid.Empty,
+ IsSelected = false,
+ MenuType = MenuType.SecondLevelMenu,
+ ProgramPath = System.Windows.Forms.Application.ExecutablePath,
+ IconPath = System.Windows.Forms.Application.ExecutablePath,
+ Icon = bitmapImage,
+ };
+
+ ShellMenuItemModel firstLevelMenuItem1 = new ShellMenuItemModel()
+ {
+ Title = "Windows 工具箱11",
+ MenuIndex = 0,
+ MenuGuid = Guid.Empty,
+ IsSelected = false,
+ MenuType = MenuType.FirstLevelMenu,
+ ProgramPath = System.Windows.Forms.Application.ExecutablePath,
+ IconPath = System.Windows.Forms.Application.ExecutablePath,
+ Icon = bitmapImage,
+ };
+
+ ShellMenuItemModel firstLevelMenuItem2 = new ShellMenuItemModel()
+ {
+ Title = "Windows 工具箱12",
+ MenuIndex = 0,
+ MenuGuid = Guid.Empty,
+ IsSelected = false,
+ MenuType = MenuType.FirstLevelMenu,
+ ProgramPath = System.Windows.Forms.Application.ExecutablePath,
+ IconPath = System.Windows.Forms.Application.ExecutablePath,
+ Icon = bitmapImage,
+ };
+
+ ShellMenuItemModel firstLevelMenuItem3 = new ShellMenuItemModel()
+ {
+ Title = "Windows 工具箱13",
+ MenuIndex = 0,
+ MenuGuid = Guid.Empty,
+ IsSelected = false,
+ MenuType = MenuType.FirstLevelMenu,
+ ProgramPath = System.Windows.Forms.Application.ExecutablePath,
+ IconPath = System.Windows.Forms.Application.ExecutablePath,
+ Icon = bitmapImage,
+ };
+
+ firstLevelMenuItem1.SubMenuItemCollection.Add(secondMenuItemModel1);
+ firstLevelMenuItem1.SubMenuItemCollection.Add(secondMenuItemModel2);
+
+ firstLevelMenuItem2.SubMenuItemCollection.Add(secondMenuItemModel1);
+ firstLevelMenuItem2.SubMenuItemCollection.Add(secondMenuItemModel2);
+
+ firstLevelMenuItem3.SubMenuItemCollection.Add(secondMenuItemModel1);
+ firstLevelMenuItem3.SubMenuItemCollection.Add(secondMenuItemModel2);
+
+ shellMenuItemModel.SubMenuItemCollection.Add(firstLevelMenuItem1);
+ shellMenuItemModel.SubMenuItemCollection.Add(firstLevelMenuItem2);
+ shellMenuItemModel.SubMenuItemCollection.Add(firstLevelMenuItem3);
+
+ ShellMenuItemCollection.Add(shellMenuItemModel);
+
+ selectedItem = ShellMenuItemCollection[0];
+ IsAddMenuEnabled = true;
+ IsEditMenuEnabled = false;
+
+ SelectedFileMatchRule = FileMatchRuleList[4];
}
#region 第一部分:重写父类事件
@@ -132,68 +566,7 @@ protected override void OnNavigatedTo(NavigationEventArgs args)
#endregion 第一部分:重写父类事件
- #region 第二部分:XamlUICommand 命令调用时挂载的事件
-
- ///
- /// 编辑菜单项
- ///
- private void OnEditExecuteRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
- {
- int menuIndex = Convert.ToInt32(args.Parameter);
-
- if (BreadCollection.Count is 1)
- {
- BreadCollection.Add(new DictionaryEntry(ShellMenu.FirstLevelMenu, "FirstLevelMenu"));
- }
- else if (BreadCollection.Count is 2)
- {
- BreadCollection.Add(new DictionaryEntry(ShellMenu.SecondLevelMenu, "SecondLevelMenu"));
- }
- }
-
- ///
- /// 定位菜单项
- ///
- private void OnOpenProgramPathRequested(XamlUICommand sender, ExecuteRequestedEventArgs args)
- {
- string filePath = args.Parameter as string;
-
- if (!string.IsNullOrEmpty(filePath))
- {
- Task.Run(() =>
- {
- if (!string.IsNullOrEmpty(filePath))
- {
- if (File.Exists(filePath))
- {
- IntPtr pidlList = Shell32Library.ILCreateFromPath(filePath);
- if (pidlList != IntPtr.Zero)
- {
- Shell32Library.SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0);
- Shell32Library.ILFree(pidlList);
- }
- }
- else
- {
- string directoryPath = Path.GetDirectoryName(filePath);
-
- if (Directory.Exists(directoryPath))
- {
- Process.Start(directoryPath);
- }
- else
- {
- Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
- }
- }
- }
- });
- }
- }
-
- #endregion 第二部分:XamlUICommand 命令调用时挂载的事件
-
- #region 第三部分:根菜单页面——挂载的事件
+ #region 第二部分:根菜单页面——挂载的事件
///
/// 单击痕迹栏条目时发生的事件
@@ -201,19 +574,8 @@ private void OnOpenProgramPathRequested(XamlUICommand sender, ExecuteRequestedEv
private void OnItemClicked(object sender, BreadcrumbBarItemClickedEventArgs args)
{
DictionaryEntry breadItem = (DictionaryEntry)args.Item;
- if (BreadCollection.Count is 3)
- {
- if (breadItem.Value.Equals(BreadCollection[0].Value))
- {
- BreadCollection.RemoveAt(2);
- BreadCollection.RemoveAt(1);
- }
- else if (breadItem.Value.Equals(BreadCollection[1].Value))
- {
- BreadCollection.RemoveAt(1);
- }
- }
- else if (BreadCollection.Count is 2)
+
+ if (BreadCollection.Count is 2)
{
if (breadItem.Value.Equals(BreadCollection[0].Value))
{
@@ -235,13 +597,10 @@ private void OnMenuSettingsClicked(object sender, RoutedEventArgs args)
///
private void OnSaveClicked(object sender, RoutedEventArgs args)
{
- // 保存一级菜单内容
if (BreadCollection.Count is 2)
{
- }
- // 保存二级菜单内容
- else if (BreadCollection.Count is 3)
- {
+ SaveSettingsInformation();
+ BreadCollection.RemoveAt(1);
}
}
@@ -266,10 +625,10 @@ private void OnModifyClicked(object sender, RoutedEventArgs args)
File.Copy(dialog.FileName, rootMenuFilePath, true);
ShellMenuService.SetRootMenuIcon(false, rootMenuFilePath);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
RootMenuImage = new() { UriSource = new Uri(rootMenuFilePath) };
- });
+ }, null);
});
}
catch (Exception e)
@@ -310,19 +669,19 @@ private void OnReturnDefaultClicked(object sender, RoutedEventArgs args)
LogService.WriteLog(EventLevel.Warning, "Delete RootMenu.png failed", e);
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
RootMenuImage = new() { UriSource = new Uri(ShellMenuService.RootMenuIconPath) };
- });
+ }, null);
}
else if (tag.Equals("Text"))
{
ShellMenuService.SetRootMenuText(true, string.Empty);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
RootMenuText = ShellMenuService.RootMenuText;
- });
+ }, null);
}
});
}
@@ -357,8 +716,11 @@ private void OnApplyClicked(object sender, RoutedEventArgs args)
///
/// 添加菜单
///
- private void OnAddMenuClicked(object sender, RoutedEventArgs args)
+ private void OnAddMenuItemClicked(object sender, RoutedEventArgs args)
{
+ Guid menuGuid = Guid.NewGuid();
+ AddShellMenu(menuGuid);
+ BreadCollection.Add(new DictionaryEntry(ShellMenu.EditMenu, "EditMenu"));
}
///
@@ -366,6 +728,15 @@ private void OnAddMenuClicked(object sender, RoutedEventArgs args)
///
private void OnClearMenuClicked(object sender, RoutedEventArgs args)
{
+ for (int index = ShellMenuItemCollection[0].SubMenuItemCollection.Count - 1; index >= 0; index--)
+ {
+ // 更新删除操作
+ ShellMenuItemCollection[0].SubMenuItemCollection.RemoveAt(index);
+ }
+
+ ShellMenuItemCollection[0].IsSelected = true;
+ IsAddMenuEnabled = true;
+ IsEditMenuEnabled = false;
}
///
@@ -373,8 +744,302 @@ private void OnClearMenuClicked(object sender, RoutedEventArgs args)
///
private void OnRefreshClicked(object sender, RoutedEventArgs args)
{
+ ShellMenuItemCollection[0].SubMenuItemCollection.Clear();
+ ShellMenuItemCollection[0].IsSelected = true;
+ IsAddMenuEnabled = true;
+ IsEditMenuEnabled = false;
+ // 添加子菜单读取操作
+ }
+
+ ///
+ /// 编辑菜单
+ ///
+ private void OnEditMenuClicked(object sender, RoutedEventArgs args)
+ {
+ if (selectedItem is not null && BreadCollection.Count is 1)
+ {
+ QueryShellMenu(selectedItem.MenuGuid);
+ BreadCollection.Add(new DictionaryEntry(ShellMenu.EditMenu, "EditMenu"));
+ }
}
- #endregion 第三部分:根菜单页面——挂载的事件
+ ///
+ /// 点击选中项触发的事件
+ ///
+ private void OnItemInvoked(Microsoft.UI.Xaml.Controls.TreeView sender, Microsoft.UI.Xaml.Controls.TreeViewItemInvokedEventArgs args)
+ {
+ if (selectedItem is not null)
+ {
+ selectedItem.IsSelected = false;
+ }
+
+ selectedItem = args.InvokedItem as ShellMenuItemModel;
+
+ if (selectedItem is not null)
+ {
+ selectedItem.IsSelected = true;
+ if (selectedItem.MenuType is MenuType.RootMenu)
+ {
+ IsAddMenuEnabled = true;
+ IsEditMenuEnabled = false;
+ }
+ else if (selectedItem.MenuType is MenuType.FirstLevelMenu)
+ {
+ IsAddMenuEnabled = true;
+ IsEditMenuEnabled = true;
+ }
+ else
+ {
+ IsAddMenuEnabled = false;
+ IsEditMenuEnabled = true;
+ }
+ }
+ }
+
+ ///
+ /// 菜单标题内容发生更改时的事件
+ ///
+ private void OnTitleTextChanged(object sender, TextChangedEventArgs args)
+ {
+ MenuTitleText = (sender as global::Windows.UI.Xaml.Controls.TextBox).Text;
+ }
+
+ ///
+ /// 是否启用主题图标按钮修改时触发的事件
+ ///
+ private void OnShouldEnableThemeIconToggled(object sender, RoutedEventArgs args)
+ {
+ ToggleSwitch toggleSwitch = sender as ToggleSwitch;
+
+ if (toggleSwitch is not null)
+ {
+ ShouldEnableThemeIcon = toggleSwitch.IsOn;
+ }
+ }
+
+ ///
+ /// 是否使用应用程序图标修改时触发的事件
+ ///
+ private void OnShouldUseProgramIconToggled(object sender, RoutedEventArgs args)
+ {
+ ToggleSwitch toggleSwitch = sender as ToggleSwitch;
+
+ if (toggleSwitch is not null)
+ {
+ ShouldUseProgramIcon = toggleSwitch.IsOn;
+ }
+ }
+
+ ///
+ /// 默认图标修改
+ ///
+ private void OnDefaultIconModifyClicked(object sender, RoutedEventArgs args)
+ {
+ OpenFileDialog dialog = new()
+ {
+ Multiselect = false,
+ Filter = ShellMenu.IconFilterCondition,
+ Title = ShellMenu.SelectIcon
+ };
+ if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
+ {
+ try
+ {
+ selectedDefaultIconPath = dialog.FileName;
+ DefaultIconPath = Path.Combine(ShellMenuService.ShellMenuConfigDirectory.FullName, editMenuGuid.ToString(), string.Format("{0} - DefualtIcon.ico", Path.GetFileName(selectedDefaultIconPath)));
+ Icon defaultIcon = Icon.ExtractAssociatedIcon(dialog.FileName);
+ MemoryStream memoryStream = new();
+ defaultIcon.ToBitmap().Save(memoryStream, ImageFormat.Png);
+ memoryStream.Seek(0, SeekOrigin.Begin);
+ DefaultIconImage.SetSource(memoryStream.AsRandomAccessStream());
+ memoryStream.Dispose();
+ }
+ catch (Exception e)
+ {
+ LogService.WriteLog(EventLevel.Error, "Set Default lightThemeIcon failed", e);
+ }
+ }
+ }
+
+ ///
+ /// 浅色主题图标修改
+ ///
+ private void OnLightThemeIconModifyClicked(object sender, RoutedEventArgs args)
+ {
+ OpenFileDialog dialog = new()
+ {
+ Multiselect = false,
+ Filter = ShellMenu.IconFilterCondition,
+ Title = ShellMenu.SelectIcon
+ };
+ if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
+ {
+ try
+ {
+ selectedLightThemeIconPath = dialog.FileName;
+ LightThemeIconPath = Path.Combine(ShellMenuService.ShellMenuConfigDirectory.FullName, editMenuGuid.ToString(), string.Format("{0} - LightThemeIcon.ico", Path.GetFileName(selectedLightThemeIconPath)));
+ Icon lightThemeIcon = Icon.ExtractAssociatedIcon(dialog.FileName);
+ MemoryStream memoryStream = new();
+ lightThemeIcon.ToBitmap().Save(memoryStream, ImageFormat.Png);
+ memoryStream.Seek(0, SeekOrigin.Begin);
+ LightThemeIconImage.SetSource(memoryStream.AsRandomAccessStream());
+ memoryStream.Dispose();
+ }
+ catch (Exception e)
+ {
+ LogService.WriteLog(EventLevel.Error, "Set light theme icon failed", e);
+ }
+ }
+ }
+
+ ///
+ /// 深色主题图标修改
+ ///
+ private void OnDarkThemeIconModifyClicked(object sender, RoutedEventArgs args)
+ {
+ OpenFileDialog dialog = new()
+ {
+ Multiselect = false,
+ Filter = ShellMenu.IconFilterCondition,
+ Title = ShellMenu.SelectIcon
+ };
+ if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
+ {
+ try
+ {
+ selectedDarkThemeIconPath = dialog.FileName;
+ DarkThemeIconPath = Path.Combine(ShellMenuService.ShellMenuConfigDirectory.FullName, editMenuGuid.ToString(), string.Format("{0} - DarkThemeIcon.ico", Path.GetFileName(selectedDarkThemeIconPath)));
+ Icon icon = Icon.ExtractAssociatedIcon(dialog.FileName);
+ MemoryStream memoryStream = new();
+ icon.ToBitmap().Save(memoryStream, ImageFormat.Png);
+ memoryStream.Seek(0, SeekOrigin.Begin);
+ DarkThemeIconImage.SetSource(memoryStream.AsRandomAccessStream());
+ memoryStream.Dispose();
+ }
+ catch (Exception e)
+ {
+ LogService.WriteLog(EventLevel.Error, "Set dark theme icon failed", e);
+ }
+ }
+ }
+
+ ///
+ /// 修改菜单程序文件路径
+ ///
+ private void OnMenuProgramPathModifyClicked(object sender, RoutedEventArgs args)
+ {
+ OpenFileDialog dialog = new()
+ {
+ Multiselect = false,
+ Filter = ShellMenu.ProgramFilterCondition,
+ Title = ShellMenu.SelectProgram
+ };
+ if (dialog.ShowDialog() is DialogResult.OK && !string.IsNullOrEmpty(dialog.FileName))
+ {
+ MenuProgramPathText = dialog.FileName;
+ }
+ }
+
+ ///
+ /// 菜单参数内容发生更改时的事件
+ ///
+ private void OnMenuParameterTextChanged(object sender, TextChangedEventArgs args)
+ {
+ MenuParameterText = (sender as global::Windows.UI.Xaml.Controls.TextBox).Text;
+ }
+
+ ///
+ /// 修改菜单文件匹配规则
+ ///
+ private void OnFileMatchRuleClicked(object sender, RoutedEventArgs args)
+ {
+ ToggleMenuFlyoutItem item = sender as ToggleMenuFlyoutItem;
+ if (item.Tag is not null)
+ {
+ SelectedFileMatchRule = FileMatchRuleList[Convert.ToInt32(item.Tag)];
+
+ if (SelectedFileMatchRule.Equals(FileMatchRuleList[0]) || SelectedFileMatchRule.Equals(4))
+ {
+ NeedInputMatchFormat = false;
+ MenuFileMatchFormatPHText = string.Empty;
+ }
+ else if (SelectedFileMatchRule.Equals(FileMatchRuleList[1]))
+ {
+ NeedInputMatchFormat = true;
+ MenuFileMatchFormatPHText = ShellMenu.MenuFileNameFormat;
+ }
+ else if (SelectedFileMatchRule.Equals(FileMatchRuleList[2]))
+ {
+ NeedInputMatchFormat = true;
+ MenuFileMatchFormatPHText = ShellMenu.MenuFileNameRegexFormat;
+ }
+ else if (SelectedFileMatchRule.Equals(FileMatchRuleList[3]))
+ {
+ NeedInputMatchFormat = true;
+ MenuFileMatchFormatPHText = ShellMenu.MenuFileExtensionFormat;
+ }
+ }
+ }
+
+ ///
+ /// 菜单文件匹配格式内容发生更改时的事件
+ ///
+ private void OnMenuFileMatchFormatTextChanged(object sender, TextChangedEventArgs args)
+ {
+ MenuFileMatchFormatText = (sender as global::Windows.UI.Xaml.Controls.TextBox).Text;
+ }
+
+ #endregion 第二部分:根菜单页面——挂载的事件
+
+ ///
+ /// 添加菜单项信息
+ ///
+ public void AddShellMenu(Guid menuGuid)
+ {
+ editMenuGuid = menuGuid;
+ selectedDefaultIconPath = string.Empty;
+ selectedLightThemeIconPath = string.Empty;
+ selectedDarkThemeIconPath = string.Empty;
+ MenuTitleText = string.Empty;
+ ShouldUseProgramIcon = true;
+ ShouldEnableThemeIcon = true;
+ DefaultIconPath = string.Empty;
+ LightThemeIconPath = string.Empty;
+ DarkThemeIconPath = string.Empty;
+ MenuProgramPathText = string.Empty;
+ MenuParameterText = string.Empty;
+ FolderBackgroundMatch = false;
+ FolderDesktopMatch = false;
+ FolderDirectoryMatch = false;
+ FolderDriveMatch = false;
+ SelectedFileMatchRule = FileMatchRuleList[4];
+ NeedInputMatchFormat = false;
+ MenuFileMatchFormatPHText = string.Empty;
+ MenuFileMatchFormatText = string.Empty;
+ }
+
+ ///
+ /// 检索设置中的菜单项信息
+ ///
+ public void QueryShellMenu(Guid menuGuid)
+ {
+ editMenuGuid = menuGuid;
+
+ Task.Run(() =>
+ {
+ // 检索窗口信息
+
+ synchronizationContext.Post(_ =>
+ {
+ }, null);
+ });
+ }
+
+ ///
+ /// 保存修改后的菜单项信息
+ ///
+ public void SaveSettingsInformation()
+ {
+ }
}
}
diff --git a/WindowsTools/Views/Pages/SimulateUpdatePage.xaml.cs b/WindowsTools/Views/Pages/SimulateUpdatePage.xaml.cs
index 01247d5..02fc874 100644
--- a/WindowsTools/Views/Pages/SimulateUpdatePage.xaml.cs
+++ b/WindowsTools/Views/Pages/SimulateUpdatePage.xaml.cs
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using System.Diagnostics.Tracing;
+using System.Threading;
using System.Timers;
using Windows.UI.Xaml.Controls;
using WindowsTools.Extensions.DataType.Enums;
@@ -15,7 +16,8 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class SimulateUpdatePage : Page, INotifyPropertyChanged
{
- private Timer simulateUpdateTimer = new();
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
+ private System.Timers.Timer simulateUpdateTimer = new();
private readonly int simulateTotalTime = 0;
private int simulatePassedTime = 0;
@@ -84,17 +86,20 @@ private void OnElapsed(object sender, ElapsedEventArgs args)
// 到达约定时间,自动停止
if (simulatePassedTime > simulateTotalTime)
{
- LoafWindow.Current.BeginInvoke(LoafWindow.Current.StopLoaf);
+ synchronizationContext.Post(_ =>
+ {
+ LoafWindow.Current.StopLoaf();
+ }, null);
return;
}
- LoafWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
string percentage = ((double)simulatePassedTime / simulateTotalTime).ToString("0%");
Windows11UpdateText = string.Format(SimulateUpdate.Windows11UpdateText1, percentage);
Windows10UpdateText = string.Format(SimulateUpdate.Windows10UpdateText1, percentage);
- });
+ }, null);
}
catch (Exception e)
{
diff --git a/WindowsTools/Views/Pages/UpdateManagerPage.xaml.cs b/WindowsTools/Views/Pages/UpdateManagerPage.xaml.cs
index 107c23b..36e92df 100644
--- a/WindowsTools/Views/Pages/UpdateManagerPage.xaml.cs
+++ b/WindowsTools/Views/Pages/UpdateManagerPage.xaml.cs
@@ -8,6 +8,7 @@
using System.Diagnostics.Tracing;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -19,7 +20,6 @@
using WindowsTools.Services.Root;
using WindowsTools.Strings;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
using WindowsTools.WindowsAPI.ComTypes;
using WUApiLib;
@@ -33,6 +33,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class UpdateManagerPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly UpdateSession updateSession = new();
private readonly UpdateServiceManager updateServiceManager = new();
private readonly IUpdateSearcher updateSearcher;
@@ -270,7 +271,7 @@ private void OnAvailableHideExecuteRequested(XamlUICommand sender, ExecuteReques
{
updateItem.Update.IsHidden = true;
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
try
{
@@ -292,7 +293,7 @@ private void OnAvailableHideExecuteRequested(XamlUICommand sender, ExecuteReques
{
LogService.WriteLog(EventLevel.Error, "Hide updates update UI failed", e);
}
- });
+ }, null);
}
catch (Exception e)
{
@@ -334,7 +335,7 @@ private void OnInstalledUnInstallExecuteRequested(XamlUICommand sender, ExecuteR
installationProgressChangedCallback.InstallationProgressChanged += (sender, args) =>
{
double percentage = installationProgressChangedCallback.CallbackArgs.Progress.CurrentUpdatePercentComplete / 100.0;
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (UpdateModel installedItem in InstalledUpdateCollection)
{
@@ -343,7 +344,7 @@ private void OnInstalledUnInstallExecuteRequested(XamlUICommand sender, ExecuteR
installedItem.InstallationProgress = percentage;
}
}
- });
+ }, null);
};
updateInstaller.BeginUninstall(installationProgressChangedCallback, installationCompletedCallback, null);
}
@@ -367,7 +368,7 @@ private void OnHiddenShowExecuteRequested(XamlUICommand sender, ExecuteRequested
{
updateItem.Update.IsHidden = false;
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
try
{
@@ -389,7 +390,7 @@ private void OnHiddenShowExecuteRequested(XamlUICommand sender, ExecuteRequested
{
LogService.WriteLog(EventLevel.Error, "Show updates update UI failed", e);
}
- });
+ }, null);
}
catch (Exception e)
{
@@ -417,11 +418,11 @@ private void OnCopyInformationExecuteRequested(XamlUICommand sender, ExecuteRequ
copyInformationBuilder.AppendLine(UpdateManager.Description);
copyInformationBuilder.AppendLine(updateModel.Description);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
bool copyResult = CopyPasteHelper.CopyToClipboard(copyInformationBuilder.ToString());
TeachingTipHelper.Show(new DataCopyTip(DataCopyKind.UpdateInformation, copyResult));
- });
+ }, null);
});
}
}
@@ -513,7 +514,7 @@ private void OnAvailableHideClicked(object sender, RoutedEventArgs args)
}
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (UpdateModel hideItem in hideList)
{
@@ -541,7 +542,7 @@ private void OnAvailableHideClicked(object sender, RoutedEventArgs args)
LogService.WriteLog(EventLevel.Error, "Hide updates update UI failed", e);
}
}
- });
+ }, null);
}
});
}
@@ -632,7 +633,7 @@ private void OnHiddenShowClicked(object sender, RoutedEventArgs args)
}
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
foreach (UpdateModel showItem in showList)
{
@@ -660,7 +661,7 @@ private void OnHiddenShowClicked(object sender, RoutedEventArgs args)
LogService.WriteLog(EventLevel.Error, "Show updates update UI failed", e);
}
}
- });
+ }, null);
}
});
}
@@ -696,10 +697,10 @@ private void OnExcludeDriversToggled(object sender, RoutedEventArgs args)
}
catch (Exception e)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsExcludeDrivers = !IsExcludeDrivers;
- });
+ }, null);
LogService.WriteLog(EventLevel.Warning, "Set exclude driver options failed", e);
}
});
@@ -771,13 +772,13 @@ private void OnSearchCompleted(object sender, EventArgs args)
LogService.WriteLog(EventLevel.Error, "Unregister SearchCompletedCallback SearchCompleted event failed", ex);
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsChecking = false;
IsAUExpanderExpanded = true;
IsIUExpanderExpanded = true;
IsHUExpanderExpanded = true;
- });
+ }, null);
return;
}
@@ -832,7 +833,7 @@ private void OnSearchCompleted(object sender, EventArgs args)
}
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
AvailableUpdateCollection.Clear();
foreach (UpdateModel updateItem in availableUpdateList)
@@ -856,7 +857,7 @@ private void OnSearchCompleted(object sender, EventArgs args)
IsAUExpanderExpanded = true;
IsIUExpanderExpanded = true;
IsHUExpanderExpanded = true;
- });
+ }, null);
GetUpdateHistory();
}
@@ -894,13 +895,13 @@ private void CheckUpdate()
catch (Exception e)
{
LogService.WriteLog(EventLevel.Error, "Search update failed", e);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsChecking = false;
IsAUExpanderExpanded = true;
IsIUExpanderExpanded = true;
IsHUExpanderExpanded = true;
- });
+ }, null);
}
});
}
@@ -924,7 +925,7 @@ private void GetUpdateHistory()
{
string status = GetStatus(updateHistoryEntry.ResultCode, updateHistoryEntry.HResult);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
UpdateHistoryCollection.Add(new UpdateModel()
{
@@ -936,15 +937,15 @@ private void GetUpdateHistory()
SupportURL = updateHistoryEntry.SupportUrl,
Status = status
});
- });
+ }, null);
}
}
}
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsUHExpanderExpanded = true;
- });
+ }, null);
});
}
diff --git a/WindowsTools/Views/Pages/UpperAndLowerCasePage.xaml.cs b/WindowsTools/Views/Pages/UpperAndLowerCasePage.xaml.cs
index 92b56c2..cd39c74 100644
--- a/WindowsTools/Views/Pages/UpperAndLowerCasePage.xaml.cs
+++ b/WindowsTools/Views/Pages/UpperAndLowerCasePage.xaml.cs
@@ -4,6 +4,7 @@
using System.ComponentModel;
using System.Diagnostics.Tracing;
using System.IO;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.ApplicationModel.DataTransfer;
@@ -21,7 +22,6 @@
using WindowsTools.Strings;
using WindowsTools.UI.Dialogs;
using WindowsTools.UI.TeachingTips;
-using WindowsTools.Views.Windows;
// 抑制 IDE0060 警告
#pragma warning disable IDE0060
@@ -33,6 +33,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class UpperAndLowerCasePage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly object upperAndLowerCaseLock = new();
private bool _isModifyingNow = false;
@@ -452,7 +453,7 @@ private async void OnViewErrorInformationClicked(object sender, RoutedEventArgs
///
public void AddtoUpperAndLowerCasePage(List upperAndLowerCaseList)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
lock (upperAndLowerCaseLock)
{
@@ -461,7 +462,7 @@ public void AddtoUpperAndLowerCasePage(List upperAndLowerCas
UpperAndLowerCaseCollection.Add(oldAndNewNameItem);
}
}
- });
+ }, null);
}
///
@@ -663,7 +664,7 @@ private void ChangeFileName()
await Task.Delay(300);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
IsModifyingNow = false;
foreach (OperationFailedModel operationFailedItem in operationFailedList)
@@ -677,7 +678,7 @@ private void ChangeFileName()
UpperAndLowerCaseCollection.Clear();
}
- });
+ }, null);
});
}
}
diff --git a/WindowsTools/Views/Pages/WinSATPage.xaml b/WindowsTools/Views/Pages/WinSATPage.xaml
index a1893fb..aa292cc 100644
--- a/WindowsTools/Views/Pages/WinSATPage.xaml
+++ b/WindowsTools/Views/Pages/WinSATPage.xaml
@@ -7,7 +7,6 @@
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:helper="using:WindowsTools.Helpers.Converters"
xmlns:string="using:WindowsTools.Strings"
- Loaded="{x:Bind OnLoaded}"
NavigationCacheMode="Enabled"
mc:Ignorable="d">
diff --git a/WindowsTools/Views/Pages/WinSATPage.xaml.cs b/WindowsTools/Views/Pages/WinSATPage.xaml.cs
index 863cc71..e404f21 100644
--- a/WindowsTools/Views/Pages/WinSATPage.xaml.cs
+++ b/WindowsTools/Views/Pages/WinSATPage.xaml.cs
@@ -4,12 +4,12 @@
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.IO;
+using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using WindowsTools.Services.Root;
using WindowsTools.Strings;
-using WindowsTools.Views.Windows;
using WindowsTools.WindowsAPI.ComTypes;
using WINSATLib;
@@ -23,6 +23,7 @@ namespace WindowsTools.Views.Pages
///
public sealed partial class WinSATPage : Page, INotifyPropertyChanged
{
+ private readonly SynchronizationContext synchronizationContext = SynchronizationContext.Current;
private readonly CInitiateWinSAT cInitiateWinSAT = new();
private readonly Guid progressDialogCLSID = new("F8383852-FCD3-11d1-A6B9-006097DF5BD4");
@@ -195,18 +196,11 @@ public string ResultMessage
public WinSATPage()
{
InitializeComponent();
+ GetWinSATInfo();
}
#region 第一部分:系统评估页面——挂载的事件
- ///
- /// 初始化系统评估信息
- ///
- private void OnLoaded(object sender, RoutedEventArgs args)
- {
- GetWinSATInfo();
- }
-
///
/// 运行评估
///
@@ -275,7 +269,7 @@ private void OnStatusUpdated(object sender, EventArgs args)
{
if (cWinSATCallbacks is not null && progressDialog is not null)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
try
{
@@ -302,7 +296,7 @@ private void OnStatusUpdated(object sender, EventArgs args)
progressDialog = null;
IsNotRunningAssessment = true;
}
- });
+ }, null);
}
}
@@ -313,7 +307,7 @@ private void OnStatusCompleted(object sender, EventArgs args)
{
if (cWinSATCallbacks is not null && progressDialog is not null)
{
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
try
{
@@ -332,7 +326,7 @@ private void OnStatusCompleted(object sender, EventArgs args)
progressDialog = null;
IsNotRunningAssessment = true;
}
- });
+ }, null);
}
}
@@ -363,7 +357,7 @@ private void GetWinSATInfo()
primaryDiskSubScore = queryWinSAT.Info.GetAssessmentInfo(WINSAT_ASSESSMENT_TYPE.WINSAT_ASSESSMENT_DISK).Score;
dynamic assessmentDate = queryWinSAT.Info.AssessmentDateTime;
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
BasicScoreExisted = basicScore is not 0.0;
BasicScore = basicScore is 0.0 ? "N/A" : basicScore.ToString("F1");
@@ -374,12 +368,12 @@ private void GetWinSATInfo()
PrimaryDiskSubScore = primaryDiskSubScore is 0.0 ? "N/A" : primaryDiskSubScore.ToString("F1");
ResultMessage = basicScore is 0.0 ? WinSAT.ErrorMessage : string.Format(WinSAT.SuccessMessage, assessmentDate);
ResultServerity = basicScore is 0.0 ? InfoBarSeverity.Warning : InfoBarSeverity.Success;
- });
+ }, null);
}
catch (Exception e)
{
LogService.WriteLog(EventLevel.Error, "Query WinSAT score failed", e);
- MainWindow.Current.BeginInvoke(() =>
+ synchronizationContext.Post(_ =>
{
BasicScoreExisted = false;
BasicScore = "N/A";
@@ -390,7 +384,7 @@ private void GetWinSATInfo()
PrimaryDiskSubScore = "N/A";
ResultMessage = WinSAT.ErrorMessage;
ResultServerity = InfoBarSeverity.Warning;
- });
+ }, null);
}
});
}
diff --git a/WindowsTools/WindowsAPI/ComTypes/ACTIVATEOPTIONS.cs b/WindowsTools/WindowsAPI/ComTypes/ACTIVATEOPTIONS.cs
new file mode 100644
index 0000000..5c546f5
--- /dev/null
+++ b/WindowsTools/WindowsAPI/ComTypes/ACTIVATEOPTIONS.cs
@@ -0,0 +1,34 @@
+namespace WindowsTools.WindowsAPI.ComTypes
+{
+ ///
+ /// 以下一个或多个标志用于支持设计模式、调试和测试方案。
+ ///
+ public enum ACTIVATEOPTIONS
+ {
+ ///
+ /// 不设置任何标志。
+ ///
+ AO_NONE = 0x00000000,
+
+ ///
+ /// 应用正在为设计模式激活,因此无法创建其正常窗口。 应用窗口的创建必须由设计工具完成,这些工具通过与通过激活管理器建立的站点链上的设计器指定的服务通信来加载必要的组件。 请注意,这意味着在常规激活期间看不到初始屏幕。
+ /// 请注意,必须在应用的包上 启用调试模式 才能成功使用设计模式。
+ ///
+ AO_DESIGNMODE = 0x00000001,
+
+ ///
+ /// 如果应用无法激活,则不显示错误对话框。
+ ///
+ AO_NOERRORUI = 0x00000002,
+
+ ///
+ /// 激活应用时,不要显示应用的初始屏幕。 使用此标志时,必须在应用的包上 启用调试模式 ;否则,PLM 将在几秒钟后终止应用。
+ ///
+ AO_NOSPLASHSCREEN = 0x00000004,
+
+ ///
+ /// 应用程序正在预启动模式下激活。 从 Windows 10 开始支持此值。
+ ///
+ AO_PRELAUNCH = 0x2000000
+ }
+}
diff --git a/WindowsTools/WindowsAPI/ComTypes/BackgroundCopyCallback.cs b/WindowsTools/WindowsAPI/ComTypes/BackgroundCopyCallback.cs
index 421db63..386ab9a 100644
--- a/WindowsTools/WindowsAPI/ComTypes/BackgroundCopyCallback.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/BackgroundCopyCallback.cs
@@ -15,22 +15,25 @@ public class BackgroundCopyCallback : IBackgroundCopyCallback
///
public event Action StatusChanged;
- public void JobTransferred([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob)
+ public int JobTransferred([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob)
{
pJob.GetState(out BG_JOB_STATE state);
StatusChanged?.Invoke(this, pJob, state);
+ return 0;
}
- public void JobError([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob, [MarshalAs(UnmanagedType.Interface)] IBackgroundCopyError pError)
+ public int JobError([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob, [MarshalAs(UnmanagedType.Interface)] IBackgroundCopyError pError)
{
pJob.GetState(out BG_JOB_STATE state);
StatusChanged?.Invoke(this, pJob, state);
+ return 0;
}
- public void JobModification([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob, uint dwReserved)
+ public int JobModification([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob, uint dwReserved)
{
pJob.GetState(out BG_JOB_STATE state);
StatusChanged?.Invoke(this, pJob, state);
+ return 0;
}
}
}
diff --git a/WindowsTools/WindowsAPI/ComTypes/DODownloadStatusCallback.cs b/WindowsTools/WindowsAPI/ComTypes/DODownloadStatusCallback.cs
index e1d7229..decf9c2 100644
--- a/WindowsTools/WindowsAPI/ComTypes/DODownloadStatusCallback.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/DODownloadStatusCallback.cs
@@ -15,9 +15,10 @@ public class DODownloadStatusCallback : IDODownloadStatusCallback
///
public event Action StatusChanged;
- public void OnStatusChange([MarshalAs(UnmanagedType.Interface)] IDODownload download, ref DO_DOWNLOAD_STATUS status)
+ public int OnStatusChange([MarshalAs(UnmanagedType.Interface)] IDODownload download, ref DO_DOWNLOAD_STATUS status)
{
StatusChanged?.Invoke(this, download, status);
+ return 0;
}
}
}
diff --git a/WindowsTools/WindowsAPI/ComTypes/IApplicationActivationManager.cs b/WindowsTools/WindowsAPI/ComTypes/IApplicationActivationManager.cs
new file mode 100644
index 0000000..4cf2643
--- /dev/null
+++ b/WindowsTools/WindowsAPI/ComTypes/IApplicationActivationManager.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsTools.WindowsAPI.ComTypes
+{
+ [ComImport, Guid("2e941141-7f97-4756-ba1d-9decde894a3d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IApplicationActivationManager
+ {
+ ///
+ /// 为当前会话中的 Windows.Launch) (通用启动协定激活指定的 Windows 应用商店应用。
+ ///
+ /// Windows 应用商店应用的应用程序用户模型 ID。
+ /// 指向特定于应用的可选参数字符串的指针。
+ /// 以下一个或多个标志用于支持设计模式、调试和测试方案。
+ /// 指向一个值的指针,当此方法成功返回时,该值接收满足此协定的应用实例的进程 ID。
+ /// 如果该方法成功,则返回 S_OK。 否则,将返回 HRESULT 错误代码。
+ int ActivateApplication([MarshalAs(UnmanagedType.LPWStr)] in string appUserModelId, [MarshalAs(UnmanagedType.LPWStr)] in string arguments, in ACTIVATEOPTIONS options, out uint processId);
+
+ ///
+ /// 为文件协定激活指定的 Windows 应用商店应用 (Windows.File) 。
+ ///
+ /// Windows 应用商店应用的应用程序用户模型 ID。
+ /// 指向 Shell 项数组的指针,每个项表示一个文件。 此值转换为通过 FileActivatedEventArgs 传递给应用的 StorageItem 对象的 VectorView。
+ /// 应用于 itemArray 指定的一个或多个文件的谓词。
+ /// 指向一个值的指针,该值在此方法成功返回时接收满足此协定的应用实例的进程 ID。
+ /// 如果该方法成功,则返回 S_OK。 否则,将返回 HRESULT 错误代码。
+ int ActivateForFile([MarshalAs(UnmanagedType.LPWStr)] in string appUserModelId, in IntPtr itemArray, [MarshalAs(UnmanagedType.LPWStr)] in string verb, out uint processId);
+
+ ///
+ /// 为 Windows.Protocol 协议协定激活指定的 Windows 应用商店应用。
+ ///
+ /// Windows 应用商店应用的应用程序用户模型 ID。
+ /// 指向单个 Shell 项数组的指针。 数组中的第一项将转换为 Uri 对象,该对象通过 ProtocolActivatedEventArgs 传递给应用。 数组中除第一个元素之外的所有项都被忽略。
+ /// 指向一个值的指针,该值在此方法成功返回时接收满足此协定的应用实例的进程 ID。
+ /// 如果该方法成功,则返回 S_OK。 否则,将返回 HRESULT 错误代码。
+ int ActivateForProtocol([MarshalAs(UnmanagedType.LPWStr)] in string appUserModelId, in IntPtr itemArray, out uint processId);
+ }
+}
diff --git a/WindowsTools/WindowsAPI/ComTypes/IBackgroundCopyCallback.cs b/WindowsTools/WindowsAPI/ComTypes/IBackgroundCopyCallback.cs
index 180fd83..cc2d813 100644
--- a/WindowsTools/WindowsAPI/ComTypes/IBackgroundCopyCallback.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/IBackgroundCopyCallback.cs
@@ -17,7 +17,8 @@ public interface IBackgroundCopyCallback
/// 此方法应返回 S_OK;否则,BITS 将继续调用此方法,直到返回 S_OK 。 出于性能原因,应将返回除 S_OK 以外的值的次数限制为多次。 作为返回错误代码的替代方法,请考虑始终返回 S_OK 并在内部处理错误。 调用此方法的间隔是任意的。
/// 请注意,如果此方法失败,并且你调用 了 IBackgroundCopyJob2::SetNotifyCmdLine 方法,则执行命令行,并且不会再次调用此方法。
///
- void JobTransferred([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob);
+ [PreserveSig]
+ int JobTransferred([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob);
///
/// 当作业的状态更改为BG_JOB_STATE_ERROR时,BITS 调用 JobError 方法的实现。
@@ -28,7 +29,8 @@ public interface IBackgroundCopyCallback
/// 此方法应返回 S_OK;否则,BITS 会继续调用此方法,直到返回 S_OK 。 出于性能原因,应将返回 非S_OK 值的次数限制为几次。 作为返回错误代码的替代方法,请考虑始终返回 S_OK 并在内部处理错误。 调用此方法的间隔是任意的。
/// 请注意,如果此方法失败,并且你调用 了 IBackgroundCopyJob2::SetNotifyCmdLine 方法,则会执行命令行,并且不会再次调用此方法。
///
- void JobError([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob, [MarshalAs(UnmanagedType.Interface)] IBackgroundCopyError pError);
+ [PreserveSig]
+ int JobError([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob, [MarshalAs(UnmanagedType.Interface)] IBackgroundCopyError pError);
///
/// 修改作业后,BITS 会调用 JobModification 方法的实现。 当传输字节、文件已添加到作业、修改属性或作业状态更改时,服务将生成此事件。
@@ -36,6 +38,6 @@ public interface IBackgroundCopyCallback
/// 包含用于访问作业的属性、进度和状态信息的方法。 不释放 pJob; 当 JobModification 方法返回时,BITS 释放接口。
/// 保留供将来使用。
/// 此方法应返回 S_OK。
- void JobModification([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob, uint dwReserved);
+ [PreserveSig] int JobModification([MarshalAs(UnmanagedType.Interface)] IBackgroundCopyJob pJob, uint dwReserved);
}
}
diff --git a/WindowsTools/WindowsAPI/ComTypes/IDODownloadStatusCallback.cs b/WindowsTools/WindowsAPI/ComTypes/IDODownloadStatusCallback.cs
index 9b7c94b..bb008df 100644
--- a/WindowsTools/WindowsAPI/ComTypes/IDODownloadStatusCallback.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/IDODownloadStatusCallback.cs
@@ -15,6 +15,7 @@ public interface IDODownloadStatusCallback
/// 指向其状态更改的 IDODownload 接口的指针。
/// 指向包含下载状态 的DO_DOWNLOAD_STATUS 结构的指针。
/// 如果函数成功,则返回 S_OK。 否则,它将返回 HRESULT错误代码。
- void OnStatusChange([MarshalAs(UnmanagedType.Interface)] IDODownload download, ref DO_DOWNLOAD_STATUS status);
+ [PreserveSig]
+ int OnStatusChange([MarshalAs(UnmanagedType.Interface)] IDODownload download, ref DO_DOWNLOAD_STATUS status);
}
}
diff --git a/WindowsTools/WindowsAPI/ComTypes/IDOManager.cs b/WindowsTools/WindowsAPI/ComTypes/IDOManager.cs
index c4c43ae..505890a 100644
--- a/WindowsTools/WindowsAPI/ComTypes/IDOManager.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/IDOManager.cs
@@ -26,7 +26,7 @@ public interface IDOManager
/// DODownloadProperty_LocalPath
///
/// 指向 IEnumUnknown 的接口指针的地址,用于枚举现有下载。 枚举器的内容取决于 类别的值。 枚举接口中包含的下载是以前由此函数的同一调用方创建的下载。
- [return: MarshalAs(UnmanagedType.Interface)]
- IntPtr EnumDownloads(IntPtr category);
+ [PreserveSig]
+ int EnumDownloads(DODownloadProperty category, out IntPtr ppEnum);
}
}
diff --git a/WindowsTools/WindowsAPI/ComTypes/IDataTransferManagerInterop.cs b/WindowsTools/WindowsAPI/ComTypes/IDataTransferManagerInterop.cs
index f3e3e5c..31adce0 100644
--- a/WindowsTools/WindowsAPI/ComTypes/IDataTransferManagerInterop.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/IDataTransferManagerInterop.cs
@@ -16,12 +16,14 @@ public interface IDataTransferManagerInterop
/// 要检索其 DataTransferManager 实例的窗口。
/// DataTransferManager 实例的请求接口 ID。
/// 接收 DataTransferManager 实例。
- DataTransferManager GetForWindow(IntPtr appWindow, ref Guid riid);
+ [PreserveSig]
+ int GetForWindow(IntPtr appWindow, ref Guid riid, out DataTransferManager dataTransferManager);
///
/// 显示用于共享指定窗口内容的 UI。
///
/// 要为其显示共享 UI 的窗口。
- void ShowShareUIForWindow(IntPtr appWindow);
+ [PreserveSig]
+ int ShowShareUIForWindow(IntPtr appWindow);
}
}
diff --git a/WindowsTools/WindowsAPI/ComTypes/IPinnedList3.cs b/WindowsTools/WindowsAPI/ComTypes/IPinnedList3.cs
index 87c46b2..050d113 100644
--- a/WindowsTools/WindowsAPI/ComTypes/IPinnedList3.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/IPinnedList3.cs
@@ -30,9 +30,7 @@ public interface IPinnedList3
/// 标记固定项是否可启动
/// 如果项目不是可固定的,返回 S_FALSE
[PreserveSig]
- int GetPinnableInfo(IDataObject dataObject, int pinnableFlag,
- [Out] out IntPtr ppsiApplication, [Out] out IntPtr ppsiDestination,
- [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder ppszAppID, [Out] uint pfLaunchable);
+ int GetPinnableInfo(IDataObject dataObject, int pinnableFlag, [Out] out IntPtr ppsiApplication, [Out] out IntPtr ppsiDestination, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder ppszAppID, [Out] uint pfLaunchable);
///
/// 数据对象是否可固定的标志
diff --git a/WindowsTools/WindowsAPI/ComTypes/IProgressDialog.cs b/WindowsTools/WindowsAPI/ComTypes/IProgressDialog.cs
index a2f90d7..75248b3 100644
--- a/WindowsTools/WindowsAPI/ComTypes/IProgressDialog.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/IProgressDialog.cs
@@ -19,20 +19,20 @@ public interface IProgressDialog
/// 控制进度对话框操作的标志。
/// 保留。 设置为 NULL。
[PreserveSig]
- void StartProgressDialog(IntPtr hwndParent, [MarshalAs(UnmanagedType.IUnknown)] object punkEnableModless, PROGDLG dwFlags, IntPtr pvResevered);
+ int StartProgressDialog(IntPtr hwndParent, [MarshalAs(UnmanagedType.IUnknown)] object punkEnableModless, PROGDLG dwFlags, IntPtr pvResevered);
///
/// 停止进度对话框并将其从屏幕中删除。
///
[PreserveSig]
- void StopProgressDialog();
+ int StopProgressDialog();
///
/// 设置进度对话框的标题。
///
/// 指向包含对话框标题的以 null 结尾的 Unicode 字符串的指针。
[PreserveSig]
- void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pwzTitle);
+ int SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pwzTitle);
///
/// 指定在对话框中运行的 Audio-Video 交错 (AVI) 剪辑。
@@ -40,7 +40,7 @@ public interface IProgressDialog
/// 应从中加载 AVI 资源的模块的实例句柄。
/// AVI 资源标识符。 若要创建此值,请使用 MAKEINTRESOURCE 宏。 控件从 hInstAnimation 指定的模块加载 AVI 资源。
[PreserveSig]
- void SetAnimation(IntPtr hInstAnimation, uint idAnimation);
+ int SetAnimation(IntPtr hInstAnimation, uint idAnimation);
///
/// 检查用户是否已取消操作。
@@ -56,7 +56,7 @@ public interface IProgressDialog
/// 应用程序定义的值,指示调用方法时已完成的操作比例。
/// 应用程序定义的值,指定当操作完成时 dwCompleted 将具有的值。
[PreserveSig]
- void SetProgress(uint dwCompleted, uint dwTotal);
+ int SetProgress(uint dwCompleted, uint dwTotal);
///
/// 汇报包含操作的当前状态的进度对话框。
@@ -64,7 +64,7 @@ public interface IProgressDialog
/// 一个应用程序定义的值,指示调用方法时已完成操作的比例。
/// 一个应用程序定义的值,该值指定操作完成时 ullCompleted 将具有的值。
[PreserveSig]
- void SetProgress64(ulong ullCompleted, ulong ullTotal);
+ int SetProgress64(ulong ullCompleted, ulong ullTotal);
///
/// 在进度对话框中显示一条消息。
@@ -76,7 +76,7 @@ public interface IProgressDialog
/// 如果 路径字符串太大而无法容纳在行上,则为 TRUE。 路径使用 PathCompactPath 进行压缩。
/// 保留。 设置为 NULL。
[PreserveSig]
- void SetLine(uint dwLineNum, [MarshalAs(UnmanagedType.LPWStr)] string pwzString, [MarshalAs(UnmanagedType.VariantBool)] bool fCompactPath, IntPtr pvResevered);
+ int SetLine(uint dwLineNum, [MarshalAs(UnmanagedType.LPWStr)] string pwzString, [MarshalAs(UnmanagedType.VariantBool)] bool fCompactPath, IntPtr pvResevered);
///
/// 设置在用户取消操作时要显示的消息。
@@ -84,7 +84,7 @@ public interface IProgressDialog
/// 指向以 null 结尾的 Unicode 字符串的指针,该字符串包含要显示的消息。
/// 保留。 设置为 NULL。
[PreserveSig]
- void SetCancelMsg([MarshalAs(UnmanagedType.LPWStr)] string pwzCancelMsg, object pvResevered);
+ int SetCancelMsg([MarshalAs(UnmanagedType.LPWStr)] string pwzCancelMsg, object pvResevered);
///
/// 将进度对话框计时器重置为零。
@@ -92,6 +92,6 @@ public interface IProgressDialog
/// 指示计时器要执行的操作的标志。
/// 保留。 设置为 NULL。
[PreserveSig]
- void Timer(PDTIMER dwTimerAction, object pvResevered);
+ int Timer(PDTIMER dwTimerAction, object pvResevered);
}
}
diff --git a/WindowsTools/WindowsAPI/ComTypes/IShellLink.cs b/WindowsTools/WindowsAPI/ComTypes/IShellLink.cs
index cfdb83e..2a0b8f6 100644
--- a/WindowsTools/WindowsAPI/ComTypes/IShellLink.cs
+++ b/WindowsTools/WindowsAPI/ComTypes/IShellLink.cs
@@ -17,21 +17,21 @@ public interface IShellLink
/// 指向 结构的指针,该结构接收有关 Shell 链接对象的目标的信息。 如果此参数为 NULL,则不会返回其他信息。
/// 指定要检索的路径信息的类型的标志。
[PreserveSig]
- void GetPath([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszFile, int cch, ref IntPtr pfd, uint fFlags);
+ int GetPath([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszFile, int cch, ref IntPtr pfd, uint fFlags);
///
/// 获取 Shell 链接对象目标的项目标识符列表。
///
/// 此方法返回时,包含 PIDL 的地址。
[PreserveSig]
- void GetIDList(out IntPtr ppidl);
+ int GetIDList(out IntPtr ppidl);
///
/// 设置指向命令行管理程序链接对象的项标识符列表 (PIDL) 的指针。
///
/// 对象的完全限定的 PIDL。
[PreserveSig]
- void SetIDList(IntPtr ppidl);
+ int SetIDList(IntPtr ppidl);
///
/// 获取 Shell 链接对象的说明字符串。
@@ -39,14 +39,14 @@ public interface IShellLink
///
/// 要复制到 参数指向的缓冲区的最大字符数。
[PreserveSig]
- void GetDescription([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszName, int cch);
+ int GetDescription([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszName, int cch);
///
/// 设置 Shell 链接对象的说明。 说明可以是任何应用程序定义的字符串。
///
/// 指向包含新说明字符串的缓冲区的指针。
[PreserveSig]
- void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
+ int SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
///
/// 获取 Shell 链接对象的工作目录的名称。
@@ -54,14 +54,14 @@ public interface IShellLink
/// 接收工作目录名称的缓冲区的地址。
/// 要复制到 参数指向的缓冲区的最大字符数。 如果工作目录的名称超过此参数指定的最大值,则将其截断。
[PreserveSig]
- void GetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszDir, int cch);
+ int GetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszDir, int cch);
///
/// 设置 Shell 链接对象的工作目录的名称。
///
/// 包含新工作目录名称的缓冲区的地址。
[PreserveSig]
- void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
+ int SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
///
/// 获取与 Shell 链接对象关联的命令行参数。
@@ -69,42 +69,42 @@ public interface IShellLink
/// 指向缓冲区的指针,当此方法成功返回时,接收命令行参数。
/// 可以复制到 参数提供的缓冲区的最大字符数。 对于 Unicode 字符串,最大字符串长度没有限制。 对于 ANSI 字符串,返回的字符串的最大长度因 Windows 版本而异,具体取决于 Windows 2000 之前的 MAX_PATH,在 Windows 2000 及更高版本中的 Commctrl.h) 中定义的 INFOTIPSIZE (。
[PreserveSig]
- void GetArguments([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszArgs, int cch);
+ int GetArguments([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszArgs, int cch);
///
/// 设置 Shell 链接对象的命令行参数。
///
/// 指向包含新命令行参数的缓冲区的指针。 对于 Unicode 字符串,最大字符串长度没有限制。 对于 ANSI 字符串,返回的字符串的最大长度因 Windows 版本而异,MAX_PATH Windows 2000 之前的 Windows 2000 和 INFOTIPSIZE (在 Windows 2000 及更高版本中定义的 Commctrl.h) 。
[PreserveSig]
- void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
+ int SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
///
/// 获取 Shell 链接对象的键盘快捷方式 (热键) 。
///
/// 键盘快捷方式的地址。 虚拟密钥代码采用低顺序字节,修饰符标志采用高阶字节。 修饰符标志可以是以下值的组合。
[PreserveSig]
- void GetHotkey(out ushort pwHotkey);
+ int GetHotkey(out ushort pwHotkey);
///
/// 设置 Shell 链接对象的键盘快捷方式 (热键) 。
///
/// 新的键盘快捷方式。 虚拟密钥代码采用低顺序字节,修饰符标志采用高阶字节。 修饰符标志可以是 方法说明中指定的值的组合。
[PreserveSig]
- void SetHotkey(ushort wHotkey);
+ int SetHotkey(ushort wHotkey);
///
/// 获取 Shell 链接对象的 show 命令。
///
/// 指向命令的指针。
[PreserveSig]
- void GetShowCmd(out int piShowCmd);
+ int GetShowCmd(out int piShowCmd);
///
/// 设置命令行管理程序链接对象的 show 命令。show 命令设置窗口的初始显示状态。
///
/// 命令。
[PreserveSig]
- void SetShowCmd(int iShowCmd);
+ int SetShowCmd(int iShowCmd);
///
/// 获取 Shell 链接对象的图标 (路径和索引) 的位置。
@@ -113,7 +113,7 @@ public interface IShellLink
/// 要复制到 参数指向的缓冲区的最大字符数。
/// 接收图标索引的值的地址。
[PreserveSig]
- void GetIconLocation([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszIconPath, int cch, out int piIcon);
+ int GetIconLocation([MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 1)] out string pszIconPath, int cch, out int piIcon);
///
/// 设置 Shell 链接对象的图标 (路径和索引) 的位置。
@@ -121,7 +121,7 @@ public interface IShellLink
/// 要包含包含图标的文件路径的缓冲区的地址。
/// 图标的索引。
[PreserveSig]
- void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
+ int SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
///
/// 设置 Shell 链接对象的相对路径。
@@ -129,7 +129,7 @@ public interface IShellLink
/// 包含快捷方式文件的完全限定路径的缓冲区的地址,相对于应执行快捷方式解析的缓冲区。 它应该是文件名,而不是文件夹名称。
/// 保留。 将此参数设置为零。
[PreserveSig]
- void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved);
+ int SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved);
///
/// 尝试查找 Shell 链接的目标,即使它已被移动或重命名也是如此。
@@ -137,13 +137,13 @@ public interface IShellLink
/// Shell 将用作对话框的父窗口的句柄。 如果 Shell 在解析 Shell 链接时需要提示用户获取详细信息,则 Shell 会显示对话框。
/// 操作标志。
[PreserveSig]
- void Resolve(IntPtr hwnd, uint fFlags);
+ int Resolve(IntPtr hwnd, uint fFlags);
///
/// 设置 Shell 链接对象目标的路径和文件名。
///
/// 包含新路径的缓冲区的地址。
[PreserveSig]
- void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
+ int SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}
}
diff --git a/WindowsToolsPackage/Package.appxmanifest b/WindowsToolsPackage/Package.appxmanifest
index 1ca94c3..0f7432f 100644
--- a/WindowsToolsPackage/Package.appxmanifest
+++ b/WindowsToolsPackage/Package.appxmanifest
@@ -13,7 +13,7 @@
+ Version="2.7.804.0" />
ms-resource:PackageDisplayName
diff --git a/WindowsToolsShellExtension/Properties/AssemblyInfo.cs b/WindowsToolsShellExtension/Properties/AssemblyInfo.cs
index 2af8d63..06af704 100644
--- a/WindowsToolsShellExtension/Properties/AssemblyInfo.cs
+++ b/WindowsToolsShellExtension/Properties/AssemblyInfo.cs
@@ -6,11 +6,11 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("Windows 工具箱 右键菜单扩展")]
-[assembly: AssemblyFileVersion("2.7.801.0")]
-[assembly: AssemblyInformationalVersion("2.7.801.0")]
+[assembly: AssemblyFileVersion("2.7.804.0")]
+[assembly: AssemblyInformationalVersion("2.7.804.0")]
[assembly: AssemblyProduct("Windows 工具箱 右键菜单扩展")]
[assembly: AssemblyTitle("Windows 工具箱 右键菜单扩展")]
-[assembly: AssemblyVersion("2.7.801.0")]
+[assembly: AssemblyVersion("2.7.804.0")]
// 应用程序默认区域性的资源控制器设置
[assembly: NeutralResourcesLanguage("en-us")]