Removed all instances of hardcoded application directory entries

Also changed some source file headers
This commit is contained in:
Leon Styhre 2023-12-15 18:33:02 +01:00
parent 0a2b9f8595
commit 56ccba81d1
32 changed files with 223 additions and 203 deletions

View file

@ -1,6 +1,6 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# #
# EmulationStation Desktop Edition # ES-DE
# CMakeLists.txt (es-app) # CMakeLists.txt (es-app)
# #
# CMake configuration for es-app # CMake configuration for es-app

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// ApplicationUpdater.cpp // ApplicationUpdater.cpp
// //
// Checks for application updates. // Checks for application updates.
@ -211,14 +211,14 @@ void ApplicationUpdater::parseFile()
#if (LOCAL_TESTING_FILE) #if (LOCAL_TESTING_FILE)
LOG(LogWarning) << "ApplicationUpdater: Using local \"latest_release.json\" testing file"; LOG(LogWarning) << "ApplicationUpdater: Using local \"latest_release.json\" testing file";
const std::string localReleaseFile {Utils::FileSystem::getHomePath() + const std::filesystem::path localReleaseFile {
"/.emulationstation/latest_release.json"}; Utils::FileSystem::getAppDataDirectory().append("latest_release.json")};
if (!Utils::FileSystem::exists(localReleaseFile)) if (!Utils::FileSystem::existsSTD(localReleaseFile))
throw std::runtime_error("Local testing file not found"); throw std::runtime_error("Local testing file not found");
const ResourceData& localReleaseFileData { const ResourceData& localReleaseFileData {
ResourceManager::getInstance().getFileData(localReleaseFile)}; ResourceManager::getInstance().getFileData(localReleaseFile.string())};
doc.Parse(reinterpret_cast<const char*>(localReleaseFileData.ptr.get()), doc.Parse(reinterpret_cast<const char*>(localReleaseFileData.ptr.get()),
localReleaseFileData.length); localReleaseFileData.length);
#else #else

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// ApplicationUpdater.h // ApplicationUpdater.h
// //
// Checks for application updates. // Checks for application updates.

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// CollectionSystemsManager.cpp // CollectionSystemsManager.cpp
// //
// Manages collections of the following two types: // Manages collections of the following two types:
@ -1437,7 +1437,7 @@ std::vector<std::string> CollectionSystemsManager::getSystemsFromConfig()
std::vector<std::string> configPaths {SystemData::getConfigPath()}; std::vector<std::string> configPaths {SystemData::getConfigPath()};
// Here we don't honor the <loadExclusive> tag which may be present in the custom es_systems.xml // Here we don't honor the <loadExclusive> tag which may be present in the custom es_systems.xml
// file under ~/.emulationstation/custom_systems as we really want to include all the themes // file under <application data>/custom_systems as we really want to include all the themes
// supported by ES-DE. Otherwise a user may accidentally create a custom collection that // supported by ES-DE. Otherwise a user may accidentally create a custom collection that
// corresponds to a supported theme. // corresponds to a supported theme.
for (auto path : configPaths) { for (auto path : configPaths) {
@ -1625,6 +1625,5 @@ std::string CollectionSystemsManager::getCustomCollectionConfigPath(
std::string CollectionSystemsManager::getCollectionsFolder() std::string CollectionSystemsManager::getCollectionsFolder()
{ {
return Utils::FileSystem::getGenericPath(Utils::FileSystem::getHomePath() + return Utils::FileSystem::getAppDataDirectory().append("collections").string();
"/.emulationstation/collections");
} }

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// CollectionSystemsManager.h // CollectionSystemsManager.h
// //
// Manages collections of the following two types: // Manages collections of the following two types:

View file

@ -152,6 +152,10 @@ const std::vector<FileData*> FileData::getChildrenRecursive() const
const std::string FileData::getROMDirectory() const std::string FileData::getROMDirectory()
{ {
#if defined(__ANDROID__)
return AndroidVariables::sROMDirectory.string();
#endif
const std::string& romDirSetting {Settings::getInstance()->getString("ROMDirectory")}; const std::string& romDirSetting {Settings::getInstance()->getString("ROMDirectory")};
std::string romDirPath; std::string romDirPath;
@ -184,8 +188,9 @@ const std::string FileData::getMediaDirectory()
const std::string& mediaDirSetting {Settings::getInstance()->getString("MediaDirectory")}; const std::string& mediaDirSetting {Settings::getInstance()->getString("MediaDirectory")};
std::string mediaDirPath; std::string mediaDirPath;
if (mediaDirSetting == "") { if (mediaDirSetting.empty()) {
mediaDirPath = Utils::FileSystem::getHomePath() + "/.emulationstation/downloaded_media/"; mediaDirPath =
Utils::FileSystem::getAppDataDirectory().append("downloaded_media").string() + "/";
} }
else { else {
mediaDirPath = mediaDirSetting; mediaDirPath = mediaDirSetting;

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// SystemData.cpp // SystemData.cpp
// //
// Provides data structures for the game systems and populates and indexes them based // Provides data structures for the game systems and populates and indexes them based
@ -41,11 +41,11 @@ FindRules::FindRules()
void FindRules::loadFindRules() void FindRules::loadFindRules()
{ {
std::vector<std::string> paths; std::vector<std::filesystem::path> paths;
std::string filePath {Utils::FileSystem::getHomePath() + "/.emulationstation/custom_systems" + std::filesystem::path filePath {Utils::FileSystem::getAppDataDirectory()
"/es_find_rules.xml"}; .append("custom_systems")
.append("es_find_rules.xml")};
if (Utils::FileSystem::exists(filePath)) { if (Utils::FileSystem::existsSTD(filePath)) {
paths.emplace_back(filePath); paths.emplace_back(filePath);
LOG(LogInfo) << "Found custom find rules configuration file"; LOG(LogInfo) << "Found custom find rules configuration file";
} }
@ -64,28 +64,28 @@ void FindRules::loadFindRules()
ResourceManager::getInstance().getResourcePath(":/systems/unix/es_find_rules.xml", false); ResourceManager::getInstance().getResourcePath(":/systems/unix/es_find_rules.xml", false);
#endif #endif
if (filePath == "" && paths.empty()) { if (filePath.empty() && paths.empty()) {
LOG(LogWarning) << "No find rules configuration file found"; LOG(LogWarning) << "No find rules configuration file found";
return; return;
} }
if (filePath != "") if (!filePath.empty())
paths.emplace_back(filePath); paths.emplace_back(filePath);
for (auto& path : paths) { for (auto& path : paths) {
#if defined(_WIN64) #if defined(_WIN64)
LOG(LogInfo) << "Parsing find rules configuration file \"" LOG(LogInfo) << "Parsing find rules configuration file \""
<< Utils::String::replace(path, "/", "\\") << "\"..."; << Utils::String::replace(path.string(), "/", "\\") << "\"...";
#else #else
LOG(LogInfo) << "Parsing find rules configuration file \"" << path << "\"..."; LOG(LogInfo) << "Parsing find rules configuration file \"" << path.string() << "\"...";
#endif #endif
pugi::xml_document doc; pugi::xml_document doc;
#if defined(_WIN64) #if defined(_WIN64)
const pugi::xml_parse_result& res { const pugi::xml_parse_result& res {
doc.load_file(Utils::String::stringToWideString(path).c_str())}; doc.load_file(Utils::String::stringToWideString(path.string()).c_str())};
#else #else
const pugi::xml_parse_result& res {doc.load_file(path.c_str())}; const pugi::xml_parse_result& res {doc.load_file(path.string().c_str())};
#endif #endif
if (!res) { if (!res) {
LOG(LogError) << "Couldn't parse es_find_rules.xml: " << res.description(); LOG(LogError) << "Couldn't parse es_find_rules.xml: " << res.description();
@ -848,10 +848,10 @@ bool SystemData::loadConfig()
void SystemData::loadSortingConfig() void SystemData::loadSortingConfig()
{ {
const std::string sortSetting {Settings::getInstance()->getString("SystemsSorting")}; const std::string sortSetting {Settings::getInstance()->getString("SystemsSorting")};
const std::string customFilePath {Utils::FileSystem::getHomePath() + const std::filesystem::path customFilePath {Utils::FileSystem::getAppDataDirectory()
"/.emulationstation/custom_systems" + .append("custom_systems")
"/es_systems_sorting.xml"}; .append("es_systems_sorting.xml")};
const bool customFileExists {Utils::FileSystem::exists(customFilePath)}; const bool customFileExists {Utils::FileSystem::existsSTD(customFilePath)};
std::string path; std::string path;
bool bundledFile {false}; bool bundledFile {false};
@ -882,10 +882,10 @@ void SystemData::loadSortingConfig()
"bundled file has been selected"; "bundled file has been selected";
} }
else if (!bundledFile && customFileExists) { else if (!bundledFile && customFileExists) {
path = customFilePath; path = customFilePath.string();
} }
if (path == "") { if (path.empty()) {
LOG(LogDebug) << "No systems sorting file loaded"; LOG(LogDebug) << "No systems sorting file loaded";
return; return;
} }
@ -957,18 +957,19 @@ std::vector<std::string> SystemData::getConfigPath()
{ {
std::vector<std::string> paths; std::vector<std::string> paths;
const std::string& customSystemsDirectory {Utils::FileSystem::getHomePath() + const std::filesystem::path customSystemsDirectory {
"/.emulationstation/custom_systems"}; Utils::FileSystem::getAppDataDirectory().append("custom_systems")};
if (!Utils::FileSystem::exists(customSystemsDirectory)) { if (!Utils::FileSystem::existsSTD(customSystemsDirectory)) {
LOG(LogInfo) << "Creating custom systems directory \"" << customSystemsDirectory << "\"..."; LOG(LogInfo) << "Creating custom systems directory \"" << customSystemsDirectory.string()
Utils::FileSystem::createDirectory(customSystemsDirectory); << "\"...";
if (!Utils::FileSystem::exists(customSystemsDirectory)) { Utils::FileSystem::createDirectory(customSystemsDirectory.string());
if (!Utils::FileSystem::existsSTD(customSystemsDirectory)) {
LOG(LogError) << "Couldn't create directory, permission problems?"; LOG(LogError) << "Couldn't create directory, permission problems?";
} }
} }
std::string path {customSystemsDirectory + "/es_systems.xml"}; std::string path {customSystemsDirectory.string() + "/es_systems.xml"};
if (Utils::FileSystem::exists(path)) { if (Utils::FileSystem::exists(path)) {
LOG(LogInfo) << "Found custom systems configuration file"; LOG(LogInfo) << "Found custom systems configuration file";
@ -1307,36 +1308,36 @@ SystemData* SystemData::getPrev() const
std::string SystemData::getGamelistPath(bool forWrite) const std::string SystemData::getGamelistPath(bool forWrite) const
{ {
std::string filePath {mRootFolder->getPath() + "/gamelist.xml"}; std::filesystem::path filePath {mRootFolder->getPath() + "/gamelist.xml"};
const std::string gamelistPath {Utils::FileSystem::getHomePath() + const std::filesystem::path gamelistPath {
"/.emulationstation/gamelists/" + mName}; Utils::FileSystem::getAppDataDirectory().append("gamelists").append(mName)};
if (Utils::FileSystem::exists(filePath)) { if (Utils::FileSystem::existsSTD(filePath)) {
if (Settings::getInstance()->getBool("LegacyGamelistFileLocation")) { if (Settings::getInstance()->getBool("LegacyGamelistFileLocation")) {
return filePath; return filePath.string();
} }
else { else {
#if defined(_WIN64) #if defined(_WIN64)
LOG(LogWarning) << "Found a gamelist.xml file in \"" LOG(LogWarning) << "Found a gamelist.xml file in \""
<< Utils::String::replace(mRootFolder->getPath(), "/", "\\") << Utils::String::replace(mRootFolder->getPath(), "/", "\\")
<< "\\\" which will not get loaded, move it to \"" << "\\\" which will not get loaded, move it to \""
<< Utils::String::replace(gamelistPath, "/", "\\") << gamelistPath.string() << "\\\" or otherwise delete it";
<< "\\\" or otherwise delete it";
#else #else
LOG(LogWarning) << "Found a gamelist.xml file in \"" << mRootFolder->getPath() LOG(LogWarning) << "Found a gamelist.xml file in \"" << mRootFolder->getPath()
<< "/\" which will not get loaded, move it to \"" << gamelistPath << "/\" which will not get loaded, move it to \""
<< "/\" or otherwise delete it"; << gamelistPath.string() << "/\" or otherwise delete it";
#endif #endif
} }
} }
filePath = gamelistPath + "/gamelist.xml"; filePath = gamelistPath;
filePath.append("gamelist.xml");
// Make sure the directory exists if we're going to write to it, or crashes will happen. // Make sure the directory exists if we're going to write to it, or crashes will happen.
if (forWrite) if (forWrite)
Utils::FileSystem::createDirectory(Utils::FileSystem::getParent(filePath)); Utils::FileSystem::createDirectory(Utils::FileSystem::getParent(filePath.string()));
if (forWrite || Utils::FileSystem::exists(filePath)) if (forWrite || Utils::FileSystem::existsSTD(filePath))
return filePath; return filePath.string();
return ""; return "";
} }

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// SystemData.h // SystemData.h
// //
// Provides data structures for the game systems and populates and indexes them based // Provides data structures for the game systems and populates and indexes them based

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// GuiMenu.cpp // GuiMenu.cpp
// //
// Main menu. // Main menu.
@ -1183,7 +1183,8 @@ void GuiMenu::openOtherOptions()
rowMediaDir.addElement(bracketMediaDirectory, false); rowMediaDir.addElement(bracketMediaDirectory, false);
std::string titleMediaDir {"ENTER GAME MEDIA DIRECTORY"}; std::string titleMediaDir {"ENTER GAME MEDIA DIRECTORY"};
std::string mediaDirectoryStaticText {"Default directory:"}; std::string mediaDirectoryStaticText {"Default directory:"};
std::string defaultDirectoryText {"~/.emulationstation/downloaded_media/"}; std::string defaultDirectoryText {
Utils::FileSystem::getAppDataDirectory().append("downloaded_media").string()};
std::string initValueMediaDir {Settings::getInstance()->getString("MediaDirectory")}; std::string initValueMediaDir {Settings::getInstance()->getString("MediaDirectory")};
bool multiLineMediaDir {false}; bool multiLineMediaDir {false};
auto updateValMediaDir = [this](const std::string& newVal) { auto updateValMediaDir = [this](const std::string& newVal) {

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// GuiMenu.h // GuiMenu.h
// //
// Main menu. // Main menu.

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// GuiThemeDownloader.cpp // GuiThemeDownloader.cpp
// //
// Theme downloader. // Theme downloader.
@ -174,28 +174,33 @@ GuiThemeDownloader::GuiThemeDownloader(std::function<void()> updateCallback)
std::promise<bool>().swap(mPromise); std::promise<bool>().swap(mPromise);
mFuture = mPromise.get_future(); mFuture = mPromise.get_future();
const std::string defaultUserThemeDir {Utils::FileSystem::getHomePath() + #if defined(__ANDROID__)
"/.emulationstation/themes"}; mThemeDirectory = Utils::FileSystem::getInternalAppDataDirectory().append("themes").string();
std::string userThemeDirSetting {Utils::FileSystem::expandHomePath( #else
const std::filesystem::path defaultUserThemeDir {
Utils::FileSystem::getAppDataDirectory().append("themes")};
const std::filesystem::path userThemeDirSetting {Utils::FileSystem::expandHomePath(
Settings::getInstance()->getString("UserThemeDirectory"))}; Settings::getInstance()->getString("UserThemeDirectory"))};
#if defined(_WIN64) #if defined(_WIN64)
mThemeDirectory = Utils::String::replace(mThemeDirectory, "\\", "/"); mThemeDirectory = Utils::String::replace(mThemeDirectory, "\\", "/");
#endif #endif
if (userThemeDirSetting == "") { if (userThemeDirSetting.empty()) {
mThemeDirectory = defaultUserThemeDir; mThemeDirectory = defaultUserThemeDir.string();
} }
else if (Utils::FileSystem::isDirectory(userThemeDirSetting) || else if (Utils::FileSystem::isDirectorySTD(userThemeDirSetting) ||
Utils::FileSystem::isSymlink(userThemeDirSetting)) { Utils::FileSystem::isSymlinkSTD(userThemeDirSetting)) {
mThemeDirectory = userThemeDirSetting; mThemeDirectory = userThemeDirSetting.string();
} }
else { else {
LOG(LogWarning) << "GuiThemeDownloader: Requested user theme directory \"" LOG(LogWarning) << "GuiThemeDownloader: Requested user theme directory \""
<< userThemeDirSetting << userThemeDirSetting.string()
<< "\" does not exist or is not a directory, reverting to \"" << "\" does not exist or is not a directory, reverting to \""
<< defaultUserThemeDir << "\""; << defaultUserThemeDir.string() << "\"";
mThemeDirectory = defaultUserThemeDir; mThemeDirectory = defaultUserThemeDir.string();
} }
#endif // __ANDROID__
if (mThemeDirectory.back() != '/') if (mThemeDirectory.back() != '/')
mThemeDirectory.append("/"); mThemeDirectory.append("/");
@ -588,8 +593,8 @@ void GuiThemeDownloader::parseThemesList()
#if (LOCAL_TESTING_FILE) #if (LOCAL_TESTING_FILE)
LOG(LogWarning) << "GuiThemeDownloader: Using local \"themes.json\" testing file"; LOG(LogWarning) << "GuiThemeDownloader: Using local \"themes.json\" testing file";
const std::string themesFile {Utils::FileSystem::getHomePath() + const std::string themesFile {
"/.emulationstation/themes.json"}; Utils::FileSystem::getAppDataDirectory().append("themes.json").string()};
#else #else
const std::string themesFile {mThemeDirectory + "themes-list/themes.json"}; const std::string themesFile {mThemeDirectory + "themes-list/themes.json"};
#endif #endif

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// GuiThemeDownloader.h // GuiThemeDownloader.h
// //
// Theme downloader. // Theme downloader.

View file

@ -441,25 +441,21 @@ bool parseArguments(const std::vector<std::string>& arguments)
return true; return true;
} }
bool checkApplicationHomeDirectory() bool checkApplicationDataDirectory()
{ {
// Check that the application home directory exists, otherwise create it. // Check that the application data directory exists, otherwise create it.
std::string home {Utils::FileSystem::getHomePath()}; const std::filesystem::path applicationData {Utils::FileSystem::getAppDataDirectory()};
std::string applicationHome {home + "/.emulationstation"}; if (!Utils::FileSystem::existsSTD(applicationData)) {
if (!Utils::FileSystem::exists(applicationHome)) { #if defined(__ANDROID__)
#if defined(_WIN64)
std::cout << "First startup, creating application home directory \""
<< Utils::String::replace(applicationHome, "/", "\\") << "\"\n";
#elif defined(__ANDROID__)
__android_log_print(ANDROID_LOG_VERBOSE, ANDROID_APPLICATION_ID, __android_log_print(ANDROID_LOG_VERBOSE, ANDROID_APPLICATION_ID,
"First startup, creating application home directory \"%s\"", "First startup, creating application data directory \"%s\"",
applicationHome.c_str()); applicationData.string().c_str());
#else #else
std::cout << "First startup, creating application home directory \"" << applicationHome std::cout << "First startup, creating application data directory \""
<< "\"\n"; << applicationData.string() << "\"\n";
#endif #endif
Utils::FileSystem::createDirectory(applicationHome); Utils::FileSystem::createDirectory(applicationData.string());
if (!Utils::FileSystem::exists(applicationHome)) { if (!Utils::FileSystem::existsSTD(applicationData)) {
#if defined(__ANDROID__) #if defined(__ANDROID__)
__android_log_print(ANDROID_LOG_ERROR, ANDROID_APPLICATION_ID, __android_log_print(ANDROID_LOG_ERROR, ANDROID_APPLICATION_ID,
"Error: Couldn't create directory, permission problems?"); "Error: Couldn't create directory, permission problems?");
@ -535,6 +531,10 @@ int main(int argc, char* argv[])
std::locale::global(std::locale("C")); std::locale::global(std::locale("C"));
#if defined(__ANDROID__)
Utils::Platform::Android::setDataDirectories();
#endif
#if defined(__APPLE__) #if defined(__APPLE__)
// This is a workaround to disable the incredibly annoying save state functionality in // This is a workaround to disable the incredibly annoying save state functionality in
// macOS which forces a restore of the previous window state. The problem is that this // macOS which forces a restore of the previous window state. The problem is that this
@ -590,8 +590,8 @@ int main(int argc, char* argv[])
FreeImage_Initialise(); FreeImage_Initialise();
#endif #endif
// If ~/.emulationstation doesn't exist and cannot be created, bail. // If the application data directory doesn't exist and can't be created, then exit.
if (!checkApplicationHomeDirectory()) if (!checkApplicationDataDirectory())
return 1; return 1;
// Start the logger. // Start the logger.
@ -632,8 +632,8 @@ int main(int argc, char* argv[])
// Check if the configuration file exists, and if not, create it. // Check if the configuration file exists, and if not, create it.
// This should only happen on first application startup. // This should only happen on first application startup.
if (!Utils::FileSystem::exists(Utils::FileSystem::getHomePath() + if (!Utils::FileSystem::existsSTD(
"/.emulationstation/es_settings.xml")) { Utils::FileSystem::getAppDataDirectory().append("es_settings.xml"))) {
LOG(LogInfo) << "Settings file es_settings.xml does not exist, creating it..."; LOG(LogInfo) << "Settings file es_settings.xml does not exist, creating it...";
Settings::getInstance()->saveFile(); Settings::getInstance()->saveFile();
} }
@ -659,63 +659,60 @@ int main(int argc, char* argv[])
Settings::getInstance()->saveFile(); Settings::getInstance()->saveFile();
} }
// Create the gamelists directory in the application home folder. // Create the gamelists folder in the application data directory.
const std::string gamelistsDir {Utils::FileSystem::getHomePath() + const std::filesystem::path gamelistsDir {
"/.emulationstation/gamelists"}; Utils::FileSystem::getAppDataDirectory().append("gamelists")};
if (!Utils::FileSystem::exists(gamelistsDir)) { if (!Utils::FileSystem::existsSTD(gamelistsDir)) {
#if defined(_WIN64) LOG(LogInfo) << "Creating gamelists directory \"" << gamelistsDir.string() << "\"...";
LOG(LogInfo) << "Creating gamelists directory \"" Utils::FileSystem::createDirectory(gamelistsDir.string());
<< Utils::String::replace(gamelistsDir, "/", "\\") << "\"..."; if (!Utils::FileSystem::existsSTD(gamelistsDir)) {
#else
LOG(LogInfo) << "Creating gamelists directory \"" << gamelistsDir << "\"...";
#endif
Utils::FileSystem::createDirectory(gamelistsDir);
if (!Utils::FileSystem::exists(gamelistsDir)) {
LOG(LogWarning) << "Couldn't create directory, permission problems?\n"; LOG(LogWarning) << "Couldn't create directory, permission problems?\n";
} }
} }
// Create the themes directory in the application home directory (or elsewhere if the #if defined(__ANDROID__)
// UserThemeDirectory setting has been defined). const std::filesystem::path themeDir {
const std::string defaultUserThemeDir {Utils::FileSystem::getHomePath() + Utils::FileSystem::getAppDataDirectory().append("themes")};
"/.emulationstation/themes"}; if (!Utils::FileSystem::existsSTD(themeDir)) {
std::string userThemeDirSetting {Utils::FileSystem::expandHomePath( LOG(LogInfo) << "Creating themes directory \"" << themeDir.string() << "\"...";
Settings::getInstance()->getString("UserThemeDirectory"))};
#if defined(_WIN64)
userThemeDirSetting = Utils::String::replace(userThemeDirSetting, "\\", "/");
#endif
std::string userThemeDirectory;
if (userThemeDirSetting == "") Utils::FileSystem::createDirectory(themeDir.string());
if (!Utils::FileSystem::existsSTD(themeDir)) {
LOG(LogWarning) << "Couldn't create directory, permission problems?";
}
}
#else
// Create the themes folder in the application data directory (or elsewhere if the
// UserThemeDirectory setting has been defined).
const std::filesystem::path defaultUserThemeDir {
Utils::FileSystem::getAppDataDirectory().append("themes")};
std::filesystem::path userThemeDirSetting {Utils::FileSystem::expandHomePath(
Settings::getInstance()->getString("UserThemeDirectory"))};
std::filesystem::path userThemeDirectory;
if (userThemeDirSetting.empty())
userThemeDirectory = defaultUserThemeDir; userThemeDirectory = defaultUserThemeDir;
else else
userThemeDirectory = userThemeDirSetting; userThemeDirectory = userThemeDirSetting;
if (!Utils::FileSystem::exists(userThemeDirectory)) { if (!Utils::FileSystem::existsSTD(userThemeDirectory)) {
#if defined(_WIN64) LOG(LogInfo) << "Creating themes directory \"" << userThemeDirectory.string() << "\"...";
LOG(LogInfo) << "Creating user theme directory \""
<< Utils::String::replace(userThemeDirectory, "/", "\\") << "\"..."; Utils::FileSystem::createDirectory(userThemeDirectory.string());
#else if (!Utils::FileSystem::existsSTD(userThemeDirectory)) {
LOG(LogInfo) << "Creating themes directory \"" << userThemeDirectory << "\"...";
#endif
Utils::FileSystem::createDirectory(userThemeDirectory);
if (!Utils::FileSystem::exists(userThemeDirectory)) {
LOG(LogWarning) << "Couldn't create directory, permission problems?"; LOG(LogWarning) << "Couldn't create directory, permission problems?";
} }
} }
// Create the scripts directory in the application home folder. This is only required
// for custom event scripts so it's also created as a convenience.
const std::string scriptsDir {Utils::FileSystem::getHomePath() + "/.emulationstation/scripts"};
if (!Utils::FileSystem::exists(scriptsDir)) {
#if defined(_WIN64)
LOG(LogInfo) << "Creating scripts directory \""
<< Utils::String::replace(scriptsDir, "/", "\\") << "\"...";
#else
LOG(LogInfo) << "Creating scripts directory \"" << scriptsDir << "\"...";
#endif #endif
Utils::FileSystem::createDirectory(scriptsDir);
if (!Utils::FileSystem::exists(scriptsDir)) { // Create the scripts folder in the application data directory. This is only required
// for custom event scripts so it's also created as a convenience.
const std::filesystem::path scriptsDir {
Utils::FileSystem::getAppDataDirectory().append("scripts")};
if (!Utils::FileSystem::existsSTD(scriptsDir)) {
LOG(LogInfo) << "Creating scripts directory \"" << scriptsDir.string() << "\"...";
Utils::FileSystem::createDirectory(scriptsDir.string());
if (!Utils::FileSystem::existsSTD(scriptsDir)) {
LOG(LogWarning) << "Couldn't create directory, permission problems?\n"; LOG(LogWarning) << "Couldn't create directory, permission problems?\n";
} }
} }
@ -740,7 +737,6 @@ int main(int argc, char* argv[])
LOG(LogDebug) << "Android storage state: " << SDL_AndroidGetExternalStorageState(); LOG(LogDebug) << "Android storage state: " << SDL_AndroidGetExternalStorageState();
LOG(LogDebug) << "Android internal path: " << SDL_AndroidGetInternalStoragePath(); LOG(LogDebug) << "Android internal path: " << SDL_AndroidGetInternalStoragePath();
LOG(LogDebug) << "Android external path: " << SDL_AndroidGetExternalStoragePath(); LOG(LogDebug) << "Android external path: " << SDL_AndroidGetExternalStoragePath();
Utils::Platform::Android::setPrivateDataDirectory();
{ {
std::string buildIdentifier {PROGRAM_VERSION_STRING}; std::string buildIdentifier {PROGRAM_VERSION_STRING};
buildIdentifier.append(" (r") buildIdentifier.append(" (r")
@ -801,14 +797,7 @@ int main(int argc, char* argv[])
#if defined(__ANDROID__) #if defined(__ANDROID__)
Utils::Platform::Android::requestStoragePermission(); Utils::Platform::Android::requestStoragePermission();
Utils::Platform::Android::setROMDirectory();
const std::string storageDir {"/sdcard/ES-DE"};
if (!Utils::FileSystem::exists(storageDir)) {
LOG(LogInfo) << "Creating data directory \"" << storageDir << "\"...";
if (!Utils::FileSystem::createDirectory(storageDir)) {
LOG(LogError) << "Couldn't create directory, permission problems?";
}
}
#endif #endif
MameNames::getInstance(); MameNames::getInstance();

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// GamesDBJSONScraper.cpp // GamesDBJSONScraper.cpp
// //
// Functions specifically for scraping from thegamesdb.net // Functions specifically for scraping from thegamesdb.net

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// GamesDBJSONScraper.h // GamesDBJSONScraper.h
// //
// Functions specifically for scraping from thegamesdb.net // Functions specifically for scraping from thegamesdb.net

View file

@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// GamesDBJSONScraperResources.cpp // GamesDBJSONScraperResources.cpp
// //
// Functions specifically for scraping from thegamesdb.net // Functions specifically for scraping from thegamesdb.net
// Called from GamesDBJSONScraper. // Called from GamesDBJSONScraper.
// //
// Downloads these resource files to ~/.emulationstation/scrapers: // Downloads these resource files to the scrapers folder in the application data directory:
// gamesdb_developers.json // gamesdb_developers.json
// gamesdb_genres.json // gamesdb_genres.json
// gamesdb_publishers.json // gamesdb_publishers.json
@ -64,8 +64,7 @@ namespace
std::string getScrapersResouceDir() std::string getScrapersResouceDir()
{ {
return Utils::FileSystem::getGenericPath(Utils::FileSystem::getHomePath() + return Utils::FileSystem::getAppDataDirectory().append(SCRAPER_RESOURCES_DIR).string();
"/.emulationstation/" + SCRAPER_RESOURCES_DIR);
} }
std::string TheGamesDBJSONRequestResources::getApiKey() const { return GamesDBAPIKey; } std::string TheGamesDBJSONRequestResources::getApiKey() const { return GamesDBAPIKey; }

View file

@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// GamesDBJSONScraperResources.h // GamesDBJSONScraperResources.h
// //
// Functions specifically for scraping from thegamesdb.net // Functions specifically for scraping from thegamesdb.net
// Called from GamesDBJSONScraper. // Called from GamesDBJSONScraper.
// //
// Downloads these resource files to ~/.emulationstation/scrapers: // Downloads these resource files to the scrapers folder in the application data directory:
// gamesdb_developers.json // gamesdb_developers.json
// gamesdb_genres.json // gamesdb_genres.json
// gamesdb_publishers.json // gamesdb_publishers.json

View file

@ -212,8 +212,8 @@ private:
bool* mSavedNewMediaPtr; bool* mSavedNewMediaPtr;
}; };
// Downloads to the home directory, using this subdirectory structure: // Downloads media using this subdirectory structure:
// ".emulationstation/downloaded_media/[system_name]/[media_type]/[game_name].[file_extension]". // <application data>/downloaded_media/<system_name>/<media_type>/<game_name>.<file_extension>
// The subdirectories are automatically created if they do not exist. // The subdirectories are automatically created if they do not exist.
std::string getSaveAsPath(const ScraperSearchParams& params, std::string getSaveAsPath(const ScraperSearchParams& params,
const std::string& filetypeSubdirectory, const std::string& filetypeSubdirectory,

View file

@ -1,6 +1,6 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# #
# EmulationStation Desktop Edition # ES-DE
# CMakeLists.txt (es-core) # CMakeLists.txt (es-core)
# #
# CMake configuration for es-core # CMake configuration for es-core

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// InputManager.cpp // InputManager.cpp
// //
// Low-level input handling. // Low-level input handling.
@ -86,14 +86,14 @@ void InputManager::init()
// the bundled mapping is incorrect, or the SDL version is a bit older, it makes sense to be // the bundled mapping is incorrect, or the SDL version is a bit older, it makes sense to be
// able to customize this. If a controller GUID is present in the mappings file that is // able to customize this. If a controller GUID is present in the mappings file that is
// already present inside SDL, the custom mapping will overwrite the bundled one. // already present inside SDL, the custom mapping will overwrite the bundled one.
std::string mappingsFile {Utils::FileSystem::getHomePath() + "/.emulationstation/" + std::filesystem::path mappingsFile {
"es_controller_mappings.cfg"}; Utils::FileSystem::getAppDataDirectory().append("es_controller_mappings.cfg")};
if (!Utils::FileSystem::exists(mappingsFile)) if (!Utils::FileSystem::existsSTD(mappingsFile))
mappingsFile = ResourceManager::getInstance().getResourcePath( mappingsFile = ResourceManager::getInstance().getResourcePath(
":/controllers/es_controller_mappings.cfg"); ":/controllers/es_controller_mappings.cfg");
int controllerMappings {SDL_GameControllerAddMappingsFromFile(mappingsFile.c_str())}; int controllerMappings {SDL_GameControllerAddMappingsFromFile(mappingsFile.string().c_str())};
if (controllerMappings != -1 && controllerMappings != 0) { if (controllerMappings != -1 && controllerMappings != 0) {
LOG(LogInfo) << "Loaded " << controllerMappings << " controller " LOG(LogInfo) << "Loaded " << controllerMappings << " controller "
@ -255,16 +255,12 @@ void InputManager::doOnFinish()
std::string InputManager::getConfigPath() std::string InputManager::getConfigPath()
{ {
std::string path {Utils::FileSystem::getHomePath()}; return Utils::FileSystem::getAppDataDirectory().append("es_input.xml").string();
path.append("/.emulationstation/es_input.xml");
return path;
} }
std::string InputManager::getTemporaryConfigPath() std::string InputManager::getTemporaryConfigPath()
{ {
std::string path {Utils::FileSystem::getHomePath()}; return Utils::FileSystem::getAppDataDirectory().append("es_temporaryinput.xml").string();
path.append("/.emulationstation/es_temporaryinput.xml");
return path;
} }
int InputManager::getNumConfiguredDevices() int InputManager::getNumConfiguredDevices()

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// InputManager.h // InputManager.h
// //
// Low-level input handling. // Low-level input handling.

View file

@ -1,12 +1,11 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// MameNames.cpp // MameNames.cpp
// //
// Provides expanded game names based on short MAME name arguments. Also contains // Provides expanded game names based on short MAME name arguments. Also contains
// functions to check whether a passed argument is a MAME BIOS or a MAME device. // functions to check whether a passed argument is a MAME BIOS or a MAME device.
// The data sources are stored in the .emulationstation/resources directory // The data sources are stored as the files mamebioses.xml, mamedevices.xml and mamenames.xml.
// as the files mamebioses.xml, mamedevices.xml and mamenames.xml.
// //
#include "MameNames.h" #include "MameNames.h"

View file

@ -1,12 +1,11 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// MameNames.h // MameNames.h
// //
// Provides expanded game names based on short MAME name arguments. Also contains // Provides expanded game names based on short MAME name arguments. Also contains
// functions to check whether a passed argument is a MAME BIOS or a MAME device. // functions to check whether a passed argument is a MAME BIOS or a MAME device.
// The data sources are stored in the .emulationstation/resources directory // The data sources are stored as the files mamebioses.xml, mamedevices.xml and mamenames.xml.
// as the files mamebioses.xml, mamedevices.xml and mamenames.xml.
// //
#ifndef ES_CORE_MAMENAMES_H #ifndef ES_CORE_MAMENAMES_H

View file

@ -1,15 +1,15 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// Scripting.cpp // Scripting.cpp
// //
// Executes custom scripts for various events. // Executes custom scripts for various events.
// By calling fireEvent() the scripts inside the directory corresponding to the // By calling fireEvent() the scripts inside the directory corresponding to the
// argument "eventName" will be executed with arg1, arg2, arg3 and arg4 as arguments. // argument "eventName" will be executed with arg1, arg2, arg3 and arg4 as arguments.
// //
// The scripts are searched for in ~/.emulationstation/scripts/<eventName> // The scripts are searched for in <application data>/scripts/<eventName>
// For example, if the event is called "game-start", all scripts inside the directory // For example, if the event is called "game-start", all scripts inside the directory
// ~/.emulationstation/scripts/game-start/ will be executed. // <application data>/scripts/game-start/ will be executed.
// //
#include "Scripting.h" #include "Scripting.h"
@ -37,12 +37,12 @@ namespace Scripting
<< "\" \"" << arg3 << "\" \"" << arg4 << "\""; << "\" \"" << arg3 << "\" \"" << arg4 << "\"";
std::list<std::string> scriptDirList; std::list<std::string> scriptDirList;
std::string scriptDir; std::filesystem::path scriptDir;
// Check in homepath. // Check in application data directory.
scriptDir = Utils::FileSystem::getHomePath() + "/.emulationstation/scripts/" + eventName; scriptDir = Utils::FileSystem::getAppDataDirectory().append("scripts").append(eventName);
if (Utils::FileSystem::exists(scriptDir)) if (Utils::FileSystem::existsSTD(scriptDir))
scriptDirList.push_back(scriptDir); scriptDirList.push_back(scriptDir.string());
for (auto dirIt = scriptDirList.cbegin(); dirIt != scriptDirList.cend(); ++dirIt) { for (auto dirIt = scriptDirList.cbegin(); dirIt != scriptDirList.cend(); ++dirIt) {
std::list<std::string> scripts {Utils::FileSystem::getDirContent(*dirIt)}; std::list<std::string> scripts {Utils::FileSystem::getDirContent(*dirIt)};

View file

@ -1,15 +1,15 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// Scripting.h // Scripting.h
// //
// Executes custom scripts for various events. // Executes custom scripts for various events.
// By calling fireEvent() the scripts inside the directory corresponding to the // By calling fireEvent() the scripts inside the directory corresponding to the
// argument "eventName" will be executed with arg1, arg2, arg3 and arg4 as arguments. // argument "eventName" will be executed with arg1, arg2, arg3 and arg4 as arguments.
// //
// The scripts are searched for in ~/.emulationstation/scripts/<eventName> // The scripts are searched for in <application data>/scripts/<eventName>
// For example, if the event is called "game-start", all scripts inside the directory // For example, if the event is called "game-start", all scripts inside the directory
// ~/.emulationstation/scripts/game-start/ will be executed. // <application data>/scripts/game-start/ will be executed.
// //
#ifndef ES_CORE_SCRIPTING_H #ifndef ES_CORE_SCRIPTING_H

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// Settings.cpp // Settings.cpp
// //
// Functions to read from and write to the configuration file es_settings.xml. // Functions to read from and write to the configuration file es_settings.xml.
@ -326,7 +326,9 @@ void Settings::setDefaults()
mBoolMap["DebugSkipMissingThemeFilesCustomCollections"] = {true, true}; mBoolMap["DebugSkipMissingThemeFilesCustomCollections"] = {true, true};
mBoolMap["LegacyGamelistFileLocation"] = {false, false}; mBoolMap["LegacyGamelistFileLocation"] = {false, false};
mStringMap["OpenGLVersion"] = {"", ""}; mStringMap["OpenGLVersion"] = {"", ""};
#if !defined(__ANDROID__)
mStringMap["ROMDirectory"] = {"", ""}; mStringMap["ROMDirectory"] = {"", ""};
#endif
mStringMap["UIMode_passkey"] = {"uuddlrlrba", "uuddlrlrba"}; mStringMap["UIMode_passkey"] = {"uuddlrlrba", "uuddlrlrba"};
mStringMap["UserThemeDirectory"] = {"", ""}; mStringMap["UserThemeDirectory"] = {"", ""};
mIntMap["LottieMaxFileCache"] = {150, 150}; mIntMap["LottieMaxFileCache"] = {150, 150};
@ -364,7 +366,7 @@ void Settings::saveFile()
{ {
LOG(LogDebug) << "Settings::saveFile(): Saving settings to es_settings.xml"; LOG(LogDebug) << "Settings::saveFile(): Saving settings to es_settings.xml";
const std::filesystem::path path { const std::filesystem::path path {
Utils::FileSystem::getESDataDirectory().append("es_settings.xml")}; Utils::FileSystem::getAppDataDirectory().append("es_settings.xml")};
pugi::xml_document doc; pugi::xml_document doc;
@ -395,7 +397,7 @@ void Settings::saveFile()
void Settings::loadFile() void Settings::loadFile()
{ {
std::filesystem::path configFile { std::filesystem::path configFile {
Utils::FileSystem::getESDataDirectory().append("es_settings.xml")}; Utils::FileSystem::getAppDataDirectory().append("es_settings.xml")};
if (!Utils::FileSystem::existsSTD(configFile)) if (!Utils::FileSystem::existsSTD(configFile))
return; return;

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// Settings.h // Settings.h
// //
// Functions to read from and write to the configuration file es_settings.xml. // Functions to read from and write to the configuration file es_settings.xml.

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// ThemeData.cpp // ThemeData.cpp
// //
// Finds available themes on the file system and loads and parses these. // Finds available themes on the file system and loads and parses these.
@ -667,8 +667,12 @@ void ThemeData::populateThemes()
// Check for themes first under the user theme directory (which is in the ES-DE home directory // Check for themes first under the user theme directory (which is in the ES-DE home directory
// by default), then under the data installation directory (Unix only) and last under the ES-DE // by default), then under the data installation directory (Unix only) and last under the ES-DE
// binary directory. // binary directory.
#if defined(__ANDROID__)
const std::filesystem::path userThemeDirectory {
Utils::FileSystem::getInternalAppDataDirectory().append("themes")};
#else
const std::filesystem::path defaultUserThemeDir { const std::filesystem::path defaultUserThemeDir {
Utils::FileSystem::getESDataDirectory().append("themes")}; Utils::FileSystem::getAppDataDirectory().append("themes")};
const std::filesystem::path userThemeDirSetting {Utils::FileSystem::expandHomePath( const std::filesystem::path userThemeDirSetting {Utils::FileSystem::expandHomePath(
Settings::getInstance()->getString("UserThemeDirectory"))}; Settings::getInstance()->getString("UserThemeDirectory"))};
std::filesystem::path userThemeDirectory; std::filesystem::path userThemeDirectory;
@ -687,10 +691,12 @@ void ThemeData::populateThemes()
<< defaultUserThemeDir.string() << "\""; << defaultUserThemeDir.string() << "\"";
userThemeDirectory = defaultUserThemeDir; userThemeDirectory = defaultUserThemeDir;
} }
#endif
#if defined(__ANDROID__) #if defined(__ANDROID__)
const std::vector<std::filesystem::path> themePaths { const std::vector<std::filesystem::path> themePaths {
Utils::FileSystem::getProgramDataPath().append("themes"), userThemeDirectory}; Utils::FileSystem::getProgramDataPath().append("themes"), userThemeDirectory,
Utils::FileSystem::getAppDataDirectory().append("themes")};
#elif defined(__APPLE__) #elif defined(__APPLE__)
const std::vector<std::filesystem::path> themePaths { const std::vector<std::filesystem::path> themePaths {
Utils::FileSystem::getExePathSTD().append("themes"), Utils::FileSystem::getExePathSTD().append("themes"),

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// ThemeData.h // ThemeData.h
// //
// Finds available themes on the file system and loads and parses these. // Finds available themes on the file system and loads and parses these.

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// ResourceManager.cpp // ResourceManager.cpp
// //
// Handles the application resources (fonts, graphics, sounds etc.). // Handles the application resources (fonts, graphics, sounds etc.).
@ -28,8 +28,8 @@ std::string ResourceManager::getResourcePath(const std::string& path, bool termi
if ((path[0] == ':') && (path[1] == '/')) { if ((path[0] == ':') && (path[1] == '/')) {
// Check under the home directory. // Check under the home directory.
std::string testHome {Utils::FileSystem::getHomePath() + "/.emulationstation/resources/" + std::string testHome {
&path[2]}; Utils::FileSystem::getAppDataDirectory().append("resources").string() + "/" + &path[2]};
if (Utils::FileSystem::exists(testHome)) if (Utils::FileSystem::exists(testHome))
return testHome; return testHome;

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// FileSystemUtil.cpp // FileSystemUtil.cpp
// //
// Low-level filesystem functions. // Low-level filesystem functions.
@ -198,6 +198,11 @@ namespace Utils
if (homePath.length()) if (homePath.length())
return homePath; return homePath;
#if defined(__ANDROID__)
homePath = AndroidVariables::sAppDataDirectory;
return homePath;
#endif
#if defined(_WIN64) #if defined(_WIN64)
// On Windows we need to check HOMEDRIVE and HOMEPATH. // On Windows we need to check HOMEDRIVE and HOMEPATH.
if (!homePath.length()) { if (!homePath.length()) {
@ -241,6 +246,11 @@ namespace Utils
if (!homePathSTD.empty()) if (!homePathSTD.empty())
return homePathSTD; return homePathSTD;
#if defined(__ANDROID__)
homePathSTD =
std::filesystem::path {getGenericPath(AndroidVariables::sAppDataDirectory)};
return homePathSTD;
#endif
#if defined(_WIN64) #if defined(_WIN64)
// On Windows we need to check HOMEDRIVE and HOMEPATH. // On Windows we need to check HOMEDRIVE and HOMEPATH.
std::wstring envHomeDrive; std::wstring envHomeDrive;
@ -261,7 +271,6 @@ namespace Utils
} }
#else #else
std::string envHome; std::string envHome;
if (getenv("HOME") != nullptr) if (getenv("HOME") != nullptr)
envHome = getenv("HOME"); envHome = getenv("HOME");
@ -304,15 +313,24 @@ namespace Utils
return ""; return "";
} }
std::filesystem::path getESDataDirectory() std::filesystem::path getAppDataDirectory()
{ {
#if defined(__ANDROID__) #if defined(__ANDROID__)
return getHomePathSTD().append(".emulationstation"); return getHomePathSTD();
#else #else
return getHomePathSTD().append(".emulationstation"); return getHomePathSTD().append(".emulationstation");
#endif #endif
} }
std::filesystem::path getInternalAppDataDirectory()
{
#if defined(__ANDROID__)
return AndroidVariables::sExternalDataDirectory;
#else
return std::filesystem::path {};
#endif
}
std::string getPathToBinary(const std::string& executable) std::string getPathToBinary(const std::string& executable)
{ {
#if defined(_WIN64) #if defined(_WIN64)
@ -332,7 +350,7 @@ namespace Utils
// Using a temporary file is the only viable solution I've found to communicate // Using a temporary file is the only viable solution I've found to communicate
// between the sandbox and the outside world. // between the sandbox and the outside world.
const std::string& tempFile {Utils::FileSystem::getHomePath() + "/.emulationstation/" + const std::string tempFile {Utils::FileSystem::getAppDataDirectory().string() +
".flatpak_emulator_binary_path.tmp"}; ".flatpak_emulator_binary_path.tmp"};
std::string emulatorPath; std::string emulatorPath;
@ -440,7 +458,7 @@ namespace Utils
std::filesystem::path getProgramDataPath() std::filesystem::path getProgramDataPath()
{ {
#if defined(__ANDROID__) #if defined(__ANDROID__)
return AndroidVariables::sPrivateDataDirectory; return AndroidVariables::sInternalDataDirectory;
#elif defined(__unix__) #elif defined(__unix__)
return std::filesystem::path {installPrefix}.append("share").append("emulationstation"); return std::filesystem::path {installPrefix}.append("share").append("emulationstation");
#else #else

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // ES-DE
// FileSystemUtil.h // FileSystemUtil.h
// //
// Low-level filesystem functions. // Low-level filesystem functions.
@ -30,7 +30,8 @@ namespace Utils
std::string getHomePath(); std::string getHomePath();
std::filesystem::path getHomePathSTD(); std::filesystem::path getHomePathSTD();
std::string getSystemHomeDirectory(); std::string getSystemHomeDirectory();
std::filesystem::path getESDataDirectory(); std::filesystem::path getAppDataDirectory();
std::filesystem::path getInternalAppDataDirectory();
std::string getPathToBinary(const std::string& executable); std::string getPathToBinary(const std::string& executable);
void setExePath(const std::string& path); void setExePath(const std::string& path);
std::string getExePath(); std::string getExePath();