1010#include < ctime>
1111
1212const QString WORK_FOLDER (QDir::homePath() + "/triage");
13+ const QString DACA2_PACKAGES (QDir::homePath() + "/daca2-packages");
1314
1415MainWindow::MainWindow (QWidget *parent) :
1516 QMainWindow(parent),
@@ -61,6 +62,32 @@ void MainWindow::loadFile()
6162 }
6263}
6364
65+ static bool wget (const QString url)
66+ {
67+ QProcess process;
68+ process.setWorkingDirectory (WORK_FOLDER);
69+ process.start (" wget" , QStringList () << url);
70+ return process.waitForFinished (-1 );
71+ }
72+
73+ static bool unpackArchive (const QString archiveName)
74+ {
75+ // Unpack archive
76+ QStringList args;
77+ if (archiveName.endsWith (" .tar.gz" ))
78+ args << " xzvf" ;
79+ else if (archiveName.endsWith (" .tar.bz2" ))
80+ args << " xjvf" ;
81+ else if (archiveName.endsWith (" .tar.xz" ))
82+ args << " xJvf" ;
83+ args << archiveName;
84+
85+ QProcess process;
86+ process.setWorkingDirectory (WORK_FOLDER);
87+ process.start (" tar" , args);
88+ return process.waitForFinished (-1 );
89+ }
90+
6491void MainWindow::showResult (QListWidgetItem *item)
6592{
6693 if (!item->text ().startsWith (" ftp://" ))
@@ -77,27 +104,19 @@ void MainWindow::showResult(QListWidgetItem *item)
77104 const QString fileName = msg.left (msg.indexOf (" :" ));
78105 const int lineNumber = msg.mid (pos1+1 ,pos2-pos1-1 ).toInt ();
79106
80- QProcess process;
81- process.setWorkingDirectory (WORK_FOLDER);
82-
83- if (!QFileInfo (WORK_FOLDER + ' /' + archiveName).exists ()) {
84- // Download archive
85- process.start (" wget" , QStringList ()<<url);
86- if (!process.waitForFinished (-1 ))
87- return ;
88-
89- // Unpack archive
90- QStringList args;
91- if (url.endsWith (" .tar.gz" ))
92- args << " xzvf" ;
93- else if (url.endsWith (" .tar.bz2" ))
94- args << " xjvf" ;
95- else if (url.endsWith (" .tar.xz" ))
96- args << " xJvf" ;
97- args << archiveName;
98- process.start (" tar" , args);
99- if (!process.waitForFinished (-1 ))
100- return ;
107+ if (!QFileInfo (fileName).exists ()) {
108+ if (QFileInfo (DACA2_PACKAGES + ' /' + archiveName.mid (0 ,archiveName.indexOf (" .tar." )) + " .tar.xz" ).exists ()) {
109+ if (!unpackArchive (DACA2_PACKAGES + ' /' + archiveName.mid (0 ,archiveName.indexOf (" .tar." )) + " .tar.xz" ))
110+ return ;
111+ } else {
112+ if (!QFileInfo (WORK_FOLDER + ' /' + archiveName).exists ()) {
113+ // Download archive
114+ if (!wget (url))
115+ return ;
116+ }
117+ if (!unpackArchive (WORK_FOLDER + ' /' + archiveName))
118+ return ;
119+ }
101120 }
102121
103122 // Open file
0 commit comments