From ab2ff1829092cc4cdf810e20c4d758bd02842a58 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 7 Oct 2023 21:52:47 +0300 Subject: [PATCH] Fix dumping --- src/emulator.cpp | 29 +++++++++++++++-------------- src/panda_qt/main_window.cpp | 7 +++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/emulator.cpp b/src/emulator.cpp index e0de4a29..7555580b 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -583,24 +583,25 @@ void Emulator::updateDiscord() { void Emulator::updateDiscord() {} #endif -static void printNode(const RomFS::RomFSNode& node, int indentation) { - for (int i = 0; i < indentation; i++) { - printf(" "); - } - printf("%s/\n", std::string(node.name.begin(), node.name.end()).c_str()); - +static void printNode(const RomFS::RomFSNode& node, const char* romFSBase, const std::filesystem::path& path) { for (auto& file : node.files) { - for (int i = 0; i <= indentation; i++) { - printf(" "); - } - printf("%s\n", std::string(file->name.begin(), file->name.end()).c_str()); + const auto p = path / file->name; + std::ofstream outFile(p); + + outFile.write(romFSBase + file->dataOffset, file->dataSize); } - indentation++; for (auto& directory : node.directories) { - printNode(*directory, indentation); + const auto newPath = path / directory->name; + + // Create the directory for the new folder + std::error_code ec; + std::filesystem::create_directories(newPath, ec); + + if (!ec) { + printNode(*directory, romFSBase, newPath); + } } - indentation--; } RomFS::DumpingResult Emulator::dumpRomFS(const std::filesystem::path& path) { @@ -637,7 +638,7 @@ RomFS::DumpingResult Emulator::dumpRomFS(const std::filesystem::path& path) { } std::unique_ptr node = parseRomFSTree((uintptr_t)&romFS[0], size); - printNode(*node, 0); + printNode(*node, (const char*) &romFS[0], path); return DumpingResult::Success; } \ No newline at end of file diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index 977a7f80..8c57e335 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -77,7 +77,6 @@ void MainWindow::emuThreadMainLoop() { } needToLoadROM.store(false, std::memory_order::seq_cst); - emu->dumpRomFS(""); } emu->runFrame(); @@ -105,8 +104,8 @@ void MainWindow::selectROM() { return; } - auto path = QFileDialog::getOpenFileName( - this, tr("Select 3DS ROM to load"), {}, tr("Nintendo 3DS ROMs (*.3ds *.cci *.cxi *.app *.3dsx *.elf *.axf)"), {}); + auto path = + QFileDialog::getOpenFileName(this, tr("Select 3DS ROM to load"), "", tr("Nintendo 3DS ROMs (*.3ds *.cci *.cxi *.app *.3dsx *.elf *.axf)")); if (!path.isEmpty()) { romToLoad = path.toStdU16String(); @@ -195,5 +194,5 @@ void MainWindow::dumpRomFS() { } std::filesystem::path path(folder.toStdU16String()); - //RomFS::DumpingResult res = emu->dumpRomFS(path); + RomFS::DumpingResult res = emu->dumpRomFS(path); } \ No newline at end of file