diff options
Diffstat (limited to 'src/frontend/qt_sdl/main.cpp')
-rw-r--r-- | src/frontend/qt_sdl/main.cpp | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 0228446..a473062 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -21,14 +21,21 @@ #include <stdio.h> #include <string.h> +#include <vector> +#include <string> +#include <algorithm> + #include <QApplication> #include <QMessageBox> #include <QMenuBar> #include <QFileDialog> +#include <QInputDialog> #include <QPaintEvent> #include <QPainter> #include <QKeyEvent> #include <QMimeData> +#include <QSet> +#include <QVector> #include <SDL2/SDL.h> @@ -63,6 +70,7 @@ #include "main_shaders.h" +#include "ArchiveUtil.h" // TODO: uniform variable spelling @@ -1441,7 +1449,6 @@ QString MainWindow::loadErrorStr(int error) } } - void MainWindow::onOpenFile() { emuThread->emuPause(); @@ -1449,7 +1456,53 @@ void MainWindow::onOpenFile() QString filename = QFileDialog::getOpenFileName(this, "Open ROM", Config::LastROMFolder, - "DS ROMs (*.nds *.dsi *.srl);;GBA ROMs (*.gba);;Any file (*.*)"); + "DS ROMs (*.nds *.dsi *.srl *.zip *.7z);;GBA ROMs (*.gba *.zip *.7z);;Other Compressed ROMs (*.zip *.7z *.rar *.tar *.tar.gz *.tar.xz *tar.bz2);;Any file (*.*)"); + + static const QSet<QString> compressedExts = {"zip", "7z", "rar", "tar", "tar.gz", "tar.xz", "tar.bz2"}; + if (compressedExts.contains(QFileInfo(filename).completeSuffix())) + { + printf("Finding list of ROMs...\n"); + QVector<QString> archiveROMList = Archive::ListArchive(filename.toUtf8().constData()); + if (archiveROMList.size() > 2) + { + archiveROMList.removeFirst(); + QString toLoad = QInputDialog::getItem(this, "melonDS", + "The archive was found to have multiple files. Select which ROM you want to load.", archiveROMList.toList(), 0, false); + printf("Extracting '%s'\n", toLoad.toUtf8().constData()); + QVector<QString> extractResult = Archive::ExtractFileFromArchive(filename.toUtf8().constData(), toLoad.toUtf8().constData()); + if (extractResult[0] != QString("Err")) + { + filename = extractResult[0]; + } + else + { + QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]); + } + } + else if (archiveROMList.size() == 2) + { + printf("Extracting the only ROM in archive\n"); + QVector<QString> extractResult = Archive::ExtractFileFromArchive(filename.toUtf8().constData(), nullptr); + if (extractResult[0] != QString("Err")) + { + filename = extractResult[0]; + } + else + { + QMessageBox::critical(this, "melonDS", QString("There was an error while trying to extract the ROM from the archive: ") + extractResult[1]); + } + } + else if ((archiveROMList.size() == 1) && (archiveROMList[0] == QString("OK"))) + { + QMessageBox::warning(this, "melonDS", "The archive is intact, but there are no files inside."); + } + else + { + QMessageBox::critical(this, "melonDS", "The archive could not be read. It may be corrupt or you don't have the permissions."); + } + + } + if (filename.isEmpty()) { emuThread->emuUnpause(); |