This commit is contained in:
2025-10-15 11:02:29 +08:00
parent 4d23e0684f
commit 7939e8988f
7 changed files with 128 additions and 9 deletions
+41
View File
@@ -6,6 +6,10 @@
#include <string.h> // for strstr
#include <devguid.h>
#include <shellapi.h>
#include <ShlObj.h>
#include <QPixmap>
#include <QFileIconProvider>
#include <QFileInfo>
#pragma comment(lib, "setupapi.lib")
static void DisableComPort(const char* portName) {
@@ -140,4 +144,41 @@ static void restartAsAdmin() {
}
}
}
// 解析 .lnk 文件,获取目标路径
static QString getShortcutTarget(const QString& shortcutPath) {
HRESULT hres;
CoInitialize(NULL);
IShellLink* psl;
QString targetPath;
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres)) {
IPersistFile* ppf;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres)) {
WCHAR wsz[MAX_PATH];
shortcutPath.toWCharArray(wsz);
wsz[shortcutPath.length()] = 0;
hres = ppf->Load(wsz, STGM_READ);
if (SUCCEEDED(hres)) {
char szTarget[MAX_PATH];
WIN32_FIND_DATA wfd;
if (SUCCEEDED(psl->GetPath(szTarget, MAX_PATH, &wfd, SLGP_UNCPRIORITY))) {
targetPath = QString::fromLocal8Bit(szTarget);
}
}
ppf->Release();
}
psl->Release();
}
CoUninitialize();
return targetPath;
}
// 获取目标文件图标
static QIcon getFileIcon(const QString& filePath, const QSize& size) {
QFileIconProvider iconProvider;
QFileInfo fileInfo(filePath);
QIcon icon = iconProvider.icon(fileInfo);
QPixmap pixmap = icon.pixmap(size);
return QIcon(pixmap);
}
#pragma once