aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorU-RAYYAN-PC\Rayyan <68647953+WaluigiWare64@users.noreply.github.com>2020-07-22 15:15:56 +0100
committerU-RAYYAN-PC\Rayyan <68647953+WaluigiWare64@users.noreply.github.com>2020-07-22 15:15:56 +0100
commit96e0e371567f90d9a08f1bf7108575fe15f6e1a0 (patch)
treef7181e6ff9b630b1005f71707ed6f45f72b9f350 /src
parent0009a3ffd193c43b2fbe90789f4e8317d973d60d (diff)
Link it up to onOpenFile()
Diffstat (limited to 'src')
-rw-r--r--src/frontend/qt_sdl/main.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp
index cc541ad..7dc72de 100644
--- a/src/frontend/qt_sdl/main.cpp
+++ b/src/frontend/qt_sdl/main.cpp
@@ -1403,15 +1403,6 @@ QString MainWindow::loadErrorStr(int error)
}
}
-std::string getFileExt(const std::string& s) {
-
- size_t i = s.rfind('.', s.length());
- if (i != std::string::npos) {
- return(s.substr(i+1, s.length() - i));
- }
-
- return("");
-}
std::string extractROM(char* zipName, std::string zipDir){
//Open the ZIP archive
int err = 0;
@@ -1432,10 +1423,8 @@ std::string extractROM(char* zipName, std::string zipDir){
zip_close(z);
//Write the file (binary mode)
- if(!std::ofstream(zipDir + "/" + st.name, std::ofstream::binary).write(contents, st.size))
- {
- std::cerr << "Error writing file" << '\n';
- }
+ std::ofstream(zipDir + "/" + st.name, std::ofstream::binary).write(contents, st.size);
+
return zipDir + "/" + st.name;
}
@@ -1443,11 +1432,23 @@ void MainWindow::onOpenFile()
{
emuThread->emuPause();
+ bool romExtracted = false; //No use yet but may be useful later
QString filename = QFileDialog::getOpenFileName(this,
"Open ROM",
Config::LastROMFolder,
- "DS ROMs (*.nds *.dsi *.srl);;GBA ROMs (*.gba);;Any file (*.*)");
- if (filename.isEmpty())
+ "DS ROMs (*.nds *.dsi *.srl *.zip);;GBA ROMs (*.gba *.zip);;Any file (*.*)");
+ QFileInfo filenameExtLoc = filename;
+
+ if (filenameExtLoc.completeSuffix().toUtf8() == "zip")
+ {
+ printf("Extracting ROM from ZIP...\n");
+ std::string extractRomLoc = extractROM(filename.toUtf8().data(), filenameExtLoc.absolutePath().toUtf8().data());
+ printf("Done.\n");
+ filename = QString::fromUtf8(extractRomLoc.c_str());
+ romExtracted = true;
+ }
+
+ if (filename.isEmpty())
{
emuThread->emuUnpause();
return;