177 lines
3.8 KiB
C++
177 lines
3.8 KiB
C++
/*
|
|
* WorkflowPackage.cpp
|
|
*
|
|
* Created on: 2013-11-27
|
|
* Author: dev
|
|
*/
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
#include <QDir>
|
|
|
|
#include "WorkflowPackage.h"
|
|
#include "LocalFile.h"
|
|
#include "error.h"
|
|
|
|
using namespace std;
|
|
using namespace pai;
|
|
using namespace pai::ios::vfs;
|
|
|
|
WorkflowPackage::WorkflowPackage()
|
|
{
|
|
}
|
|
|
|
WorkflowPackage::~WorkflowPackage()
|
|
{
|
|
}
|
|
|
|
bool WorkflowPackage::CanRead(const QString &path)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
return file.CanRead();
|
|
}
|
|
|
|
bool WorkflowPackage::CanWrite(const QString &path)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
return file.CanWrite();
|
|
}
|
|
|
|
bool WorkflowPackage::Exists(const QString &path)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
return file.Exists();
|
|
}
|
|
|
|
bool WorkflowPackage::IsDirectory(const QString &path)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
return file.IsDirectory();
|
|
}
|
|
|
|
bool WorkflowPackage::IsFile(const QString &path)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
return file.IsFile();
|
|
}
|
|
|
|
bool WorkflowPackage::Mkdir(const QString &path, QString &msg)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
try
|
|
{
|
|
file.Mkdir();
|
|
}
|
|
catch (pai::error::filesystem_error &e)
|
|
{
|
|
msg = QString(e.what());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool WorkflowPackage::Mkdirs(const QString &path, QString &msg)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
try
|
|
{
|
|
file.Mkdirs();
|
|
}
|
|
catch (pai::error::filesystem_error &e)
|
|
{
|
|
msg = QString(e.what());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool WorkflowPackage::Delete(const QString &path, QString &msg)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
try
|
|
{
|
|
file.Delete();
|
|
}
|
|
catch (pai::error::filesystem_error &e)
|
|
{
|
|
msg = QString(e.what());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool WorkflowPackage::Rename(const QString& oldPath, const QString& newPath)
|
|
{
|
|
LocalFile file(oldPath.toStdString(), FSTYPE_LOCALFS);
|
|
return file.Rename(oldPath.toStdString(), newPath.toStdString());
|
|
}
|
|
|
|
int WorkflowPackage::ListFiles(const QString &path, const QString& filter, QList<QString>& files)
|
|
{
|
|
LocalFile file(path.toStdString(), FSTYPE_LOCALFS);
|
|
|
|
std::vector<std::string> vFiles;
|
|
int ret = file.ListFiles(filter.toStdString(), vFiles);
|
|
for (size_t i = 0; i < vFiles.size(); i++)
|
|
{
|
|
files.append(QString::fromStdString(vFiles[i]));
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
bool WorkflowPackage::Rmdir(const QString &dirName)
|
|
{
|
|
QDir dir;
|
|
return dir.rmdir(dirName);
|
|
}
|
|
|
|
bool WorkflowPackage::ZipPackage(const QString &targetDir,
|
|
const QString &targetName,
|
|
const QStringList &srcFiles,
|
|
QString &msg)
|
|
{
|
|
QString command = "";
|
|
QString targetPath = targetDir + "/" +targetName;
|
|
if (!Exists(targetDir))
|
|
{
|
|
if (!Mkdirs(targetDir, msg))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
command.append("zip -jmq ").append(targetPath);
|
|
foreach (QString path, srcFiles)
|
|
{
|
|
command.append(" ").append(path);
|
|
}
|
|
|
|
if (-1 == system(command.toUtf8().data()))
|
|
{
|
|
msg = QString(QObject::tr("execute command failed: ")) + command;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool WorkflowPackage::UnZipPackage(const QString &pkgPath, const QString &unzipPath, QString &msg)
|
|
{
|
|
if (!Exists(pkgPath))
|
|
{
|
|
msg = QString(QObject::tr("cannot find or open ")) + pkgPath;
|
|
return false;
|
|
}
|
|
|
|
QString command = "";
|
|
command.clear();
|
|
command.append("unzip -qud ").append(unzipPath).append(" ").append(pkgPath);
|
|
|
|
if (-1 == system(command.toUtf8().data()))
|
|
{
|
|
msg = QString(QObject::tr("execute command failed: ")) + command;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|