178 lines
5.0 KiB
C++
Raw Normal View History

2020-01-04 16:39:25 +03:00
#include "qif.h"
#include "quasarapp.h"
2020-01-13 18:25:03 +03:00
#include "deploycore.h"
#include "deployconfig.h"
2020-01-04 16:39:25 +03:00
2020-01-14 15:48:35 +03:00
#include <QDateTime>
2020-01-15 18:31:09 +03:00
#include <QProcess>
2020-01-16 15:25:36 +03:00
#include <pathutils.h>
2020-01-14 15:48:35 +03:00
2020-01-15 18:31:09 +03:00
QIF::QIF(FileManager *fileManager)
:iDistribution(fileManager){
};
2020-01-04 16:39:25 +03:00
2020-01-16 11:10:16 +03:00
Envirement QIF::toolKitEnv() const {
Envirement result;
2020-01-15 18:31:09 +03:00
result.addEnv(QProcessEnvironment::systemEnvironment().value("PATH"));
// BASE
const DeployConfig *cfg = DeployCore::_config;
auto basePATH = cfg->qtDir.getBins() + "/../../../Tools/QtInstallerFramework/";
QDir QifDir(basePATH);
auto list = QifDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
QMap<double, QString> sortedItems;
for (const auto& i : list) {
sortedItems.insert(i.toDouble(), i);
}
if (sortedItems.size()) {
basePATH += ("/" + sortedItems.last() + "/bin");
result.addEnv(basePATH);
}
// SNAP
2020-01-04 16:39:25 +03:00
QString AppPath = QuasarAppUtils::Params::getStrArg("appPath", "");
result.addEnv(AppPath);
//Installer
result.addEnvRec(AppPath + "../../QIF/", 2);
return result;
2020-01-04 16:39:25 +03:00
}
QString QIF::getConfig() const {
return ":/Distro/Distributions/configures/QIF.json";
2020-01-04 16:39:25 +03:00
}
2020-01-16 11:10:16 +03:00
QString QIF::runCmd() {
QString base = "binarycreator";
if (binarycreator.isEmpty())
binarycreator = findProcess(toolKitEnv().concatEnv(), base);
return binarycreator;
2020-01-04 16:39:25 +03:00
}
2020-01-16 15:25:36 +03:00
bool QIF::deployTemplate() {
auto customTemplate = QuasarAppUtils::Params::getStrArg("qif", "");
2020-01-13 18:25:03 +03:00
const DeployConfig *cfg = DeployCore::_config;
if (customTemplate.isEmpty()) {
// default template
for (auto it = cfg->prefixes().cbegin(); it != cfg->prefixes().cend(); ++it) {
2020-01-14 15:48:35 +03:00
auto package = it.value();
2020-01-13 18:25:03 +03:00
2020-01-14 15:48:35 +03:00
TemplateInfo info;
2020-01-18 15:39:02 +03:00
info.Name = (it.key().isEmpty())? "Application": PathUtils::stripPath(it.key());
2020-01-15 18:31:09 +03:00
if (!package.name().isEmpty()) {
2020-01-14 15:48:35 +03:00
info.Name = package.name();
2020-01-15 18:31:09 +03:00
}
2020-01-14 15:48:35 +03:00
2020-01-16 15:25:36 +03:00
auto location = cfg->getTargetDir() + "/" + getLocation() + "/packages/" + info.Name;
2020-01-18 15:39:02 +03:00
auto locationData = location + "/data";
if (!it.key().isEmpty()) {
locationData += "/" + info.Name;
}
2020-01-16 15:25:36 +03:00
2020-01-14 15:48:35 +03:00
info.Description = "This package contains the " + info.Name;
if (!package.description().isEmpty())
info.Description = package.description();
info.Version = "1.0";
if (!package.version().isEmpty())
info.Version = package.version();
2020-01-16 15:25:36 +03:00
info.ReleaseData = QDate::currentDate().toString("yyyy-MM-dd");
2020-01-14 15:48:35 +03:00
if (!package.releaseData().isEmpty())
info.ReleaseData = package.releaseData();
2020-01-14 15:48:35 +03:00
info.Icon = "";
2020-01-16 15:25:36 +03:00
if (!package.icon().isEmpty()) {
2020-01-14 15:48:35 +03:00
info.Icon = package.icon();
2020-01-18 15:39:02 +03:00
if (!copyFile(info.Icon, locationData + "/icons/")) {
2020-01-16 15:25:36 +03:00
return false;
}
}
2020-01-15 18:31:09 +03:00
info.Publisher = "Company";
2020-01-15 11:50:30 +03:00
if (!package.publisher().isEmpty())
info.Publisher = package.publisher();
2020-01-16 15:25:36 +03:00
QString cmdArray = "[";
for (const auto &target :it.value().targets()) {
auto info = QFileInfo(target);
if (info.suffix().compare("exe", ONLY_WIN_CASE_INSENSIATIVE) || info.suffix().isEmpty()) {
cmdArray += "\"" + info.fileName() + "\"";
}
}
cmdArray += "]";
info.Custom = {{"[\"array\", \"of\", \"cmds\"]", cmdArray},
{"$LOCAL_ICON", info.Name + "/icons/" + QFileInfo(info.Icon).fileName()}};
2020-01-15 18:31:09 +03:00
2020-01-15 11:50:30 +03:00
if (!unpackDir(":/Templates/QIF/Distributions/Templates/qif/packages/default", location, info)) {
2020-01-14 15:48:35 +03:00
return false;
}
2020-01-18 15:39:02 +03:00
if (!moveData(cfg->getTargetDir() + "/" + info.Name, locationData)) {
2020-01-15 18:31:09 +03:00
return false;
}
2020-01-15 11:50:30 +03:00
generalInfo = info;
}
auto configLocation = cfg->getTargetDir() + "/" + getLocation() + "/config/";
if (!unpackDir(":/Templates/QIF/Distributions/Templates/qif/config/",
configLocation, generalInfo)) {
return false;
2020-01-14 15:48:35 +03:00
}
2020-01-15 11:50:30 +03:00
2020-01-14 15:48:35 +03:00
return true;
}
2020-01-14 15:48:35 +03:00
// custom template
return true;
}
QStringList QIF::runArg() const {
2020-01-16 15:25:36 +03:00
auto location = DeployCore::_config->getTargetDir() + "/" + getLocation();
#ifdef Q_OS_LINUX
QString sufix = ".run";
#else
QString sufix = ".exe";
#endif
return {
"-c", location + "/config/config.xml",
"-p", location + "/packages/",
DeployCore::_config->getTargetDir() + "/" + generalInfo.Name + sufix
};
}
2020-01-15 11:50:30 +03:00
bool QIF::removeTemplate() const {
auto customTemplate = QuasarAppUtils::Params::getStrArg("qif", "");
const DeployConfig *cfg = DeployCore::_config;
if (customTemplate.isEmpty()) {
return QDir(cfg->getTargetDir() + "/" + getLocation()).removeRecursively();
}
return true;
}
2020-01-16 11:10:16 +03:00
QProcessEnvironment QIF::processEnvirement() const {
return QProcessEnvironment::systemEnvironment();
}