|
1 | 1 | #include "mainwindow.h"
|
2 | 2 |
|
3 |
| -#include <iostream> |
4 | 3 | #include <QFileDialog>
|
5 | 4 | #include <QLineEdit>
|
6 | 5 | #include <QMenuBar>
|
@@ -139,6 +138,8 @@ void MainWindow::InitializeMenuBar()
|
139 | 138 |
|
140 | 139 | file_menu->addAction(tr("&View SI File"), tr("Ctrl+I"), this, &MainWindow::ViewSIFile);
|
141 | 140 |
|
| 141 | + file_menu->addAction(tr("E&xtract All"), this, &MainWindow::ExtractAll); |
| 142 | + |
142 | 143 | file_menu->addSeparator();
|
143 | 144 |
|
144 | 145 | file_menu->addAction(tr("E&xit"), this, &MainWindow::close);
|
@@ -244,6 +245,39 @@ QString MainWindow::GetOpenFileName()
|
244 | 245 | return QFileDialog::getOpenFileName(this, QString(), QString(), kFileFilter);
|
245 | 246 | }
|
246 | 247 |
|
| 248 | +bool MainWindow::ExtractAllRecursiveInternal(const QDir &dir, const si::Core *obj) |
| 249 | +{ |
| 250 | + if (!dir.mkpath(QStringLiteral("."))) { |
| 251 | + QMessageBox::critical(this, tr("Extract All Failed"), tr("Failed to create directory \"%1\". Try extracting somewhere else.").arg(dir.absolutePath())); |
| 252 | + return false; |
| 253 | + } |
| 254 | + |
| 255 | + for (const Core *child : obj->GetChildren()) { |
| 256 | + if (const Object *obj = dynamic_cast<const Object*>(child)) { |
| 257 | + if (!obj->data().empty()) { |
| 258 | + QString realFilename = QString::fromStdString(obj->filename()); |
| 259 | + realFilename = realFilename.mid(realFilename.lastIndexOf('\\')+1); |
| 260 | + |
| 261 | + QString output = dir.filePath(realFilename); |
| 262 | + |
| 263 | + if (!obj->ExtractToFile(output.toUtf8())) { |
| 264 | + QMessageBox::critical(this, tr("Extract All Failed"), tr("Failed to create file \"%1\". Try extracting somewhere else.").arg(output)); |
| 265 | + return false; |
| 266 | + } |
| 267 | + } |
| 268 | + |
| 269 | + if (obj->HasChildren()) { |
| 270 | + // Extract its children too |
| 271 | + if (!ExtractAllRecursiveInternal(QDir(dir.filePath(QString::fromStdString(obj->name()))), obj)) { |
| 272 | + return false; |
| 273 | + } |
| 274 | + } |
| 275 | + } |
| 276 | + } |
| 277 | + |
| 278 | + return true; |
| 279 | +} |
| 280 | + |
247 | 281 | void MainWindow::NewFile()
|
248 | 282 | {
|
249 | 283 | model_.SetCore(nullptr);
|
@@ -354,6 +388,22 @@ void MainWindow::ViewSIFile()
|
354 | 388 | }
|
355 | 389 | }
|
356 | 390 |
|
| 391 | +void MainWindow::ExtractAll() |
| 392 | +{ |
| 393 | + QString s = QFileDialog::getExistingDirectory(this, tr("Extract All To...")); |
| 394 | + if (s.isEmpty()) { |
| 395 | + return; |
| 396 | + } |
| 397 | + |
| 398 | + QDir dir(s); |
| 399 | + if (!dir.exists()) { |
| 400 | + QMessageBox::critical(this, tr("Extract All Failed"), tr("Directory \"%1\" is not valid. Try extracting somewhere else.").arg(s)); |
| 401 | + return; |
| 402 | + } |
| 403 | + |
| 404 | + ExtractAllRecursiveInternal(dir, &interleaf_); |
| 405 | +} |
| 406 | + |
357 | 407 | void MainWindow::ExtraChanged()
|
358 | 408 | {
|
359 | 409 | if (last_set_data_) {
|
|
0 commit comments