Commit f9c671cf authored by James's avatar James
Browse files

Implement support for LibRetro save paths (closes #3)

parent 61a1a50f
......@@ -69,6 +69,7 @@ void LibRetro::OnConfigureEnvironment() {
{"citra_limit_framerate", "Enable frame limiter; enabled|disabled"},
{"citra_audio_stretching", "Enable audio stretching; enabled|disabled"},
{"citra_use_virtual_sd", "Enable virtual SD card; enabled|disabled"},
{"citra_use_libretro_save_path", "Savegame location; Citra Default|LibRetro Default"},
{"citra_is_new_3ds", "3DS system model; Old 3DS|New 3DS"},
{"citra_region_value",
"3DS system region; Auto|Japan|USA|Europe|Australia|China|Korea|Taiwan"},
......@@ -251,6 +252,31 @@ void UpdateSettings(bool init) {
Settings::values.analogs[1] = "";
}
// Configure the file storage location
auto use_libretro_saves = LibRetro::FetchVariable("citra_use_libretro_save_path", "Citra Default") ==
"LibRetro Default";
if (use_libretro_saves) {
auto target_dir = LibRetro::GetSaveDir();
if (target_dir.empty()) {
LOG_INFO(Frontend, "No save dir provided; trying system dir...");
target_dir = LibRetro::GetSystemDir();
}
if (!target_dir.empty()) {
target_dir += "/Citra";
// Ensure that this new dir exists
if (!FileUtil::CreateDir(target_dir)) {
LOG_ERROR(Frontend, "Failed to create \"%s\". Using Citra's default paths.", target_dir.c_str());
} else {
FileUtil::GetUserPath(D_ROOT_IDX, target_dir);
const auto &target_dir_result = FileUtil::GetUserPath(D_USER_IDX, target_dir);
LOG_INFO(Frontend, "User dir set to \"%s\".", target_dir_result.c_str());
}
}
}
// Update the framebuffer sizing, but only if there is a oGL context.
emu_window->Prepare(!init);
......
......@@ -77,7 +77,7 @@ bool DisplayMessage(const char* sg) {
}
std::string FetchVariable(std::string key, std::string def) {
struct retro_variable var = {0};
struct retro_variable var = {nullptr};
var.key = key.c_str();
if (!environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value == nullptr) {
// Fetching variable failed.
......@@ -87,6 +87,26 @@ std::string FetchVariable(std::string key, std::string def) {
return std::string(var.value);
}
std::string GetSaveDir() {
char* var = nullptr;
if (!environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &var) || var == nullptr) {
// Fetching variable failed.
LOG_ERROR(Frontend, "No save directory provided by LibRetro.");
return std::string();
}
return std::string(var);
}
std::string GetSystemDir() {
char* var = nullptr;
if (!environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &var) || var == nullptr) {
// Fetching variable failed.
LOG_ERROR(Frontend, "No system directory provided by LibRetro.");
return std::string();
}
return std::string(var);
}
int16_t CheckInput(unsigned port, unsigned device, unsigned index, unsigned id) {
return input_state_cb(port, device, index, id);
}
......
......@@ -27,6 +27,12 @@ bool SetVariables(const retro_variable vars[]);
bool SetHWSharedContext(void);
/// Returns the LibRetro save directory, or a empty string if one doesn't exist.
std::string GetSaveDir();
/// Returns the LibRetro system directory, or a empty string if one doesn't exist.
std::string GetSystemDir();
/// Fetches a variable by key name.
std::string FetchVariable(std::string key, std::string def);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment