2019-11-28 18:13:56 +03:00
|
|
|
#include "idistribution.h"
|
2020-01-05 13:58:38 +03:00
|
|
|
#include <typeinfo>
|
|
|
|
#include <QFile>
|
2020-01-13 18:25:03 +03:00
|
|
|
#include <QTextStream>
|
2020-01-14 15:48:35 +03:00
|
|
|
#include <QDir>
|
2020-01-15 18:31:09 +03:00
|
|
|
#include <cassert>
|
|
|
|
#include <filemanager.h>
|
2020-01-16 11:10:16 +03:00
|
|
|
#include "deploycore.h"
|
|
|
|
#include "pathutils.h"
|
2019-11-28 18:13:56 +03:00
|
|
|
|
|
|
|
iDistribution::~iDistribution() = default;
|
2020-01-05 13:58:38 +03:00
|
|
|
|
2020-01-15 18:31:09 +03:00
|
|
|
iDistribution::iDistribution(FileManager *fileManager) {
|
|
|
|
_fileManager = fileManager;
|
|
|
|
assert(_fileManager);
|
|
|
|
}
|
|
|
|
|
2020-01-05 13:58:38 +03:00
|
|
|
QString iDistribution::getClassName() const {
|
|
|
|
return typeid(*this).name();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString iDistribution::getLocation() const {
|
|
|
|
return _location;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iDistribution::setLocation(const QString &location) {
|
|
|
|
_location = location;
|
|
|
|
}
|
2020-01-13 18:25:03 +03:00
|
|
|
|
2020-01-14 15:48:35 +03:00
|
|
|
bool iDistribution::unpackFile(const QFileInfo &resource,
|
|
|
|
const QString &target,
|
|
|
|
const TemplateInfo &info) const {
|
|
|
|
QFile file(resource.absoluteFilePath());
|
2020-01-13 18:25:03 +03:00
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString inputData = file.readAll();
|
|
|
|
file.close();
|
|
|
|
|
2020-01-14 15:48:35 +03:00
|
|
|
if (!QDir().mkpath(target))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
file.setFileName(target + "/" + resource.fileName());
|
2020-01-13 18:25:03 +03:00
|
|
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inputData.replace("$NAME", info.Name);
|
|
|
|
inputData.replace("$DESCRIPTION", info.Description);
|
|
|
|
inputData.replace("$VERSION", info.Version);
|
|
|
|
inputData.replace("$RELEASEDATA", info.ReleaseData);
|
|
|
|
inputData.replace("$ICON", info.Icon);
|
2020-01-15 11:50:30 +03:00
|
|
|
inputData.replace("$PUBLISHER", info.Publisher);
|
2020-01-13 18:25:03 +03:00
|
|
|
|
|
|
|
for (auto it = info.Custom.cbegin(); it != info.Custom.cend(); ++it) {
|
|
|
|
inputData.replace(it.key(), it.value());
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextStream stream(&file);
|
|
|
|
stream << inputData;
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
2020-01-15 18:31:09 +03:00
|
|
|
return _fileManager->addToDeployed(target + "/" + resource.fileName());
|
2020-01-13 18:25:03 +03:00
|
|
|
}
|
2020-01-14 15:48:35 +03:00
|
|
|
|
|
|
|
bool iDistribution::unpackDir(const QString &resource,
|
|
|
|
const QString &target,
|
|
|
|
const TemplateInfo &info) const {
|
|
|
|
|
|
|
|
|
|
|
|
QDir res(resource);
|
|
|
|
auto list = res.entryInfoList();
|
|
|
|
|
|
|
|
for (const auto & item :list) {
|
|
|
|
|
|
|
|
if (item.isFile()) {
|
|
|
|
if (!unpackFile(item, target, info)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!unpackDir(item.absoluteFilePath(),
|
|
|
|
target + "/" + item.fileName(),
|
|
|
|
info)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-15 18:31:09 +03:00
|
|
|
|
|
|
|
bool iDistribution::moveData(const QString &from,
|
|
|
|
const QString &to) const {
|
|
|
|
return _fileManager->moveFolder(from, to);
|
|
|
|
}
|
2020-01-16 11:10:16 +03:00
|
|
|
|
|
|
|
QString iDistribution::findProcess(const QString &env, const QString& proc) const {
|
|
|
|
auto list = env.split(DeployCore::getEnvSeparator());
|
|
|
|
|
|
|
|
for (const auto& path : list) {
|
|
|
|
auto files = QDir(path).entryInfoList(QDir::NoDotAndDotDot | QDir::Files);
|
|
|
|
|
|
|
|
for (const auto& bin : files) {
|
|
|
|
if (bin.fileName().compare(proc, ONLY_WIN_CASE_INSENSIATIVE) == 0) {
|
|
|
|
return bin.absoluteFilePath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|