Create paths.c

This commit is contained in:
twinaphex 2016-09-17 12:10:46 +02:00
parent 96d4347c4a
commit 005b86eb5d
5 changed files with 94 additions and 38 deletions

View File

@ -132,6 +132,7 @@ OBJ += frontend/frontend.o \
ui/drivers/null/ui_null_application.o \
core_impl.o \
retroarch.o \
paths.o \
input/input_keyboard.o \
command.o \
msg_hash.o \

View File

@ -797,6 +797,7 @@ RETROARCH
============================================================ */
#include "../core_impl.c"
#include "../retroarch.c"
#include "../paths.c"
#include "../runloop.c"
#include "../libretro-common/queues/task_queue.c"

61
paths.c Normal file
View File

@ -0,0 +1,61 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* 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/>.
*/
#include <compat/strl.h>
#include <file/file_path.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "paths.h"
#include "runloop.h"
void path_set_basename(const char *path)
{
char *dst = NULL;
global_t *global = global_get_ptr();
runloop_ctl(RUNLOOP_CTL_SET_CONTENT_PATH, (void*)path);
strlcpy(global->name.base, path, sizeof(global->name.base));
#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(global->name.base);
fill_pathname_dir(global->name.base, path, "", sizeof(global->name.base));
#endif
if ((dst = strrchr(global->name.base, '.')))
*dst = '\0';
}

28
paths.h Normal file
View File

@ -0,0 +1,28 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* 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/>.
*/
#ifndef __PATHS_H
#define __PATHS_H
#include <boolean.h>
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
void path_set_basename(const char *path);
RETRO_END_DECLS
#endif

View File

@ -64,6 +64,7 @@
#include "driver.h"
#include "msg_hash.h"
#include "movie.h"
#include "paths.h"
#include "file_path_special.h"
#include "verbosity.h"
@ -338,42 +339,6 @@ static void retroarch_print_help(const char *arg0)
"then exits.\n");
}
static void retroarch_set_basename(const char *path)
{
char *dst = NULL;
global_t *global = global_get_ptr();
runloop_ctl(RUNLOOP_CTL_SET_CONTENT_PATH, (void*)path);
strlcpy(global->name.base, path, sizeof(global->name.base));
#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(global->name.base);
fill_pathname_dir(global->name.base, path, "", sizeof(global->name.base));
#endif
if ((dst = strrchr(global->name.base, '.')))
*dst = '\0';
}
static void retroarch_set_special_paths(char **argv, unsigned num_content)
{
unsigned i;
@ -381,7 +346,7 @@ static void retroarch_set_special_paths(char **argv, unsigned num_content)
global_t *global = global_get_ptr();
/* First content file is the significant one. */
retroarch_set_basename(argv[0]);
path_set_basename(argv[0]);
global->subsystem_fullpaths = string_list_new();
retro_assert(global->subsystem_fullpaths);
@ -1603,7 +1568,7 @@ void retroarch_set_pathnames(const char *path)
{
global_t *global = global_get_ptr();
retroarch_set_basename(path);
path_set_basename(path);
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_SAVE_PATH))
fill_pathname_noext(global->name.savefile, global->name.base,