tools/triage: try to unpack package from ~/daca2-packages
This commit is contained in:
parent
7b3898f0f4
commit
c650c8a111
|
@ -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,27 +104,19 @@ 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"))
|
||||||
if (!QFileInfo(WORK_FOLDER + '/' + archiveName).exists()) {
|
return;
|
||||||
// Download archive
|
} else {
|
||||||
process.start("wget", QStringList()<<url);
|
if (!QFileInfo(WORK_FOLDER + '/' + archiveName).exists()) {
|
||||||
if (!process.waitForFinished(-1))
|
// Download archive
|
||||||
return;
|
if (!wget(url))
|
||||||
|
return;
|
||||||
// Unpack archive
|
}
|
||||||
QStringList args;
|
if (!unpackArchive(WORK_FOLDER + '/' + archiveName))
|
||||||
if (url.endsWith(".tar.gz"))
|
return;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
|
|
Loading…
Reference in New Issue