UI: AppInfo: Add "altPath" for Service DLL-s

This commit is contained in:
Nodir Temirkhodjaev 2022-02-10 09:04:16 +03:00
parent 3725b62b1f
commit 21461aee47
7 changed files with 31 additions and 25 deletions

View File

@ -2,7 +2,12 @@
#include "appinfoutil.h"
QString AppInfo::getPath(const QString &appPath) const
{
return !altPath.isEmpty() ? altPath : appPath;
}
bool AppInfo::isFileModified(const QString &appPath) const
{
return fileModTime != AppInfoUtil::fileModTime(appPath);
return fileModTime != AppInfoUtil::fileModTime(getPath(appPath));
}

View File

@ -7,6 +7,7 @@
class AppInfo
{
public:
QString getPath(const QString &appPath) const;
bool isFileModified(const QString &appPath) const;
bool isValid() const { return iconId != 0; }
@ -16,6 +17,7 @@ public:
QDateTime fileModTime;
QString altPath;
QString fileDescription;
QString companyName;
QString productName;

View File

@ -16,13 +16,13 @@ Q_LOGGING_CATEGORY(CLOG_APPINFO_MANAGER, "appInfo")
#define logWarning() qCWarning(CLOG_APPINFO_MANAGER, )
#define logCritical() qCCritical(CLOG_APPINFO_MANAGER, )
#define DATABASE_USER_VERSION 3
#define DATABASE_USER_VERSION 4
#define APP_CACHE_MAX_COUNT 2000
namespace {
const char *const sqlSelectAppInfo = "SELECT file_descr, company_name,"
const char *const sqlSelectAppInfo = "SELECT alt_path, file_descr, company_name,"
" product_name, product_ver, file_mod_time, icon_id"
" FROM app WHERE path = ?1;";
@ -41,10 +41,10 @@ const char *const sqlUpdateIconRefCount = "UPDATE icon"
" SET ref_count = ref_count + ?2"
" WHERE icon_id = ?1;";
const char *const sqlInsertAppInfo = "INSERT INTO app(path, file_descr, company_name,"
const char *const sqlInsertAppInfo = "INSERT INTO app(path, alt_path, file_descr, company_name,"
" product_name, product_ver, file_mod_time,"
" icon_id, access_time)"
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, datetime('now'));";
" VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, datetime('now'));";
const char *const sqlSelectAppCount = "SELECT count(*) FROM app;";
@ -123,9 +123,9 @@ bool AppInfoManager::loadInfoFromFs(const QString &appPath, AppInfo &appInfo)
return AppInfoUtil::getInfo(appPath, appInfo);
}
QImage AppInfoManager::loadIconFromFs(const QString &appPath)
QImage AppInfoManager::loadIconFromFs(const QString &appPath, const AppInfo &appInfo)
{
return AppInfoUtil::getIcon(appPath);
return AppInfoUtil::getIcon(appInfo.getPath(appPath));
}
bool AppInfoManager::loadInfoFromDb(const QString &appPath, AppInfo &appInfo)
@ -145,12 +145,13 @@ bool AppInfoManager::loadInfoFromDb(const QString &appPath, AppInfo &appInfo)
if (stmt.step() != SqliteStmt::StepRow)
return false;
appInfo.fileDescription = stmt.columnText(0);
appInfo.companyName = stmt.columnText(1);
appInfo.productName = stmt.columnText(2);
appInfo.productVersion = stmt.columnText(3);
appInfo.fileModTime = stmt.columnDateTime(4);
appInfo.iconId = stmt.columnInt64(5);
appInfo.altPath = stmt.columnText(0);
appInfo.fileDescription = stmt.columnText(1);
appInfo.companyName = stmt.columnText(2);
appInfo.productName = stmt.columnText(3);
appInfo.productVersion = stmt.columnText(4);
appInfo.fileModTime = stmt.columnDateTime(5);
appInfo.iconId = stmt.columnInt64(6);
// Update last access time
updateAppAccessTime(appPath);
@ -202,8 +203,8 @@ bool AppInfoManager::saveToDb(const QString &appPath, AppInfo &appInfo, const QI
// Save version info
if (ok) {
const QVariantList vars = QVariantList()
<< appPath << appInfo.fileDescription << appInfo.companyName << appInfo.productName
<< appInfo.productVersion << appInfo.fileModTime << iconId;
<< appPath << appInfo.altPath << appInfo.fileDescription << appInfo.companyName
<< appInfo.productName << appInfo.productVersion << appInfo.fileModTime << iconId;
sqliteDb()->executeEx(sqlInsertAppInfo, vars, 0, &ok);
}

View File

@ -26,7 +26,7 @@ public:
void setUp() override;
bool loadInfoFromFs(const QString &appPath, AppInfo &appInfo);
QImage loadIconFromFs(const QString &appPath);
QImage loadIconFromFs(const QString &appPath, const AppInfo &appInfo);
bool loadInfoFromDb(const QString &appPath, AppInfo &appInfo);
QImage loadIconFromDb(qint64 iconId);

View File

@ -173,6 +173,7 @@ bool getInfo(const QString &appPath, AppInfo &appInfo)
QString serviceName;
if (FileUtil::isSvcHostService(appPath, serviceName)) {
path = ServiceInfoManager::getSvcHostServiceDll(serviceName);
appInfo.altPath = path;
}
const auto wow64FsRedir = disableWow64FsRedirection();
@ -202,16 +203,9 @@ QImage getIcon(const QString &appPath)
return QImage(":/icons/windows-48.png");
}
QString path = appPath;
QString serviceName;
if (FileUtil::isSvcHostService(appPath, serviceName)) {
path = ServiceInfoManager::getSvcHostServiceDll(serviceName);
}
const auto wow64FsRedir = disableWow64FsRedirection();
const QImage result = extractShellIcon(path);
const QImage result = extractShellIcon(appPath);
revertWow64FsRedirection(wow64FsRedir);
@ -241,6 +235,9 @@ bool fileExists(const QString &appPath)
QDateTime fileModTime(const QString &appPath)
{
if (appPath.isEmpty() || FileUtil::isSystemApp(appPath))
return {};
const auto wow64FsRedir = disableWow64FsRedirection();
const QDateTime res = FileUtil::fileModTime(appPath);

View File

@ -40,7 +40,7 @@ void AppInfoWorker::doJob(WorkerJob *workerJob)
// Try to load from FS
if (!loadedFromDb && manager()->loadInfoFromFs(appPath, appInfo)) {
const QImage appIcon = manager()->loadIconFromFs(appPath);
const QImage appIcon = manager()->loadIconFromFs(appPath, appInfo);
manager()->saveToDb(appPath, appInfo, appIcon);
}

View File

@ -1,5 +1,6 @@
CREATE TABLE app(
path TEXT PRIMARY KEY,
alt_path TEXT,
file_descr TEXT,
company_name TEXT,
product_name TEXT,