mirror of
https://github.com/Rosalie241/RMG.git
synced 2026-07-31 02:38:27 +02:00
CoreGetSharedDataDirectory() is called in CoreInit() before mupen64plus has started, so the settings function will return an empty string, which is not expected.
202 lines
4.7 KiB
C++
202 lines
4.7 KiB
C++
/*
|
|
* Rosalie's Mupen GUI - https://github.com/Rosalie241/RMG
|
|
* Copyright (C) 2020 Rosalie Wanders <rosalie@mailbox.org>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 3.
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "Directories.hpp"
|
|
#include "Config.hpp"
|
|
#include "Error.hpp"
|
|
#include "Core.hpp"
|
|
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
#include <filesystem>
|
|
|
|
//
|
|
// Local Functions
|
|
//
|
|
|
|
static std::string get_var_directory(std::string var, std::string append, std::string fallbackVar, std::string fallbackAppend)
|
|
{
|
|
std::string directory;
|
|
|
|
const char* env = std::getenv(var.c_str());
|
|
if (env == nullptr)
|
|
{
|
|
env = std::getenv(fallbackVar.c_str());
|
|
if (env == nullptr)
|
|
{
|
|
std::cerr << "get_var_directory: fallbackVar: $" << fallbackVar << " cannot be nullptr!" << std::endl;
|
|
std::terminate();
|
|
}
|
|
directory = env;
|
|
directory += fallbackAppend;
|
|
}
|
|
else
|
|
{
|
|
directory = env;
|
|
directory += append;
|
|
}
|
|
|
|
return directory;
|
|
}
|
|
|
|
//
|
|
// Exported Functions
|
|
//
|
|
|
|
bool CoreCreateDirectories(void)
|
|
{
|
|
std::string error;
|
|
|
|
std::string directories[] =
|
|
{
|
|
#ifdef PORTABLE_INSTALL
|
|
CoreGetCoreDirectory(),
|
|
CoreGetPluginDirectory(),
|
|
CoreGetSharedDataDirectory(),
|
|
#endif // PORTABLE_INSTALL
|
|
CoreGetUserConfigDirectory(),
|
|
CoreGetUserDataDirectory(),
|
|
CoreGetUserCacheDirectory(),
|
|
CoreGetSaveDirectory(),
|
|
CoreGetSaveStateDirectory()
|
|
};
|
|
|
|
for (const auto& dir : directories)
|
|
{
|
|
try
|
|
{
|
|
std::filesystem::create_directories(dir);
|
|
}
|
|
catch (...)
|
|
{
|
|
error = "CoreCreateDirectories Failed: cannot create the '";
|
|
error += dir;
|
|
error += "' directory!";
|
|
CoreSetError(error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
std::string CoreGetCoreDirectory(void)
|
|
{
|
|
std::string directory;
|
|
#ifdef PORTABLE_INSTALL
|
|
directory = "Core";
|
|
#else // Not Portable
|
|
directory = CORE_INSTAlL_PREFIX;
|
|
directory += "/lib/RMG/Core";
|
|
#endif // PORTABLE_INSTALL
|
|
return directory;
|
|
}
|
|
|
|
std::string CoreGetPluginDirectory(void)
|
|
{
|
|
std::string directory;
|
|
#ifdef PORTABLE_INSTALL
|
|
directory = "Plugin";
|
|
#else // Not Portable
|
|
directory = CORE_INSTAlL_PREFIX;
|
|
directory += "/lib/RMG/Plugin";
|
|
#endif // PORTABLE_INSTALL
|
|
return directory;
|
|
}
|
|
|
|
std::string CoreGetUserConfigDirectory(void)
|
|
{
|
|
std::string directory;
|
|
#ifdef PORTABLE_INSTALL
|
|
directory = "Config";
|
|
#else // Not Portable
|
|
directory = get_var_directory("XDG_CONFIG_HOME", "/RMG", "HOME", "/.config/RMG");
|
|
#endif // PORTABLE_INSTALL
|
|
return directory;
|
|
}
|
|
|
|
std::string CoreGetDefaultUserDataDirectory(void)
|
|
{
|
|
std::string directory;
|
|
#ifdef PORTABLE_INSTALL
|
|
directory = "Data";
|
|
#else // Not Portable
|
|
directory = get_var_directory("XDG_DATA_HOME", "/RMG", "HOME", "/.local/share/RMG");
|
|
#endif // PORTABLE_INSTALL
|
|
return directory;
|
|
}
|
|
|
|
std::string CoreGetDefaultUserCacheDirectory(void)
|
|
{
|
|
std::string directory;
|
|
#ifdef PORTABLE_INSTALL
|
|
directory = "Cache";
|
|
#else // Not Portable
|
|
directory = get_var_directory("XDG_CACHE_HOME", "/RMG", "HOME", "/.cache/RMG");
|
|
#endif // PORTABLE_INSTALL
|
|
return directory;
|
|
}
|
|
|
|
std::string CoreGetDefaultSaveDirectory(void)
|
|
{
|
|
std::string directory;
|
|
#ifdef PORTABLE_INSTALL
|
|
directory = "Save/Game";
|
|
#else
|
|
directory = CoreGetUserDataDirectory();
|
|
directory += "/Save/Game";
|
|
#endif // PORTABLE_INSTALL
|
|
return directory;
|
|
}
|
|
|
|
std::string CoreGetDefaultSaveStateDirectory(void)
|
|
{
|
|
std::string directory;
|
|
#ifdef PORTABLE_INSTALL
|
|
directory = "Save/State";
|
|
#else
|
|
directory = CoreGetUserDataDirectory();
|
|
directory += "/Save/State";
|
|
#endif // PORTABLE_INSTALL
|
|
return directory;
|
|
}
|
|
|
|
std::string CoreGetUserDataDirectory(void)
|
|
{
|
|
return CoreSettingsGetStringValue(SettingsID::Core_UserDataDirOverride);
|
|
}
|
|
|
|
std::string CoreGetUserCacheDirectory(void)
|
|
{
|
|
return CoreSettingsGetStringValue(SettingsID::Core_UserCacheDirOverride);
|
|
}
|
|
|
|
std::string CoreGetSharedDataDirectory(void)
|
|
{
|
|
std::string directory;
|
|
#ifdef PORTABLE_INSTALL
|
|
directory = "Data";
|
|
#else // Not Portable
|
|
directory = CORE_INSTAlL_PREFIX;
|
|
directory += "/share/RMG";
|
|
#endif // PORTABLE_INSTALL
|
|
return directory;
|
|
}
|
|
|
|
std::string CoreGetSaveDirectory(void)
|
|
{
|
|
return CoreSettingsGetStringValue(SettingsID::Core_SaveSRAMPath);
|
|
}
|
|
|
|
std::string CoreGetSaveStateDirectory(void)
|
|
{
|
|
return CoreSettingsGetStringValue(SettingsID::Core_SaveStatePath);
|
|
}
|
|
|