diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index c04eb9d3..8439db7a 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -439,6 +439,16 @@ namespace Ink_Canvas LogHelper.NewLog(string.Format("Ink Canvas Starting (Version: {0})", Assembly.GetExecutingAssembly().GetName().Version)); + // 在应用启动时自动释放IACore相关DLL + try + { + Helpers.IACoreDllExtractor.ExtractIACoreDlls(); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"释放IACore DLL时出错: {ex.Message}", LogHelper.LogType.Error); + } + // 记录应用启动(设备标识符) DeviceIdentifier.RecordAppLaunch(); LogHelper.WriteLogToFile($"App | 设备ID: {DeviceIdentifier.GetDeviceId()}"); diff --git a/Ink Canvas/Helpers/IACoreDllExtractor.cs b/Ink Canvas/Helpers/IACoreDllExtractor.cs new file mode 100644 index 00000000..de717826 --- /dev/null +++ b/Ink Canvas/Helpers/IACoreDllExtractor.cs @@ -0,0 +1,168 @@ +using System; +using System.IO; +using System.Reflection; +using System.Windows; + +namespace Ink_Canvas.Helpers +{ + /// + /// IACore DLL自动释放器 + /// 在应用启动时自动释放IACore相关的DLL文件到应用程序目录 + /// + public static class IACoreDllExtractor + { + private static readonly string[] RequiredDlls = { + "IACore.dll", + "IALoader.dll", + "IAWinFX.dll" + }; + + /// + /// 在应用启动时释放IACore相关DLL + /// + public static void ExtractIACoreDlls() + { + try + { + string appDirectory = AppDomain.CurrentDomain.BaseDirectory; + LogHelper.WriteLogToFile("开始检查并释放IACore相关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},可能影响形状识别功能", LogHelper.LogType.Warning); + } + } + + LogHelper.WriteLogToFile("IACore DLL释放检查完成"); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"释放IACore DLL时出错: {ex.Message}", LogHelper.LogType.Error); + } + } + + /// + /// 从嵌入资源中提取DLL文件 + /// + private static bool ExtractDllFromResource(string dllName, string targetPath) + { + try + { + Assembly assembly = Assembly.GetExecutingAssembly(); + string resourceName = $"Ink_Canvas.Resources.IACore.{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($"清理IACore DLL时出错: {ex.Message}", LogHelper.LogType.Error); + } + } + } +} diff --git a/Ink Canvas/InkCanvasForClass.csproj b/Ink Canvas/InkCanvasForClass.csproj index defa92d8..4c53cecb 100644 --- a/Ink Canvas/InkCanvasForClass.csproj +++ b/Ink Canvas/InkCanvasForClass.csproj @@ -113,15 +113,15 @@ .\IACore.dll - True + False .\IALoader.dll - True + False .\IAWinFX.dll - True + False @@ -190,6 +190,11 @@ + + + + + diff --git a/Ink Canvas/Resources/IACore/IACore.dll b/Ink Canvas/Resources/IACore/IACore.dll new file mode 100644 index 00000000..fdef2ca7 Binary files /dev/null and b/Ink Canvas/Resources/IACore/IACore.dll differ diff --git a/Ink Canvas/Resources/IACore/IALoader.dll b/Ink Canvas/Resources/IACore/IALoader.dll new file mode 100644 index 00000000..3ebd354c Binary files /dev/null and b/Ink Canvas/Resources/IACore/IALoader.dll differ diff --git a/Ink Canvas/Resources/IACore/IAWinFX.dll b/Ink Canvas/Resources/IACore/IAWinFX.dll new file mode 100644 index 00000000..1ce450a8 Binary files /dev/null and b/Ink Canvas/Resources/IACore/IAWinFX.dll differ diff --git a/Ink Canvas/obj/Debug/net472/InkCanvasForClass_MarkupCompile.cache b/Ink Canvas/obj/Debug/net472/InkCanvasForClass_MarkupCompile.cache deleted file mode 100644 index ad729a64..00000000 --- a/Ink Canvas/obj/Debug/net472/InkCanvasForClass_MarkupCompile.cache +++ /dev/null @@ -1,20 +0,0 @@ -InkCanvasForClass - - -winexe -C# -.cs -E:\ICC CE\ICC CE main\community\Ink Canvas\obj\Debug\net472\ -Ink_Canvas -none -false -TRACE;DEBUG;NETFRAMEWORK;NET472;;NET30_OR_GREATER;NET35_OR_GREATER;NET40_OR_GREATER;NET45_OR_GREATER;NET451_OR_GREATER;NET452_OR_GREATER;NET46_OR_GREATER;NET461_OR_GREATER;NET462_OR_GREATER;NET47_OR_GREATER;NET471_OR_GREATER;NET472_OR_GREATER -E:\ICC CE\ICC CE main\community\Ink Canvas\App.xaml -22-2143008179 - -79-461684434 -471037513499 -Helpers\Plugins\BuiltIn\SuperLauncher\LauncherSettingsControl.xaml;Helpers\Plugins\BuiltIn\SuperLauncher\LauncherWindow.xaml;MainWindow.xaml;MainWindow_cs\MW_Eraser.xaml;Resources\DrawShapeImageDictionary.xaml;Resources\IconImageDictionary.xaml;Resources\SeewoImageDictionary.xaml;Resources\Styles\Dark.xaml;Resources\Styles\Light.xaml;Windows\AddCustomIconWindow.xaml;Windows\AddPickNameBackgroundWindow.xaml;Windows\CountdownTimerWindow.xaml;Windows\CustomIconWindow.xaml;Windows\CycleProcessBar.xaml;Windows\HasNewUpdateWindow.xaml;Windows\HistoryRollbackWindow.xaml;Windows\ManagePickNameBackgroundsWindow.xaml;Windows\NamesInputWindow.xaml;Windows\OperatingGuideWindow.xaml;Windows\PluginSettingsWindow.xaml;Windows\RandWindow.xaml;Windows\YesOrNoNotificationWindow.xaml; - -False -