我有一个使用 SharpShell 作为图标处理程序的项目。它会在 APK 内部窥视以查找并显示其图标。我已经让它工作了,但有一些副作用。如果我尝试将 APK 重命名为其他名称,例如 from A.apk
to B.apk
,那么 Explorer 就会崩溃,我找不到原因。
这是主要部分和日志记录位:
using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using ApkDetails;
using SharpShell.Attributes;
using SharpShell.SharpIconHandler;
namespace ApkIconHandler {
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".apk")]
public class ApkHandler : SharpIconHandler {
protected override Icon GetIcon(bool smallIcon, uint iconSize) {
try {
APK apk = new APK(SelectedItemPath);
using (Bitmap icon = apk.GetIcon()) {
IntPtr icH = icon.GetHicon();
Icon ico = Icon.FromHandle(icH);
return ico;
}
} catch (Exception ex) {
File.AppendAllText(@"C:\APKError.txt", ex.Message + Environment.NewLine + ex.StackTrace);
return Icons.DefaultIcon;
}
}
protected override void LogError(string message, Exception exception = null) {
base.LogError(message, exception);
String err = message;
if (exception != null) err += Environment.NewLine + exception.StackTrace;
File.AppendAllText(@"C:\APKError.txt", err + Environment.NewLine);
}
protected override void Log(string message) {
base.Log(message);
File.AppendAllText(@"C:\APKLog.txt", message + Environment.NewLine);
}
}
}
我的 APK 代码运行aapt d badging "path.apk"
并解析输出以获取图标信息,GetIcon 将 APK 作为 zip 打开以获取该文件。我将它全部包装在一个 try/catch 中并绑定到 SharpShell 的 LogError 方法中,但我从来没有得到任何输出。我禁用了 UAC。我认为写入驱动器的根目录没有权限问题,因为 APKLog.txt 确实显示但没有有用的信息。
我得到窗口“Windows 资源管理器已停止工作”并将此信息列为“问题签名”
Problem Event Name: CLR20r3
Problem Signature 01: explorer.exe
Problem Signature 02: 6.1.7601.17567
Problem Signature 03: 4d672ee4
Problem Signature 04: mscorlib
Problem Signature 05: 4.0.30319.18047
Problem Signature 06: 5155314f
Problem Signature 07: 326
Problem Signature 08: 5d
Problem Signature 09: System.AccessViolationException
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 59cf
Additional Information 2: 59cf5fdf81b829ceb8b613f1f092df60
Additional Information 3: 6d90
Additional Information 4: 6d903bfb0ab1d4b858654f0b33b94d7f
我看到它说System.AccessViolationException
,但我的代码都没有捕捉到它。有人可以对这里发生的事情提供一些见解吗?