mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05: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/ViewController.h"
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "utils/PlatformUtilAndroid.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <regex>
|
||||
|
||||
|
|
|
@ -37,6 +37,10 @@
|
|||
#include <SDL2/SDL_main.h>
|
||||
#include <SDL2/SDL_timer.h>
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "utils/PlatformUtilAndroid.h"
|
||||
#endif
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
|
|
@ -696,32 +696,27 @@ void ThemeData::populateThemes()
|
|||
userThemeDirectory = defaultUserThemeDir;
|
||||
}
|
||||
|
||||
#if defined(__unix__) || defined(__APPLE__)
|
||||
#if defined(APPIMAGE_BUILD)
|
||||
static const size_t pathCount {2};
|
||||
#else
|
||||
static const size_t pathCount {3};
|
||||
#endif
|
||||
#else
|
||||
static const size_t pathCount {2};
|
||||
#endif
|
||||
std::string paths[pathCount] = {
|
||||
#if defined(__ANDROID__)
|
||||
const std::vector<std::string> themePaths {Utils::FileSystem::getProgramDataPath() + "/themes",
|
||||
userThemeDirectory};
|
||||
#elif defined(__APPLE__)
|
||||
const std::vector<std::string> themePaths {
|
||||
Utils::FileSystem::getExePath() + "/themes",
|
||||
#if defined(__APPLE__)
|
||||
Utils::FileSystem::getExePath() + "/../Resources/themes",
|
||||
#elif defined(__ANDROID__)
|
||||
ResourceManager::getInstance().getDataDirectory() + "/themes",
|
||||
#elif defined(__unix__) && !defined(APPIMAGE_BUILD)
|
||||
Utils::FileSystem::getProgramDataPath() + "/themes",
|
||||
Utils::FileSystem::getExePath() + "/../Resources/themes", userThemeDirectory};
|
||||
#elif defined(_WIN64) || defined(APPIMAGE_BUILD)
|
||||
const std::vector<std::string> themePaths {Utils::FileSystem::getExePath() + "/themes",
|
||||
userThemeDirectory};
|
||||
#else
|
||||
const std::vector<std::string> themePaths {Utils::FileSystem::getExePath() + "/themes",
|
||||
Utils::FileSystem::getProgramDataPath() + "/themes",
|
||||
userThemeDirectory};
|
||||
#endif
|
||||
userThemeDirectory
|
||||
};
|
||||
|
||||
for (size_t i {0}; i < pathCount; ++i) {
|
||||
if (!Utils::FileSystem::isDirectory(paths[i]))
|
||||
for (auto path : themePaths) {
|
||||
if (!Utils::FileSystem::isDirectory(path))
|
||||
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();
|
||||
it != dirContent.cend(); ++it) {
|
||||
|
@ -732,7 +727,6 @@ void ThemeData::populateThemes()
|
|||
Utils::String::toLower(themeDirName.substr(themeDirName.length() - 8, 8)) ==
|
||||
"disabled"))
|
||||
continue;
|
||||
|
||||
#if defined(_WIN64)
|
||||
LOG(LogDebug) << "Loading theme capabilities for \""
|
||||
<< Utils::String::replace(*it, "/", "\\") << "\"...";
|
||||
|
@ -745,9 +739,8 @@ void ThemeData::populateThemes()
|
|||
continue;
|
||||
|
||||
std::string themeName;
|
||||
if (capabilities.themeName != "") {
|
||||
if (capabilities.themeName != "")
|
||||
themeName.append(" (\"").append(capabilities.themeName).append("\")");
|
||||
}
|
||||
|
||||
#if defined(_WIN64)
|
||||
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)) {
|
||||
return applePackagePath;
|
||||
}
|
||||
#elif defined(__unix__) && !defined(APPIMAGE_BUILD)
|
||||
#if defined(__ANDROID__)
|
||||
std::string testDataPath {mDataDirectory + "/resources/" + &path[2]};
|
||||
#else
|
||||
// Check under the data installation directory (Unix only).
|
||||
#elif (defined(__unix__) && !defined(APPIMAGE_BUILD)) || defined(__ANDROID__)
|
||||
// Check in the program data directory.
|
||||
std::string testDataPath {Utils::FileSystem::getProgramDataPath() + "/resources/" +
|
||||
&path[2]};
|
||||
#endif
|
||||
if (Utils::FileSystem::exists(testDataPath))
|
||||
return testDataPath;
|
||||
#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.
|
||||
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
|
||||
// terminateOnFailure is set to false though, then skip this step.
|
||||
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
|
||||
if (terminateOnFailure) {
|
||||
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)};
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
// Check in the assets directory using AssetManager.
|
||||
SDL_RWops* resFile {SDL_RWFromFile(respath.c_str(), "rb")};
|
||||
if (resFile != nullptr) {
|
||||
ResourceData data {loadFile(resFile)};
|
||||
|
|
|
@ -44,9 +44,6 @@ public:
|
|||
void unloadAll();
|
||||
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;
|
||||
const ResourceData getFileData(const std::string& path) const;
|
||||
bool fileExists(const std::string& path) const;
|
||||
|
@ -58,7 +55,6 @@ private:
|
|||
ResourceData loadFile(SDL_RWops* resFile) const;
|
||||
|
||||
std::list<std::weak_ptr<IReloadable>> mReloadables;
|
||||
std::string mDataDirectory;
|
||||
};
|
||||
|
||||
#endif // ES_CORE_RESOURCES_RESOURCE_MANAGER_H
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
// remove files etc.
|
||||
//
|
||||
|
||||
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && \
|
||||
!defined(__NetBSD__) && !defined(__EMSCRIPTEN__)
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#if defined(__ANDROID__)
|
||||
#include "utils/PlatformUtilAndroid.h"
|
||||
#include <SDL2/SDL_system.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
@ -365,10 +365,12 @@ namespace Utils
|
|||
|
||||
std::string getProgramDataPath()
|
||||
{
|
||||
#if defined(__unix__)
|
||||
#if defined(__ANDROID__)
|
||||
return AndroidVariables::sAndroidDataDirectory;
|
||||
#elif defined(__unix__)
|
||||
return installPrefix + "/share/emulationstation";
|
||||
#else
|
||||
return "";
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,6 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "utils/PlatformUtilAndroid.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
namespace Platform
|
||||
|
|
Loading…
Reference in a new issue