mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15:38 +00:00
(Android) Implemented a cleaner way of handling the private data directory
This commit is contained in:
parent
854cef60cb
commit
8571dfe7bf
|
@ -25,6 +25,10 @@
|
||||||
#include "views/GamelistView.h"
|
#include "views/GamelistView.h"
|
||||||
#include "views/ViewController.h"
|
#include "views/ViewController.h"
|
||||||
|
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#include "utils/PlatformUtilAndroid.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,10 @@
|
||||||
#include <SDL2/SDL_main.h>
|
#include <SDL2/SDL_main.h>
|
||||||
#include <SDL2/SDL_timer.h>
|
#include <SDL2/SDL_timer.h>
|
||||||
|
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#include "utils/PlatformUtilAndroid.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__EMSCRIPTEN__)
|
#if defined(__EMSCRIPTEN__)
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -696,32 +696,27 @@ void ThemeData::populateThemes()
|
||||||
userThemeDirectory = defaultUserThemeDir;
|
userThemeDirectory = defaultUserThemeDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__ANDROID__)
|
||||||
#if defined(APPIMAGE_BUILD)
|
const std::vector<std::string> themePaths {Utils::FileSystem::getProgramDataPath() + "/themes",
|
||||||
static const size_t pathCount {2};
|
userThemeDirectory};
|
||||||
#else
|
#elif defined(__APPLE__)
|
||||||
static const size_t pathCount {3};
|
const std::vector<std::string> themePaths {
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
static const size_t pathCount {2};
|
|
||||||
#endif
|
|
||||||
std::string paths[pathCount] = {
|
|
||||||
Utils::FileSystem::getExePath() + "/themes",
|
Utils::FileSystem::getExePath() + "/themes",
|
||||||
#if defined(__APPLE__)
|
Utils::FileSystem::getExePath() + "/../Resources/themes", userThemeDirectory};
|
||||||
Utils::FileSystem::getExePath() + "/../Resources/themes",
|
#elif defined(_WIN64) || defined(APPIMAGE_BUILD)
|
||||||
#elif defined(__ANDROID__)
|
const std::vector<std::string> themePaths {Utils::FileSystem::getExePath() + "/themes",
|
||||||
ResourceManager::getInstance().getDataDirectory() + "/themes",
|
userThemeDirectory};
|
||||||
#elif defined(__unix__) && !defined(APPIMAGE_BUILD)
|
#else
|
||||||
|
const std::vector<std::string> themePaths {Utils::FileSystem::getExePath() + "/themes",
|
||||||
Utils::FileSystem::getProgramDataPath() + "/themes",
|
Utils::FileSystem::getProgramDataPath() + "/themes",
|
||||||
|
userThemeDirectory};
|
||||||
#endif
|
#endif
|
||||||
userThemeDirectory
|
|
||||||
};
|
|
||||||
|
|
||||||
for (size_t i {0}; i < pathCount; ++i) {
|
for (auto path : themePaths) {
|
||||||
if (!Utils::FileSystem::isDirectory(paths[i]))
|
if (!Utils::FileSystem::isDirectory(path))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Utils::FileSystem::StringList dirContent {Utils::FileSystem::getDirContent(paths[i])};
|
Utils::FileSystem::StringList dirContent {Utils::FileSystem::getDirContent(path)};
|
||||||
|
|
||||||
for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin();
|
for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin();
|
||||||
it != dirContent.cend(); ++it) {
|
it != dirContent.cend(); ++it) {
|
||||||
|
@ -732,7 +727,6 @@ void ThemeData::populateThemes()
|
||||||
Utils::String::toLower(themeDirName.substr(themeDirName.length() - 8, 8)) ==
|
Utils::String::toLower(themeDirName.substr(themeDirName.length() - 8, 8)) ==
|
||||||
"disabled"))
|
"disabled"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
LOG(LogDebug) << "Loading theme capabilities for \""
|
LOG(LogDebug) << "Loading theme capabilities for \""
|
||||||
<< Utils::String::replace(*it, "/", "\\") << "\"...";
|
<< Utils::String::replace(*it, "/", "\\") << "\"...";
|
||||||
|
@ -745,9 +739,8 @@ void ThemeData::populateThemes()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string themeName;
|
std::string themeName;
|
||||||
if (capabilities.themeName != "") {
|
if (capabilities.themeName != "")
|
||||||
themeName.append(" (\"").append(capabilities.themeName).append("\")");
|
themeName.append(" (\"").append(capabilities.themeName).append("\")");
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
LOG(LogInfo) << "Added theme \"" << Utils::String::replace(*it, "/", "\\") << "\""
|
LOG(LogInfo) << "Added theme \"" << Utils::String::replace(*it, "/", "\\") << "\""
|
||||||
|
|
|
@ -41,18 +41,22 @@ std::string ResourceManager::getResourcePath(const std::string& path, bool termi
|
||||||
if (Utils::FileSystem::exists(applePackagePath)) {
|
if (Utils::FileSystem::exists(applePackagePath)) {
|
||||||
return applePackagePath;
|
return applePackagePath;
|
||||||
}
|
}
|
||||||
#elif defined(__unix__) && !defined(APPIMAGE_BUILD)
|
#elif (defined(__unix__) && !defined(APPIMAGE_BUILD)) || defined(__ANDROID__)
|
||||||
#if defined(__ANDROID__)
|
// Check in the program data directory.
|
||||||
std::string testDataPath {mDataDirectory + "/resources/" + &path[2]};
|
|
||||||
#else
|
|
||||||
// Check under the data installation directory (Unix only).
|
|
||||||
std::string testDataPath {Utils::FileSystem::getProgramDataPath() + "/resources/" +
|
std::string testDataPath {Utils::FileSystem::getProgramDataPath() + "/resources/" +
|
||||||
&path[2]};
|
&path[2]};
|
||||||
#endif
|
|
||||||
if (Utils::FileSystem::exists(testDataPath))
|
if (Utils::FileSystem::exists(testDataPath))
|
||||||
return testDataPath;
|
return testDataPath;
|
||||||
#endif
|
#endif
|
||||||
#if !defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
|
// Check in the assets directory using AssetManager.
|
||||||
|
SDL_RWops* resFile {SDL_RWFromFile(path.substr(2).c_str(), "rb")};
|
||||||
|
if (resFile != nullptr) {
|
||||||
|
SDL_RWclose(resFile);
|
||||||
|
return path.substr(2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#else
|
||||||
// Check under the ES executable directory.
|
// Check under the ES executable directory.
|
||||||
std::string testExePath {Utils::FileSystem::getExePath() + "/resources/" + &path[2]};
|
std::string testExePath {Utils::FileSystem::getExePath() + "/resources/" + &path[2]};
|
||||||
|
|
||||||
|
@ -63,13 +67,6 @@ std::string ResourceManager::getResourcePath(const std::string& path, bool termi
|
||||||
// indicate that we have a broken EmulationStation installation. If the argument
|
// indicate that we have a broken EmulationStation installation. If the argument
|
||||||
// terminateOnFailure is set to false though, then skip this step.
|
// terminateOnFailure is set to false though, then skip this step.
|
||||||
else {
|
else {
|
||||||
#else
|
|
||||||
SDL_RWops* resFile {SDL_RWFromFile(path.substr(2).c_str(), "rb")};
|
|
||||||
if (resFile != nullptr) {
|
|
||||||
SDL_RWclose(resFile);
|
|
||||||
return path.substr(2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
#endif
|
#endif
|
||||||
if (terminateOnFailure) {
|
if (terminateOnFailure) {
|
||||||
LOG(LogError) << "Program resource missing: " << path;
|
LOG(LogError) << "Program resource missing: " << path;
|
||||||
|
@ -102,6 +99,7 @@ const ResourceData ResourceManager::getFileData(const std::string& path) const
|
||||||
const std::string respath {getResourcePath(path)};
|
const std::string respath {getResourcePath(path)};
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
|
// Check in the assets directory using AssetManager.
|
||||||
SDL_RWops* resFile {SDL_RWFromFile(respath.c_str(), "rb")};
|
SDL_RWops* resFile {SDL_RWFromFile(respath.c_str(), "rb")};
|
||||||
if (resFile != nullptr) {
|
if (resFile != nullptr) {
|
||||||
ResourceData data {loadFile(resFile)};
|
ResourceData data {loadFile(resFile)};
|
||||||
|
|
|
@ -44,9 +44,6 @@ public:
|
||||||
void unloadAll();
|
void unloadAll();
|
||||||
void reloadAll();
|
void reloadAll();
|
||||||
|
|
||||||
void setDataDirectory(const std::string& dataDirectory) { mDataDirectory = dataDirectory; }
|
|
||||||
const std::string& getDataDirectory() const { return mDataDirectory; }
|
|
||||||
|
|
||||||
std::string getResourcePath(const std::string& path, bool terminateOnFailure = true) const;
|
std::string getResourcePath(const std::string& path, bool terminateOnFailure = true) const;
|
||||||
const ResourceData getFileData(const std::string& path) const;
|
const ResourceData getFileData(const std::string& path) const;
|
||||||
bool fileExists(const std::string& path) const;
|
bool fileExists(const std::string& path) const;
|
||||||
|
@ -58,7 +55,6 @@ private:
|
||||||
ResourceData loadFile(SDL_RWops* resFile) const;
|
ResourceData loadFile(SDL_RWops* resFile) const;
|
||||||
|
|
||||||
std::list<std::weak_ptr<IReloadable>> mReloadables;
|
std::list<std::weak_ptr<IReloadable>> mReloadables;
|
||||||
std::string mDataDirectory;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_CORE_RESOURCES_RESOURCE_MANAGER_H
|
#endif // ES_CORE_RESOURCES_RESOURCE_MANAGER_H
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
// remove files etc.
|
// remove files etc.
|
||||||
//
|
//
|
||||||
|
|
||||||
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && \
|
#if defined(__ANDROID__)
|
||||||
!defined(__NetBSD__) && !defined(__EMSCRIPTEN__)
|
#include "utils/PlatformUtilAndroid.h"
|
||||||
#define _FILE_OFFSET_BITS 64
|
#include <SDL2/SDL_system.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
@ -365,7 +365,9 @@ namespace Utils
|
||||||
|
|
||||||
std::string getProgramDataPath()
|
std::string getProgramDataPath()
|
||||||
{
|
{
|
||||||
#if defined(__unix__)
|
#if defined(__ANDROID__)
|
||||||
|
return AndroidVariables::sAndroidDataDirectory;
|
||||||
|
#elif defined(__unix__)
|
||||||
return installPrefix + "/share/emulationstation";
|
return installPrefix + "/share/emulationstation";
|
||||||
#else
|
#else
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -15,11 +15,6 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
#include "utils/PlatformUtilAndroid.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
namespace Platform
|
namespace Platform
|
||||||
|
|
Loading…
Reference in a new issue