mirror of
https://github.com/tnodir/fort
synced 2024-11-15 11:55:09 +00:00
UI: AppUtil: Add getInfo().
This commit is contained in:
parent
62444dcd88
commit
a7138869a7
@ -168,8 +168,9 @@ RESOURCES += db/migrations.qrc
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Windows
|
# Windows
|
||||||
LIBS += -lfwpuclnt -lkernel32 -luser32 -luuid -lws2_32
|
LIBS += -lfwpuclnt -lkernel32 -luser32 -luuid -lversion -lws2_32
|
||||||
RC_FILE = FortFirewall.rc
|
RC_FILE = FortFirewall.rc
|
||||||
|
OTHER_FILES += $${RC_FILE}
|
||||||
|
|
||||||
# Kernel Driver
|
# Kernel Driver
|
||||||
installer_build {
|
installer_build {
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
#define VER_PRODUCTVERSION VER_FILEVERSION
|
#define VER_PRODUCTVERSION VER_FILEVERSION
|
||||||
#define VER_PRODUCTVERSION_STR APP_VERSION_STR
|
#define VER_PRODUCTVERSION_STR APP_VERSION_STR
|
||||||
|
|
||||||
#define VER_COMPANYNAME_STR "Open Source Developer, Nodir Temirkhodjaev"
|
#define VER_COMPANYNAME_STR "Nodir Temirkhodjaev"
|
||||||
#define VER_FILEDESCRIPTION_STR "Fort Firewall"
|
#define VER_FILEDESCRIPTION_STR "Fort Firewall"
|
||||||
#define VER_INTERNALNAME_STR "FortFirewall"
|
#define VER_INTERNALNAME_STR "FortFirewall"
|
||||||
#define VER_LEGALCOPYRIGHT_STR "Copyright 2015 Nodir Temirkhodjaev"
|
#define VER_LEGALCOPYRIGHT_STR "Copyright (C) 2015-2019 Nodir Temirkhodjaev. All Rights Reserved."
|
||||||
#define VER_LEGALTRADEMARKS1_STR ""
|
#define VER_LEGALTRADEMARKS1_STR ""
|
||||||
#define VER_LEGALTRADEMARKS2_STR ""
|
#define VER_LEGALTRADEMARKS2_STR ""
|
||||||
#define VER_ORIGINALFILENAME_STR "FortFirewall.exe"
|
#define VER_ORIGINALFILENAME_STR "FortFirewall.exe"
|
||||||
|
@ -31,8 +31,7 @@ static QPixmap pixmapFromImageList(int iImageList, const SHFILEINFO &info)
|
|||||||
|
|
||||||
static QPixmap extractShellIcon(const QString &appPath)
|
static QPixmap extractShellIcon(const QString &appPath)
|
||||||
{
|
{
|
||||||
const QString nativePath = QDir::toNativeSeparators(appPath);
|
const wchar_t *appPathW = (LPCWSTR) appPath.utf16();
|
||||||
const wchar_t *nativePathW = reinterpret_cast<const wchar_t *>(nativePath.utf16());
|
|
||||||
|
|
||||||
const UINT flags = SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES;
|
const UINT flags = SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES;
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ static QPixmap extractShellIcon(const QString &appPath)
|
|||||||
SHFILEINFOW info;
|
SHFILEINFOW info;
|
||||||
ZeroMemory(&info, sizeof(SHFILEINFOW));
|
ZeroMemory(&info, sizeof(SHFILEINFOW));
|
||||||
|
|
||||||
const HRESULT hr = SHGetFileInfoW(nativePathW, 0, &info,
|
const HRESULT hr = SHGetFileInfoW(appPathW, 0, &info,
|
||||||
sizeof(SHFILEINFOW), flags);
|
sizeof(SHFILEINFOW), flags);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
pixmap = pixmapFromImageList(SHIL_JUMBO, info);
|
pixmap = pixmapFromImageList(SHIL_JUMBO, info);
|
||||||
@ -50,14 +49,83 @@ static QPixmap extractShellIcon(const QString &appPath)
|
|||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString extractInfoText(LPVOID infoData, const WORD *langInfo,
|
||||||
|
const WCHAR *name)
|
||||||
|
{
|
||||||
|
WCHAR verStrName[128];
|
||||||
|
wsprintfW(verStrName, L"\\StringFileInfo\\%04x%04x\\%s",
|
||||||
|
langInfo[0], langInfo[1], name);
|
||||||
|
|
||||||
|
WCHAR *content;
|
||||||
|
UINT len;
|
||||||
|
if (VerQueryValueW(infoData, verStrName,
|
||||||
|
(LPVOID *) &content, &len)
|
||||||
|
&& len > 1) {
|
||||||
|
return QString::fromWCharArray(content, len - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
AppUtil::AppUtil(QObject *parent) :
|
static bool extractAppInfo(const QString &appPath, AppInfo &appInfo)
|
||||||
QObject(parent)
|
|
||||||
{
|
{
|
||||||
|
const wchar_t *appPathW = (LPCWSTR) appPath.utf16();
|
||||||
|
|
||||||
|
const DWORD flags = FILE_VER_GET_NEUTRAL | FILE_VER_GET_PREFETCHED;
|
||||||
|
|
||||||
|
DWORD dummy;
|
||||||
|
const DWORD infoSize = GetFileVersionInfoSizeExW(flags, appPathW, &dummy);
|
||||||
|
if (infoSize == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QScopedArrayPointer<BYTE> infoBuf(new BYTE[infoSize]);
|
||||||
|
LPVOID infoData = infoBuf.data();
|
||||||
|
|
||||||
|
if (!GetFileVersionInfoExW(flags, appPathW, 0, infoSize, infoData))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Product Version
|
||||||
|
{
|
||||||
|
VS_FIXEDFILEINFO *ffi;
|
||||||
|
if (!VerQueryValueA(infoData, "\\", (LPVOID *) &ffi, (PUINT) dummy))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const DWORD leftMost = HIWORD(ffi->dwProductVersionMS);
|
||||||
|
const DWORD secondLeft = LOWORD(ffi->dwProductVersionMS);
|
||||||
|
const DWORD secondRight = HIWORD(ffi->dwProductVersionLS);
|
||||||
|
const DWORD rightMost = LOWORD(ffi->dwProductVersionLS);
|
||||||
|
|
||||||
|
appInfo.productVersion = QString("%1.%2.%3.%4").arg(
|
||||||
|
QString::number(leftMost), QString::number(secondLeft),
|
||||||
|
QString::number(secondRight), QString::number(rightMost));
|
||||||
|
|
||||||
|
if (rightMost == 0) {
|
||||||
|
appInfo.productVersion.chop(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Language info
|
||||||
|
WORD *langInfo;
|
||||||
|
if (!VerQueryValueA(infoData, "\\VarFileInfo\\Translation",
|
||||||
|
(LPVOID *) &langInfo, (PUINT) dummy))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Texts
|
||||||
|
appInfo.productName = extractInfoText(infoData, langInfo, L"ProductName");
|
||||||
|
appInfo.companyName = extractInfoText(infoData, langInfo, L"CompanyName");
|
||||||
|
appInfo.fileDescription = extractInfoText(infoData, langInfo, L"FileDescription");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap AppUtil::getIcon(const QString &appPath)
|
QPixmap AppUtil::getIcon(const QString &appPath)
|
||||||
{
|
{
|
||||||
return extractShellIcon(appPath);
|
return extractShellIcon(appPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AppUtil::getInfo(const QString &appPath, AppInfo &appInfo)
|
||||||
|
{
|
||||||
|
return extractAppInfo(appPath, appInfo);
|
||||||
|
}
|
||||||
|
@ -4,14 +4,18 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
class AppUtil : public QObject
|
typedef struct AppInfo {
|
||||||
|
QString fileDescription;
|
||||||
|
QString companyName;
|
||||||
|
QString productName;
|
||||||
|
QString productVersion;
|
||||||
|
} AppInfo;
|
||||||
|
|
||||||
|
class AppUtil
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AppUtil(QObject *parent = nullptr);
|
static QPixmap getIcon(const QString &appPath);
|
||||||
|
static bool getInfo(const QString &appPath, AppInfo &appInfo);
|
||||||
Q_INVOKABLE static QPixmap getIcon(const QString &appPath);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPUTIL_H
|
#endif // APPUTIL_H
|
||||||
|
Loading…
Reference in New Issue
Block a user