2019-01-26 07:54:56 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018-2019 QuasarApp.
|
|
|
|
* Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
* of this license document, but changing it is not allowed.
|
|
|
|
*/
|
|
|
|
|
2019-03-19 21:50:05 +03:00
|
|
|
#include "dependenciesscanner.h"
|
2018-12-09 17:35:07 +03:00
|
|
|
#include "deployutils.h"
|
2018-11-15 18:00:23 +03:00
|
|
|
|
|
|
|
#include <QList>
|
2018-11-18 17:22:05 +03:00
|
|
|
#include <QDir>
|
2018-11-26 16:17:46 +03:00
|
|
|
#include <QDebug>
|
2018-11-15 18:00:23 +03:00
|
|
|
|
2019-03-19 21:50:05 +03:00
|
|
|
DependenciesScanner::DependenciesScanner() {}
|
2018-11-15 18:00:23 +03:00
|
|
|
|
2019-03-17 18:42:07 +03:00
|
|
|
|
2019-03-19 21:50:05 +03:00
|
|
|
PrivateScaner DependenciesScanner::getScaner(const QString &lib) const {
|
2019-03-17 18:42:07 +03:00
|
|
|
|
2019-03-19 21:50:05 +03:00
|
|
|
QFileInfo info(lib);
|
|
|
|
|
|
|
|
auto sufix = info.completeSuffix();
|
|
|
|
|
|
|
|
if (sufix.contains("dll", Qt::CaseSensitive) ||
|
|
|
|
sufix.contains("exe", Qt::CaseSensitive)) {
|
|
|
|
return PrivateScaner::PE;
|
|
|
|
} else if (sufix.isEmpty() || sufix.contains("so", Qt::CaseSensitive)) {
|
|
|
|
return PrivateScaner::ELF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PrivateScaner::UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DependenciesScanner::fillLibInfo(LibInfo &info, const QString &file) {
|
|
|
|
|
2019-03-23 23:13:52 +03:00
|
|
|
info.clear();
|
2019-03-19 21:50:05 +03:00
|
|
|
auto scaner = getScaner(file);
|
|
|
|
|
|
|
|
switch (scaner) {
|
|
|
|
case PrivateScaner::PE: {
|
|
|
|
return _peScaner.getLibInfo(file, info);
|
|
|
|
}
|
2019-03-23 23:13:52 +03:00
|
|
|
case PrivateScaner::ELF:
|
|
|
|
return _elfScaner.getLibInfo(file, info);
|
2019-03-19 21:50:05 +03:00
|
|
|
|
|
|
|
default: return false;
|
|
|
|
}
|
2018-12-09 17:35:07 +03:00
|
|
|
}
|
|
|
|
|
2019-03-19 21:50:05 +03:00
|
|
|
void DependenciesScanner::setEnvironment(const QStringList &env) {
|
2018-11-18 17:22:05 +03:00
|
|
|
QDir dir;
|
2018-11-23 14:56:55 +03:00
|
|
|
for (auto i : env) {
|
2018-12-09 17:35:07 +03:00
|
|
|
|
2018-11-18 17:22:05 +03:00
|
|
|
dir.setPath(i);
|
|
|
|
if (!dir.exists()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:56:55 +03:00
|
|
|
auto list = dir.entryInfoList(QStringList() << "*.dll",
|
2018-11-18 17:22:05 +03:00
|
|
|
QDir::Files| QDir::NoDotAndDotDot);
|
|
|
|
|
2018-11-23 14:56:55 +03:00
|
|
|
for (auto i : list) {
|
2018-12-09 17:35:07 +03:00
|
|
|
|
|
|
|
auto newPriority = DeployUtils::getLibPriority(i.absoluteFilePath());
|
|
|
|
auto oldPriority = DeployUtils::getLibPriority(_EnvLibs.value(i.fileName(), ""));
|
|
|
|
|
|
|
|
if (newPriority > oldPriority)
|
|
|
|
_EnvLibs.insert(i.fileName(), i.absoluteFilePath());
|
2018-11-23 14:56:55 +03:00
|
|
|
}
|
2018-11-18 17:22:05 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-19 21:50:05 +03:00
|
|
|
QStringList DependenciesScanner::scan(const QString &path) {
|
2018-11-18 17:22:05 +03:00
|
|
|
QStringList result;
|
|
|
|
|
2018-11-26 16:17:46 +03:00
|
|
|
QString errorMessage;
|
|
|
|
|
|
|
|
QStringList dep;
|
|
|
|
|
|
|
|
if (!errorMessage.isEmpty()) {
|
|
|
|
qCritical() << errorMessage;
|
|
|
|
return result;
|
|
|
|
}
|
2018-11-18 17:22:05 +03:00
|
|
|
|
2018-11-23 14:56:55 +03:00
|
|
|
for (auto i : dep) {
|
|
|
|
QString lib(i);
|
|
|
|
if (_EnvLibs.count(lib)) {
|
|
|
|
result.push_back(_EnvLibs.value(lib));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 17:22:05 +03:00
|
|
|
return result;
|
2018-11-15 18:00:23 +03:00
|
|
|
}
|
2018-11-23 14:56:55 +03:00
|
|
|
|
2019-03-19 21:50:05 +03:00
|
|
|
DependenciesScanner::~DependenciesScanner() {
|
2018-11-23 14:56:55 +03:00
|
|
|
|
|
|
|
}
|