备份
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user