diff options
author | U-RAYYAN-PC\Rayyan <68647953+WaluigiWare64@users.noreply.github.com> | 2020-07-22 15:13:14 +0100 |
---|---|---|
committer | U-RAYYAN-PC\Rayyan <68647953+WaluigiWare64@users.noreply.github.com> | 2020-07-22 15:13:14 +0100 |
commit | 0009a3ffd193c43b2fbe90789f4e8317d973d60d (patch) | |
tree | 6b92577d5e2548fd7447302182c2640a8b41a278 /src/frontend/qt_sdl/main.cpp | |
parent | 523ff9ff1cc46f811fc60136673e1ca2adbf84ff (diff) |
Add the extractROM function
Diffstat (limited to 'src/frontend/qt_sdl/main.cpp')
-rw-r--r-- | src/frontend/qt_sdl/main.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index de6887c..cc541ad 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -21,6 +21,10 @@ #include <stdio.h> #include <string.h> +#include <zip.h> +#include <fstream> +#include <iostream> + #include <QApplication> #include <QMessageBox> #include <QMenuBar> @@ -1399,6 +1403,41 @@ 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; + zip *z = zip_open(zipName, 0, &err); + + struct zip_stat st; + zip_stat_init(&st); + zip_stat_index(z, 0, 0, &st); //Get information about the file at index 0 + + //Allocate memory for its uncompressed contents + char *contents = new char[st.size]; + + //Read the compressed file + zip_file *f = zip_fopen_index(z, 0, 0); //Open file at index 0 + zip_fread(f, contents, st.size); + zip_fclose(f); + + 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'; + } + return zipDir + "/" + st.name; +} void MainWindow::onOpenFile() { |