tools/triage: try to unpack package from ~/daca2-packages

This commit is contained in:
Daniel Marjamäki 2018-02-08 22:18:50 +01:00
parent 7b3898f0f4
commit c650c8a111
1 changed files with 40 additions and 21 deletions

View File

@ -10,6 +10,7 @@
#include <ctime> #include <ctime>
const QString WORK_FOLDER(QDir::homePath() + "/triage"); const QString WORK_FOLDER(QDir::homePath() + "/triage");
const QString DACA2_PACKAGES(QDir::homePath() + "/daca2-packages");
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
@ -61,6 +62,32 @@ void MainWindow::loadFile()
} }
} }
static bool wget(const QString url)
{
QProcess process;
process.setWorkingDirectory(WORK_FOLDER);
process.start("wget", QStringList() << url);
return process.waitForFinished(-1);
}
static bool unpackArchive(const QString archiveName)
{
// Unpack archive
QStringList args;
if (archiveName.endsWith(".tar.gz"))
args << "xzvf";
else if (archiveName.endsWith(".tar.bz2"))
args << "xjvf";
else if (archiveName.endsWith(".tar.xz"))
args << "xJvf";
args << archiveName;
QProcess process;
process.setWorkingDirectory(WORK_FOLDER);
process.start("tar", args);
return process.waitForFinished(-1);
}
void MainWindow::showResult(QListWidgetItem *item) void MainWindow::showResult(QListWidgetItem *item)
{ {
if (!item->text().startsWith("ftp://")) if (!item->text().startsWith("ftp://"))
@ -77,28 +104,20 @@ void MainWindow::showResult(QListWidgetItem *item)
const QString fileName = msg.left(msg.indexOf(":")); const QString fileName = msg.left(msg.indexOf(":"));
const int lineNumber = msg.mid(pos1+1,pos2-pos1-1).toInt(); const int lineNumber = msg.mid(pos1+1,pos2-pos1-1).toInt();
QProcess process; if (!QFileInfo(fileName).exists()) {
process.setWorkingDirectory(WORK_FOLDER); if (QFileInfo(DACA2_PACKAGES + '/' + archiveName.mid(0,archiveName.indexOf(".tar.")) + ".tar.xz").exists()) {
if (!unpackArchive(DACA2_PACKAGES + '/' + archiveName.mid(0,archiveName.indexOf(".tar.")) + ".tar.xz"))
return;
} else {
if (!QFileInfo(WORK_FOLDER + '/' + archiveName).exists()) { if (!QFileInfo(WORK_FOLDER + '/' + archiveName).exists()) {
// Download archive // Download archive
process.start("wget", QStringList()<<url); if (!wget(url))
if (!process.waitForFinished(-1))
return; return;
}
// Unpack archive if (!unpackArchive(WORK_FOLDER + '/' + archiveName))
QStringList args;
if (url.endsWith(".tar.gz"))
args << "xzvf";
else if (url.endsWith(".tar.bz2"))
args << "xjvf";
else if (url.endsWith(".tar.xz"))
args << "xJvf";
args << archiveName;
process.start("tar", args);
if (!process.waitForFinished(-1))
return; return;
} }
}
// Open file // Open file
ui->code->setFocus(); ui->code->setFocus();