Skip to content

Commit

Permalink
Merge pull request #314 from hydra-emu/wrage-4
Browse files Browse the repository at this point in the history
Fix android app data path
  • Loading branch information
OFFTKP authored Oct 17, 2023
2 parents e57256a + ab83fc1 commit afa2bbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,25 +449,33 @@ bool Emulator::loadROM(const std::filesystem::path& path) {
memory.loadedCXI = std::nullopt;
memory.loaded3DSX = std::nullopt;

// Get path for saving files (AppData on Windows, /home/user/.local/share/ApplcationName on Linux, etc)
// 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
char* appData;
std::filesystem::path appDataPath;

#ifdef __ANDROID__
// SDL_GetPrefPath fails to get the path due to no JNI environment
std::ifstream cmdline("/proc/self/cmdline");
std::string applicationName;
std::getline(cmdline, applicationName, '\0');
appDataPath = std::filesystem::path("/data") / "data" / applicationName / "files";
#else
char* appData;
if (!config.usePortableBuild) {
appData = SDL_GetPrefPath(nullptr, "Alber");
appDataPath = std::filesystem::path(appData);
} else {
appData = SDL_GetBasePath();
appDataPath = std::filesystem::path(appData) / "Emulator Files";
}
SDL_free(appData);
#endif

const std::filesystem::path dataPath = appDataPath / path.filename().stem();
const std::filesystem::path aesKeysPath = appDataPath / "sysdata" / "aes_keys.txt";
IOFile::setAppDataDir(dataPath);
SDL_free(appData);

// Open the text file containing our AES keys if it exists. We use the std::filesystem::exists overload that takes an error code param to
// avoid the call throwing exceptions
Expand Down
5 changes: 3 additions & 2 deletions third_party/cryptopp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ find_package(Threads)
target_link_libraries(cryptopp PRIVATE ${CMAKE_THREAD_LIBS_INIT})

if(ANDROID)
include(AndroidNdkModules)
android_ndk_import_module_cpufeatures()
include_directories(${ANDROID_NDK}/sources/android/cpufeatures)
add_library(cpufeatures ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
target_link_libraries(cpufeatures dl)
target_link_libraries(cryptopp PRIVATE cpufeatures)
endif()

0 comments on commit afa2bbf

Please sign in to comment.