diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index ce78c510..d75d8b58 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -1217,15 +1217,6 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"释放IACore DLL时出错: {ex.Message}", LogHelper.LogType.Error); } - try - { - UIAccessDllExtractor.ExtractUIAccessDlls(); - } - catch (Exception ex) - { - LogHelper.WriteLogToFile($"释放UIAccess DLL时出错: {ex.Message}", LogHelper.LogType.Error); - } - try { LogHelper.WriteLogToFile("开始注册.icstk文件关联"); diff --git a/Ink Canvas/Helpers/UIAccessDllExtractor.cs b/Ink Canvas/Helpers/UIAccessDllExtractor.cs deleted file mode 100644 index f9448167..00000000 --- a/Ink Canvas/Helpers/UIAccessDllExtractor.cs +++ /dev/null @@ -1,165 +0,0 @@ -using System; -using System.IO; -using System.Reflection; - -namespace Ink_Canvas.Helpers -{ - /// - /// UIAccess DLL释放器 - /// - public static class UIAccessDllExtractor - { - private static readonly string[] RequiredDlls = { - "UIAccessDLL_x64.dll", - "UIAccessDLL_x86.dll" - }; - - /// - /// 在应用启动时释放UIAccess相关DLL - /// - public static void ExtractUIAccessDlls() - { - try - { - string appDirectory = AppDomain.CurrentDomain.BaseDirectory; - LogHelper.WriteLogToFile("开始检查并释放UIAccess相关DLL文件"); - - foreach (string dllName in RequiredDlls) - { - string targetPath = Path.Combine(appDirectory, dllName); - - // 检查文件是否已存在且有效 - if (File.Exists(targetPath) && IsValidDll(targetPath)) - { - LogHelper.WriteLogToFile($"{dllName} 已存在且有效,跳过释放"); - continue; - } - - // 从嵌入资源中释放DLL - if (ExtractDllFromResource(dllName, targetPath)) - { - LogHelper.WriteLogToFile($"成功释放 {dllName} 到 {targetPath}"); - } - else - { - LogHelper.WriteLogToFile($"警告:无法释放 {dllName},可能影响UIA置顶功能", LogHelper.LogType.Warning); - } - } - - LogHelper.WriteLogToFile("UIAccess DLL释放检查完成"); - } - catch (Exception ex) - { - LogHelper.WriteLogToFile($"释放UIAccess DLL时出错: {ex.Message}", LogHelper.LogType.Error); - } - } - - /// - /// 从嵌入资源中提取DLL文件 - /// - private static bool ExtractDllFromResource(string dllName, string targetPath) - { - try - { - Assembly assembly = Assembly.GetExecutingAssembly(); - string resourceName = $"Ink_Canvas.{dllName}"; - - using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)) - { - if (resourceStream == null) - { - LogHelper.WriteLogToFile($"未找到嵌入资源: {resourceName}", LogHelper.LogType.Warning); - return false; - } - - // 确保目标目录存在 - string targetDirectory = Path.GetDirectoryName(targetPath); - if (!Directory.Exists(targetDirectory)) - { - Directory.CreateDirectory(targetDirectory); - } - - // 写入文件 - using (FileStream fileStream = new FileStream(targetPath, FileMode.Create, FileAccess.Write)) - { - resourceStream.CopyTo(fileStream); - } - - return true; - } - } - catch (Exception ex) - { - LogHelper.WriteLogToFile($"从资源提取 {dllName} 失败: {ex.Message}", LogHelper.LogType.Error); - return false; - } - } - - /// - /// 检查DLL文件是否有效 - /// - private static bool IsValidDll(string filePath) - { - try - { - if (!File.Exists(filePath)) - return false; - - FileInfo fileInfo = new FileInfo(filePath); - - // 检查文件大小(空文件或过小的文件可能无效) - if (fileInfo.Length < 1024) // 小于1KB可能无效 - return false; - - // 简单检查PE头(DLL文件应该以MZ开头) - using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) - { - byte[] buffer = new byte[2]; - if (fs.Read(buffer, 0, 2) == 2) - { - return buffer[0] == 0x4D && buffer[1] == 0x5A; // "MZ" - } - } - - return false; - } - catch - { - return false; - } - } - - /// - /// 清理释放的DLL文件(可选,在应用退出时调用) - /// - public static void CleanupExtractedDlls() - { - try - { - string appDirectory = AppDomain.CurrentDomain.BaseDirectory; - - foreach (string dllName in RequiredDlls) - { - string filePath = Path.Combine(appDirectory, dllName); - - if (File.Exists(filePath)) - { - try - { - File.Delete(filePath); - LogHelper.WriteLogToFile($"已清理 {dllName}"); - } - catch (Exception ex) - { - LogHelper.WriteLogToFile($"清理 {dllName} 失败: {ex.Message}", LogHelper.LogType.Warning); - } - } - } - } - catch (Exception ex) - { - LogHelper.WriteLogToFile($"清理UIAccess DLL时出错: {ex.Message}", LogHelper.LogType.Error); - } - } - } -} diff --git a/Ink Canvas/InkCanvasForClass.csproj b/Ink Canvas/InkCanvasForClass.csproj index 7e36dd91..fd79492b 100644 --- a/Ink Canvas/InkCanvasForClass.csproj +++ b/Ink Canvas/InkCanvasForClass.csproj @@ -191,8 +191,6 @@ - - diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 1c393a4f..b1b59dcd 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -39,12 +39,6 @@ namespace Ink_Canvas { public partial class MainWindow : Window { - [DllImport("UIAccessDLL_x86.dll", EntryPoint = "PrepareUIAccess", CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 PrepareUIAccessX86(); - - [DllImport("UIAccessDLL_x64.dll", EntryPoint = "PrepareUIAccess", CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 PrepareUIAccessX64(); - // 每一页一个Canvas对象 private List whiteboardPages = new List(); private int currentPageIndex; diff --git a/Ink Canvas/UIAccessDLL_x64.dll b/Ink Canvas/UIAccessDLL_x64.dll deleted file mode 100644 index 9edc84b8..00000000 Binary files a/Ink Canvas/UIAccessDLL_x64.dll and /dev/null differ diff --git a/Ink Canvas/UIAccessDLL_x86.dll b/Ink Canvas/UIAccessDLL_x86.dll deleted file mode 100644 index 48fe7e3e..00000000 Binary files a/Ink Canvas/UIAccessDLL_x86.dll and /dev/null differ