RetroArch/paths.c

761 lines
22 KiB
C
Raw Normal View History

2016-09-17 10:10:46 +00:00
/* RetroArch - A frontend for libretro.
2017-03-22 02:09:18 +00:00
* Copyright (C) 2011-2017 - Daniel De Matteis
2016-09-17 10:10:46 +00:00
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
2016-09-17 10:35:29 +00:00
#include <retro_miscellaneous.h>
2016-09-17 10:10:46 +00:00
#include <compat/strl.h>
#include <file/file_path.h>
2016-09-17 10:19:17 +00:00
#include <lists/string_list.h>
2016-09-17 10:16:11 +00:00
#include <string/stdstring.h>
2016-09-17 10:19:17 +00:00
#include <retro_assert.h>
2016-09-17 10:16:11 +00:00
#include <retro_stat.h>
2016-09-17 10:10:46 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2016-09-29 19:07:10 +00:00
#ifdef HAVE_NETWORKING
2016-09-19 01:03:31 +00:00
#include "network/netplay/netplay.h"
#endif
2016-09-17 12:57:53 +00:00
#include "dirs.h"
2016-09-17 10:10:46 +00:00
#include "paths.h"
2016-09-17 10:16:11 +00:00
#include "configuration.h"
2016-09-17 10:22:51 +00:00
#include "command.h"
2016-09-17 10:16:11 +00:00
#include "content.h"
2016-09-17 10:22:51 +00:00
#include "dynamic.h"
2016-09-17 10:35:29 +00:00
#include "movie.h"
2016-09-17 10:16:11 +00:00
#include "file_path_special.h"
#include "core.h"
#include "msg_hash.h"
2016-09-17 10:19:17 +00:00
#include "retroarch.h"
2016-09-17 10:16:11 +00:00
#include "verbosity.h"
#include "tasks/tasks_internal.h"
2016-09-17 10:16:11 +00:00
#define MENU_VALUE_NO_CORE 0x7d5472cbU
2016-09-25 13:49:09 +00:00
static struct string_list *subsystem_fullpaths = NULL;
2016-10-01 07:06:55 +00:00
static char subsystem_path[PATH_MAX_LENGTH] = {0};
2016-09-25 02:56:19 +00:00
static char path_default_shader_preset[PATH_MAX_LENGTH] = {0};
static char path_main_basename[8192] = {0};
2016-09-23 01:39:29 +00:00
static char path_content[PATH_MAX_LENGTH] = {0};
2016-09-17 10:35:29 +00:00
static char path_libretro[PATH_MAX_LENGTH] = {0};
static char path_config_file[PATH_MAX_LENGTH] = {0};
2016-09-17 12:04:19 +00:00
static char path_config_append_file[PATH_MAX_LENGTH] = {0};
2016-09-17 11:57:38 +00:00
static char path_core_options_file[PATH_MAX_LENGTH] = {0};
2016-09-17 10:16:11 +00:00
void path_set_redirect(void)
{
2016-10-16 00:00:59 +00:00
char new_savefile_dir[PATH_MAX_LENGTH];
char new_savestate_dir[PATH_MAX_LENGTH];
uint32_t library_name_hash = 0;
bool check_library_name_hash = false;
global_t *global = global_get_ptr();
2016-10-03 06:15:41 +00:00
const char *old_savefile_dir = dir_get(RARCH_DIR_SAVEFILE);
const char *old_savestate_dir = dir_get(RARCH_DIR_SAVESTATE);
2017-04-23 14:41:26 +00:00
rarch_system_info_t *info = runloop_get_system_info();
2016-09-17 10:16:11 +00:00
2016-10-16 00:00:59 +00:00
new_savefile_dir[0] = new_savestate_dir[0] = '\0';
if (info && !string_is_empty(info->info_int.library_name))
library_name_hash =
msg_hash_calculate(info->info_int.library_name);
2016-09-17 10:16:11 +00:00
/* Initialize current save directories
* with the values from the config. */
2016-10-01 07:03:41 +00:00
strlcpy(new_savefile_dir,
2016-09-17 12:31:39 +00:00
old_savefile_dir,
2016-10-01 07:03:41 +00:00
sizeof(new_savefile_dir));
2016-10-01 07:03:41 +00:00
strlcpy(new_savestate_dir,
2016-09-17 12:31:39 +00:00
old_savestate_dir,
2016-10-01 07:03:41 +00:00
sizeof(new_savestate_dir));
2016-09-17 10:16:11 +00:00
check_library_name_hash = (library_name_hash != 0);
2016-09-17 10:16:11 +00:00
#ifdef HAVE_MENU
check_library_name_hash = check_library_name_hash &&
(library_name_hash != MENU_VALUE_NO_CORE);
2016-09-17 10:16:11 +00:00
#endif
if (check_library_name_hash)
2016-09-17 10:16:11 +00:00
{
2016-09-18 23:47:30 +00:00
settings_t *settings = config_get_ptr();
2016-09-17 10:16:11 +00:00
/* per-core saves: append the library_name to the save location */
2017-04-28 11:43:47 +00:00
if ( settings->bools.sort_savefiles_enable
2016-09-17 12:31:39 +00:00
&& !string_is_empty(old_savefile_dir))
2016-09-17 10:16:11 +00:00
{
fill_pathname_join(
2016-10-01 07:03:41 +00:00
new_savefile_dir,
2016-09-17 12:31:39 +00:00
old_savefile_dir,
info->info_int.library_name,
2016-10-01 07:03:41 +00:00
sizeof(new_savefile_dir));
2016-09-17 10:16:11 +00:00
/* If path doesn't exist, try to create it,
* if everything fails revert to the original path. */
2016-10-01 07:03:41 +00:00
if(!path_is_directory(new_savefile_dir)
&& !string_is_empty(new_savefile_dir))
2016-09-17 10:16:11 +00:00
{
2016-10-01 07:03:41 +00:00
path_mkdir(new_savefile_dir);
if(!path_is_directory(new_savefile_dir))
2016-09-17 10:16:11 +00:00
{
RARCH_LOG("%s %s\n",
msg_hash_to_str(MSG_REVERTING_SAVEFILE_DIRECTORY_TO),
2016-09-17 12:31:39 +00:00
old_savefile_dir);
2016-09-17 10:16:11 +00:00
2016-10-01 07:03:41 +00:00
strlcpy(new_savefile_dir,
2016-09-17 12:31:39 +00:00
old_savefile_dir,
2016-10-01 07:03:41 +00:00
sizeof(new_savefile_dir));
2016-09-17 10:16:11 +00:00
}
}
}
/* per-core states: append the library_name to the save location */
2017-04-28 11:43:47 +00:00
if (settings->bools.sort_savestates_enable
2016-09-17 12:31:39 +00:00
&& !string_is_empty(old_savestate_dir))
2016-09-17 10:16:11 +00:00
{
fill_pathname_join(
2016-10-01 07:03:41 +00:00
new_savestate_dir,
2016-09-17 12:31:39 +00:00
old_savestate_dir,
info->info_int.library_name,
2016-10-01 07:03:41 +00:00
sizeof(new_savestate_dir));
2016-09-17 10:16:11 +00:00
/* If path doesn't exist, try to create it.
* If everything fails, revert to the original path. */
2016-10-01 07:03:41 +00:00
if(!path_is_directory(new_savestate_dir) &&
!string_is_empty(new_savestate_dir))
2016-09-17 10:16:11 +00:00
{
2016-10-01 07:03:41 +00:00
path_mkdir(new_savestate_dir);
if(!path_is_directory(new_savestate_dir))
2016-09-17 10:16:11 +00:00
{
RARCH_LOG("%s %s\n",
msg_hash_to_str(MSG_REVERTING_SAVESTATE_DIRECTORY_TO),
2016-09-17 12:31:39 +00:00
old_savestate_dir);
2016-10-01 07:03:41 +00:00
strlcpy(new_savestate_dir,
2016-09-17 12:31:39 +00:00
old_savestate_dir,
2016-10-01 07:03:41 +00:00
sizeof(new_savestate_dir));
2016-09-17 10:16:11 +00:00
}
}
}
}
/* Set savefile directory if empty based on content directory */
2016-10-01 07:03:41 +00:00
if (string_is_empty(new_savefile_dir))
2016-09-17 10:16:11 +00:00
{
2016-10-01 07:03:41 +00:00
strlcpy(new_savefile_dir, path_main_basename,
sizeof(new_savefile_dir));
path_basedir(new_savefile_dir);
2016-09-17 10:16:11 +00:00
}
if (global)
2016-09-28 06:15:03 +00:00
{
2016-10-01 07:03:41 +00:00
if(path_is_directory(new_savefile_dir))
strlcpy(global->name.savefile, new_savefile_dir,
sizeof(global->name.savefile));
2016-09-17 10:16:11 +00:00
2016-10-01 07:03:41 +00:00
if(path_is_directory(new_savestate_dir))
strlcpy(global->name.savestate, new_savestate_dir,
sizeof(global->name.savestate));
2016-09-17 10:16:11 +00:00
if (path_is_directory(global->name.savefile))
{
2017-01-29 03:48:51 +00:00
fill_pathname_dir(global->name.savefile,
!string_is_empty(path_main_basename) ? path_main_basename :
info->info_int.library_name,
file_path_str(FILE_PATH_SRM_EXTENSION),
sizeof(global->name.savefile));
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_REDIRECTING_SAVEFILE_TO),
global->name.savefile);
}
2016-09-17 10:16:11 +00:00
if (path_is_directory(global->name.savestate))
{
2017-01-29 03:48:51 +00:00
fill_pathname_dir(global->name.savestate,
!string_is_empty(path_main_basename) ? path_main_basename :
info->info_int.library_name,
file_path_str(FILE_PATH_STATE_EXTENSION),
sizeof(global->name.savestate));
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_REDIRECTING_SAVESTATE_TO),
global->name.savestate);
}
2016-09-17 10:16:11 +00:00
if (path_is_directory(global->name.cheatfile))
{
fill_pathname_dir(global->name.cheatfile, path_main_basename,
file_path_str(FILE_PATH_STATE_EXTENSION),
sizeof(global->name.cheatfile));
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_REDIRECTING_CHEATFILE_TO),
global->name.cheatfile);
}
2016-09-17 10:16:11 +00:00
}
2016-10-01 07:03:41 +00:00
2016-10-03 14:05:07 +00:00
dir_set(RARCH_DIR_CURRENT_SAVEFILE, new_savefile_dir);
2016-10-03 06:20:33 +00:00
dir_set(RARCH_DIR_CURRENT_SAVESTATE, new_savestate_dir);
2016-09-17 10:16:11 +00:00
}
2016-09-17 10:10:46 +00:00
void path_set_basename(const char *path)
{
char *dst = NULL;
2016-10-03 14:05:07 +00:00
path_set(RARCH_PATH_CONTENT, path);
path_set(RARCH_PATH_BASENAME, path);
2016-09-17 10:10:46 +00:00
#ifdef HAVE_COMPRESSION
/* Removing extension is a bit tricky for compressed files.
* Basename means:
* /file/to/path/game.extension should be:
* /file/to/path/game
*
* Two things to consider here are: /file/to/path/ is expected
* to be a directory and "game" is a single file. This is used for
* states and srm default paths.
*
* For compressed files we have:
*
* /file/to/path/comp.7z#game.extension and
* /file/to/path/comp.7z#folder/game.extension
*
* The choice I take here is:
* /file/to/path/game as basename. We might end up in a writable
* directory then and the name of srm and states are meaningful.
*
*/
path_basedir_wrapper(path_main_basename);
2016-09-17 17:41:16 +00:00
fill_pathname_dir(path_main_basename, path, "", sizeof(path_main_basename));
2016-09-17 10:10:46 +00:00
#endif
2016-09-17 17:41:16 +00:00
if ((dst = strrchr(path_main_basename, '.')))
2016-09-17 10:10:46 +00:00
*dst = '\0';
}
2016-09-17 10:16:11 +00:00
2016-09-25 13:49:09 +00:00
struct string_list *path_get_subsystem_list(void)
{
return subsystem_fullpaths;
}
2016-09-17 10:19:17 +00:00
void path_set_special(char **argv, unsigned num_content)
{
unsigned i;
union string_list_elem_attr attr;
global_t *global = global_get_ptr();
2016-09-17 10:19:17 +00:00
/* First content file is the significant one. */
path_set_basename(argv[0]);
2016-09-25 13:49:09 +00:00
subsystem_fullpaths = string_list_new();
retro_assert(subsystem_fullpaths);
2016-09-17 10:19:17 +00:00
attr.i = 0;
for (i = 0; i < num_content; i++)
2016-09-25 13:49:09 +00:00
string_list_append(subsystem_fullpaths, argv[i], attr);
2016-09-17 10:19:17 +00:00
/* We defer SRAM path updates until we can resolve it.
* It is more complicated for special content types. */
if (global)
2016-09-17 10:19:17 +00:00
{
2016-10-01 06:24:02 +00:00
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL))
fill_pathname_noext(global->name.savestate, path_main_basename,
file_path_str(FILE_PATH_STATE_EXTENSION),
sizeof(global->name.savestate));
2016-09-30 04:11:11 +00:00
if (path_is_directory(global->name.savestate))
{
fill_pathname_dir(global->name.savestate, path_main_basename,
file_path_str(FILE_PATH_STATE_EXTENSION),
sizeof(global->name.savestate));
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_REDIRECTING_SAVESTATE_TO),
global->name.savestate);
}
2016-09-17 10:19:17 +00:00
}
}
2016-09-17 10:22:51 +00:00
2016-09-18 23:41:00 +00:00
static bool path_init_subsystem(void)
2016-09-17 10:22:51 +00:00
{
2016-09-28 06:15:03 +00:00
unsigned i, j;
2016-09-18 23:41:00 +00:00
const struct retro_subsystem_info *info = NULL;
global_t *global = global_get_ptr();
2017-04-23 14:41:26 +00:00
rarch_system_info_t *system = runloop_get_system_info();
2016-09-17 10:22:51 +00:00
2017-04-23 14:41:26 +00:00
if (!system || path_is_empty(RARCH_PATH_SUBSYSTEM))
2016-09-18 23:41:00 +00:00
return false;
2016-09-17 10:22:51 +00:00
2016-09-18 23:41:00 +00:00
/* For subsystems, we know exactly which RAM types are supported. */
2016-09-17 10:22:51 +00:00
2016-09-18 23:41:00 +00:00
info = libretro_find_subsystem_info(
system->subsystem.data,
system->subsystem.size,
2016-09-29 06:23:41 +00:00
path_get(RARCH_PATH_SUBSYSTEM));
2016-09-17 10:22:51 +00:00
2016-09-18 23:41:00 +00:00
/* We'll handle this error gracefully later. */
2016-09-17 10:22:51 +00:00
2016-09-28 06:15:03 +00:00
if (info)
2016-09-18 23:41:00 +00:00
{
2016-09-28 06:15:03 +00:00
unsigned num_content = MIN(info->num_roms,
2016-09-30 02:43:16 +00:00
path_is_empty(RARCH_PATH_SUBSYSTEM) ?
0 : (unsigned)subsystem_fullpaths->size);
2016-09-28 06:15:03 +00:00
for (i = 0; i < num_content; i++)
2016-09-17 10:22:51 +00:00
{
2016-09-28 06:15:03 +00:00
for (j = 0; j < info->roms[i].num_memory; j++)
{
union string_list_elem_attr attr;
2016-10-16 00:00:59 +00:00
char path[PATH_MAX_LENGTH];
char ext[32];
2016-09-28 06:15:03 +00:00
const struct retro_subsystem_memory_info *mem =
(const struct retro_subsystem_memory_info*)
&info->roms[i].memory[j];
2016-09-17 10:22:51 +00:00
2016-10-16 00:00:59 +00:00
path[0] = ext[0] = '\0';
2016-09-28 06:15:03 +00:00
snprintf(ext, sizeof(ext), ".%s", mem->extension);
2016-09-17 10:22:51 +00:00
2016-10-03 06:15:41 +00:00
if (path_is_directory(dir_get(RARCH_DIR_SAVEFILE)))
2016-09-28 06:15:03 +00:00
{
/* Use SRAM dir */
/* Redirect content fullpath to save directory. */
2016-10-03 06:15:41 +00:00
strlcpy(path, dir_get(RARCH_DIR_SAVEFILE), sizeof(path));
2016-09-28 06:15:03 +00:00
fill_pathname_dir(path,
subsystem_fullpaths->elems[i].data, ext,
sizeof(path));
}
else
{
fill_pathname(path, subsystem_fullpaths->elems[i].data,
ext, sizeof(path));
}
2016-09-17 10:22:51 +00:00
2016-09-28 06:15:03 +00:00
attr.i = mem->type;
string_list_append((struct string_list*)savefile_ptr_get(), path, attr);
}
2016-09-17 10:22:51 +00:00
}
}
2016-09-18 23:41:00 +00:00
if (global)
2016-09-17 10:22:51 +00:00
{
/* Let other relevant paths be inferred from the main SRAM location. */
2016-10-01 06:24:02 +00:00
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL))
fill_pathname_noext(global->name.savefile,
path_main_basename,
file_path_str(FILE_PATH_SRM_EXTENSION),
sizeof(global->name.savefile));
if (path_is_directory(global->name.savefile))
{
fill_pathname_dir(global->name.savefile,
path_main_basename,
file_path_str(FILE_PATH_SRM_EXTENSION),
sizeof(global->name.savefile));
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_REDIRECTING_SAVEFILE_TO),
global->name.savefile);
}
2016-09-17 10:22:51 +00:00
}
2016-09-18 23:41:00 +00:00
return true;
}
2016-09-19 01:03:31 +00:00
void path_init_savefile(void)
{
2016-09-28 05:27:39 +00:00
bool should_sram_be_used = rarch_ctl(RARCH_CTL_IS_SRAM_USED, NULL)
&& !rarch_ctl(RARCH_CTL_IS_SRAM_SAVE_DISABLED, NULL);
2016-09-19 01:03:31 +00:00
if (should_sram_be_used)
rarch_ctl(RARCH_CTL_SET_SRAM_ENABLE_FORCE, NULL);
else
rarch_ctl(RARCH_CTL_UNSET_SRAM_ENABLE, NULL);
2016-09-19 01:03:31 +00:00
2016-09-29 06:25:37 +00:00
if (!rarch_ctl(RARCH_CTL_IS_SRAM_USED, NULL))
{
2016-09-29 06:25:37 +00:00
RARCH_LOG("%s\n",
msg_hash_to_str(MSG_SRAM_WILL_NOT_BE_SAVED));
return;
}
2016-09-29 06:25:37 +00:00
command_event(CMD_EVENT_AUTOSAVE_INIT, NULL);
2016-09-19 01:03:31 +00:00
}
static void path_init_savefile_internal(void)
2016-09-18 23:41:00 +00:00
{
2016-09-19 01:03:31 +00:00
path_deinit_savefile();
2016-09-18 23:41:00 +00:00
path_init_savefile_new();
2016-09-18 23:41:00 +00:00
if (!path_init_subsystem())
2017-05-07 15:52:48 +00:00
{
global_t *global = global_get_ptr();
path_init_savefile_rtc(global->name.savefile);
}
2016-09-17 10:22:51 +00:00
}
void path_fill_names(void)
{
global_t *global = global_get_ptr();
2016-09-30 04:11:11 +00:00
path_init_savefile_internal();
if (global)
bsv_movie_set_path(global->name.savefile);
2016-09-17 17:41:16 +00:00
if (string_is_empty(path_main_basename))
return;
if (global)
2016-09-29 08:07:10 +00:00
{
if (string_is_empty(global->name.ups))
fill_pathname_noext(global->name.ups, path_main_basename,
file_path_str(FILE_PATH_UPS_EXTENSION),
sizeof(global->name.ups));
if (string_is_empty(global->name.bps))
fill_pathname_noext(global->name.bps, path_main_basename,
file_path_str(FILE_PATH_BPS_EXTENSION),
sizeof(global->name.bps));
if (string_is_empty(global->name.ips))
fill_pathname_noext(global->name.ips, path_main_basename,
file_path_str(FILE_PATH_IPS_EXTENSION),
sizeof(global->name.ips));
2016-09-29 08:07:10 +00:00
}
}
2016-09-17 10:35:29 +00:00
2016-10-03 13:44:20 +00:00
char *path_get_ptr(enum rarch_path_type type)
{
switch (type)
{
case RARCH_PATH_CONTENT:
return path_content;
case RARCH_PATH_DEFAULT_SHADER_PRESET:
return path_default_shader_preset;
case RARCH_PATH_BASENAME:
return path_main_basename;
case RARCH_PATH_CORE_OPTIONS:
if (!path_is_empty(RARCH_PATH_CORE_OPTIONS))
return path_core_options_file;
break;
case RARCH_PATH_SUBSYSTEM:
return subsystem_path;
case RARCH_PATH_CONFIG:
if (!path_is_empty(RARCH_PATH_CONFIG))
return path_config_file;
break;
case RARCH_PATH_CONFIG_APPEND:
if (!path_is_empty(RARCH_PATH_CONFIG_APPEND))
return path_config_append_file;
break;
case RARCH_PATH_CORE:
return path_libretro;
case RARCH_PATH_NONE:
case RARCH_PATH_NAMES:
break;
}
return NULL;
}
2016-09-29 06:23:41 +00:00
const char *path_get(enum rarch_path_type type)
2016-09-17 10:35:29 +00:00
{
2016-09-29 06:23:41 +00:00
switch (type)
{
2016-10-01 09:47:51 +00:00
case RARCH_PATH_CONTENT:
return path_content;
case RARCH_PATH_DEFAULT_SHADER_PRESET:
return path_default_shader_preset;
2016-09-29 06:46:41 +00:00
case RARCH_PATH_BASENAME:
return path_main_basename;
2016-09-29 06:34:08 +00:00
case RARCH_PATH_CORE_OPTIONS:
2016-09-30 02:43:16 +00:00
if (!path_is_empty(RARCH_PATH_CORE_OPTIONS))
2016-09-29 06:34:08 +00:00
return path_core_options_file;
break;
2016-09-29 06:23:41 +00:00
case RARCH_PATH_SUBSYSTEM:
return subsystem_path;
2016-09-29 06:31:41 +00:00
case RARCH_PATH_CONFIG:
2016-09-30 02:43:16 +00:00
if (!path_is_empty(RARCH_PATH_CONFIG))
2016-09-29 06:31:41 +00:00
return path_config_file;
break;
case RARCH_PATH_CONFIG_APPEND:
2016-09-30 02:43:16 +00:00
if (!path_is_empty(RARCH_PATH_CONFIG_APPEND))
2016-09-29 06:31:41 +00:00
return path_config_append_file;
break;
2016-09-29 06:23:41 +00:00
case RARCH_PATH_CORE:
return path_libretro;
case RARCH_PATH_NONE:
2016-10-01 09:47:51 +00:00
case RARCH_PATH_NAMES:
2016-09-29 06:23:41 +00:00
break;
}
return NULL;
2016-09-17 10:35:29 +00:00
}
2016-10-03 14:16:55 +00:00
size_t path_get_realsize(enum rarch_path_type type)
{
2016-10-03 14:16:55 +00:00
switch (type)
{
case RARCH_PATH_CONTENT:
return sizeof(path_content);
case RARCH_PATH_DEFAULT_SHADER_PRESET:
return sizeof(path_default_shader_preset);
case RARCH_PATH_BASENAME:
return sizeof(path_main_basename);
case RARCH_PATH_CORE_OPTIONS:
return sizeof(path_core_options_file);
case RARCH_PATH_SUBSYSTEM:
return sizeof(subsystem_path);
case RARCH_PATH_CONFIG:
return sizeof(path_config_file);
case RARCH_PATH_CONFIG_APPEND:
return sizeof(path_config_append_file);
case RARCH_PATH_CORE:
return sizeof(path_libretro);
case RARCH_PATH_NONE:
case RARCH_PATH_NAMES:
break;
}
return 0;
2016-09-17 10:35:29 +00:00
}
static void path_set_names(const char *path)
{
global_t *global = global_get_ptr();
2016-09-30 04:11:11 +00:00
path_set_basename(path);
2016-09-30 04:11:11 +00:00
if (global)
{
2016-10-01 06:24:02 +00:00
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL))
fill_pathname_noext(global->name.savefile, path_main_basename,
file_path_str(FILE_PATH_SRM_EXTENSION), sizeof(global->name.savefile));
2016-10-01 06:24:02 +00:00
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL))
fill_pathname_noext(global->name.savestate, path_main_basename,
file_path_str(FILE_PATH_STATE_EXTENSION), sizeof(global->name.savestate));
fill_pathname_noext(global->name.cheatfile, path_main_basename,
file_path_str(FILE_PATH_CHT_EXTENSION), sizeof(global->name.cheatfile));
}
path_set_redirect();
}
2016-09-29 05:40:14 +00:00
bool path_set(enum rarch_path_type type, const char *path)
2016-09-25 13:49:09 +00:00
{
2016-09-29 05:40:14 +00:00
if (!path)
return false;
2016-09-29 05:36:09 +00:00
switch (type)
{
2016-10-01 09:47:51 +00:00
case RARCH_PATH_BASENAME:
strlcpy(path_main_basename, path,
sizeof(path_main_basename));
break;
case RARCH_PATH_NAMES:
path_set_names(path);
break;
2016-09-29 05:46:21 +00:00
case RARCH_PATH_CORE:
strlcpy(path_libretro, path,
sizeof(path_libretro));
break;
2016-09-29 05:49:54 +00:00
case RARCH_PATH_DEFAULT_SHADER_PRESET:
strlcpy(path_default_shader_preset, path,
sizeof(path_default_shader_preset));
break;
case RARCH_PATH_CONFIG_APPEND:
strlcpy(path_config_append_file, path,
sizeof(path_config_append_file));
break;
2016-09-29 05:46:21 +00:00
case RARCH_PATH_CONFIG:
strlcpy(path_config_file, path,
sizeof(path_config_file));
break;
2016-09-29 05:36:09 +00:00
case RARCH_PATH_SUBSYSTEM:
2016-09-29 05:46:21 +00:00
strlcpy(subsystem_path, path,
sizeof(subsystem_path));
2016-09-29 05:36:09 +00:00
break;
2016-09-29 05:40:14 +00:00
case RARCH_PATH_CORE_OPTIONS:
2016-09-29 05:46:21 +00:00
strlcpy(path_core_options_file, path,
sizeof(path_core_options_file));
2016-09-29 05:40:14 +00:00
break;
case RARCH_PATH_CONTENT:
2016-09-29 05:46:21 +00:00
strlcpy(path_content, path,
sizeof(path_content));
2016-09-29 05:40:14 +00:00
break;
2016-09-29 05:36:09 +00:00
case RARCH_PATH_NONE:
break;
}
2016-09-29 05:40:14 +00:00
return true;
2016-09-25 13:49:09 +00:00
}
2016-09-30 02:43:16 +00:00
bool path_is_empty(enum rarch_path_type type)
2016-09-17 10:35:29 +00:00
{
2016-09-30 02:43:16 +00:00
switch (type)
{
2016-10-01 09:47:51 +00:00
case RARCH_PATH_DEFAULT_SHADER_PRESET:
if (string_is_empty(path_default_shader_preset))
return true;
break;
2016-09-30 02:43:16 +00:00
case RARCH_PATH_SUBSYSTEM:
if (string_is_empty(subsystem_path))
return true;
break;
case RARCH_PATH_CONFIG:
if (string_is_empty(path_config_file))
return true;
break;
case RARCH_PATH_CORE_OPTIONS:
if (string_is_empty(path_core_options_file))
return true;
break;
case RARCH_PATH_CONFIG_APPEND:
if (string_is_empty(path_config_append_file))
return true;
break;
2016-10-01 09:47:51 +00:00
case RARCH_PATH_CONTENT:
if (string_is_empty(path_content))
return true;
break;
2016-09-30 02:43:16 +00:00
case RARCH_PATH_CORE:
2016-10-01 09:47:51 +00:00
if (string_is_empty(path_libretro))
return true;
break;
case RARCH_PATH_BASENAME:
if (string_is_empty(path_main_basename))
return true;
break;
case RARCH_PATH_NONE:
case RARCH_PATH_NAMES:
2016-09-30 02:43:16 +00:00
break;
}
return false;
}
2016-09-30 02:31:19 +00:00
void path_clear(enum rarch_path_type type)
{
2016-09-30 02:31:19 +00:00
switch (type)
{
case RARCH_PATH_SUBSYSTEM:
*subsystem_path = '\0';
break;
case RARCH_PATH_CORE:
*path_libretro = '\0';
break;
case RARCH_PATH_CONFIG:
*path_config_file = '\0';
break;
case RARCH_PATH_CONTENT:
*path_content = '\0';
break;
case RARCH_PATH_BASENAME:
*path_main_basename = '\0';
break;
case RARCH_PATH_CORE_OPTIONS:
*path_core_options_file = '\0';
break;
case RARCH_PATH_DEFAULT_SHADER_PRESET:
*path_default_shader_preset = '\0';
break;
case RARCH_PATH_CONFIG_APPEND:
*path_config_append_file = '\0';
break;
2016-10-01 09:47:51 +00:00
case RARCH_PATH_NONE:
case RARCH_PATH_NAMES:
2016-09-30 02:31:19 +00:00
break;
}
}
2016-09-30 02:31:19 +00:00
void path_clear_all(void)
2016-09-17 17:41:16 +00:00
{
2016-10-03 06:24:35 +00:00
path_clear(RARCH_PATH_CONTENT);
2016-09-30 02:31:19 +00:00
path_clear(RARCH_PATH_CONFIG);
path_clear(RARCH_PATH_CONFIG_APPEND);
path_clear(RARCH_PATH_CORE_OPTIONS);
path_clear(RARCH_PATH_BASENAME);
2016-09-17 17:41:16 +00:00
}
enum rarch_content_type path_is_media_type(const char *path)
{
char ext_lower[128];
2016-10-16 00:00:59 +00:00
ext_lower[0] = '\0';
strlcpy(ext_lower, path_get_extension(path), sizeof(ext_lower));
string_to_lower(ext_lower);
switch (msg_hash_to_file_type(msg_hash_calculate(ext_lower)))
{
#ifdef HAVE_FFMPEG
case FILE_TYPE_OGM:
case FILE_TYPE_MKV:
case FILE_TYPE_AVI:
case FILE_TYPE_MP4:
case FILE_TYPE_FLV:
case FILE_TYPE_WEBM:
case FILE_TYPE_3GP:
case FILE_TYPE_3G2:
case FILE_TYPE_F4F:
case FILE_TYPE_F4V:
case FILE_TYPE_MOV:
case FILE_TYPE_WMV:
case FILE_TYPE_MPG:
case FILE_TYPE_MPEG:
case FILE_TYPE_VOB:
case FILE_TYPE_ASF:
case FILE_TYPE_DIVX:
case FILE_TYPE_M2P:
case FILE_TYPE_M2TS:
case FILE_TYPE_PS:
case FILE_TYPE_TS:
case FILE_TYPE_MXF:
return RARCH_CONTENT_MOVIE;
case FILE_TYPE_WMA:
case FILE_TYPE_OGG:
case FILE_TYPE_MP3:
case FILE_TYPE_M4A:
case FILE_TYPE_FLAC:
case FILE_TYPE_WAV:
return RARCH_CONTENT_MUSIC;
#endif
#ifdef HAVE_IMAGEVIEWER
case FILE_TYPE_JPEG:
case FILE_TYPE_PNG:
case FILE_TYPE_TGA:
case FILE_TYPE_BMP:
return RARCH_CONTENT_IMAGE;
#endif
case FILE_TYPE_NONE:
default:
break;
}
return RARCH_CONTENT_NONE;
}
2016-09-25 13:49:09 +00:00
void path_deinit_subsystem(void)
{
if (subsystem_fullpaths)
string_list_free(subsystem_fullpaths);
subsystem_fullpaths = NULL;
}