Skip to content

Commit

Permalink
Merge pull request #372 from wheremyfoodat/pander3ds
Browse files Browse the repository at this point in the history
More app folder utilities & "Open Panda3DS folder" button
  • Loading branch information
wheremyfoodat authored Jan 21, 2024
2 parents b571801 + 75663d0 commit 1791159
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
2 changes: 2 additions & 0 deletions include/emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class Emulator {

std::filesystem::path getConfigPath();
std::filesystem::path getAndroidAppPath();
// Get the root path for the emulator's app data
std::filesystem::path getAppDataRoot();

std::span<u8> getSMDH();
};
39 changes: 22 additions & 17 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,16 @@ void Emulator::runFrame() {
}
}

bool Emulator::loadROM(const std::filesystem::path& path) {
// Reset the emulator if we've already loaded a ROM
if (romType != ROMType::None) {
reset(ReloadOption::NoReload);
}

// Reset whatever state needs to be reset before loading a new ROM
memory.loadedCXI = std::nullopt;
memory.loaded3DSX = std::nullopt;

// Get path for saving files (AppData on Windows, /home/user/.local/share/ApplicationName on Linux, etc)
// Inside that path, we be use a game-specific folder as well. Eg if we were loading a ROM called PenguinDemo.3ds, the savedata would be in
// %APPDATA%/Alber/PenguinDemo/SaveData on Windows, and so on. We do this because games save data in their own filesystem on the cart.
// If the portable build setting is enabled, then those saves go in the executable directory instead
// Get path for saving files (AppData on Windows, /home/user/.local/share/ApplicationName on Linux, etc)
// Inside that path, we be use a game-specific folder as well. Eg if we were loading a ROM called PenguinDemo.3ds, the savedata would be in
// %APPDATA%/Alber/PenguinDemo/SaveData on Windows, and so on. We do this because games save data in their own filesystem on the cart.
// If the portable build setting is enabled, then those saves go in the executable directory instead
std::filesystem::path Emulator::getAppDataRoot() {
std::filesystem::path appDataPath;

#ifdef __ANDROID__
#ifdef __ANDROID__
appDataPath = getAndroidAppPath();
#else
#else
char* appData;
if (!config.usePortableBuild) {
appData = SDL_GetPrefPath(nullptr, "Alber");
Expand All @@ -145,8 +136,22 @@ bool Emulator::loadROM(const std::filesystem::path& path) {
appDataPath = std::filesystem::path(appData) / "Emulator Files";
}
SDL_free(appData);
#endif
#endif

return appDataPath;
}

bool Emulator::loadROM(const std::filesystem::path& path) {
// Reset the emulator if we've already loaded a ROM
if (romType != ROMType::None) {
reset(ReloadOption::NoReload);
}

// Reset whatever state needs to be reset before loading a new ROM
memory.loadedCXI = std::nullopt;
memory.loaded3DSX = std::nullopt;

const std::filesystem::path appDataPath = getAppDataRoot();
const std::filesystem::path dataPath = appDataPath / path.filename().stem();
const std::filesystem::path aesKeysPath = appDataPath / "sysdata" / "aes_keys.txt";
IOFile::setAppDataDir(dataPath);
Expand Down
11 changes: 9 additions & 2 deletions src/panda_qt/main_window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "panda_qt/main_window.hpp"

#include <QDesktopServices>
#include <QFileDialog>
#include <QString>
#include <cstdio>
#include <fstream>

Expand All @@ -26,8 +28,14 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
// Create and bind actions for them
auto loadGameAction = fileMenu->addAction(tr("Load game"));
auto loadLuaAction = fileMenu->addAction(tr("Load Lua script"));
auto openAppFolderAction = fileMenu->addAction(tr("Open Panda3DS folder"));

connect(loadGameAction, &QAction::triggered, this, &MainWindow::selectROM);
connect(loadLuaAction, &QAction::triggered, this, &MainWindow::selectLuaFile);
connect(openAppFolderAction, &QAction::triggered, this, [this]() {
QString path = QString::fromStdU16String(emu->getAppDataRoot().u16string());
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
});

auto pauseAction = emulationMenu->addAction(tr("Pause"));
auto resumeAction = emulationMenu->addAction(tr("Resume"));
Expand Down Expand Up @@ -194,8 +202,7 @@ void MainWindow::dumpRomFS() {
return;
}
std::filesystem::path path(folder.toStdU16String());

// TODO: This might break if the game accesses RomFS while we're dumping, we should move it to the emulator thread when we've got a message queue going

messageQueueMutex.lock();
RomFS::DumpingResult res = emu->dumpRomFS(path);
messageQueueMutex.unlock();
Expand Down

0 comments on commit 1791159

Please sign in to comment.