mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-18 17:04:34 +00:00
Move compression-related code outside of libretro-common file_path.c
and move it into RetroArch's file_path_special.c file instead
This commit is contained in:
parent
bd67208d74
commit
5364b0b837
@ -80,7 +80,7 @@ void fill_pathname_expand_special(char *out_path,
|
||||
application_dir[0] = '\0';
|
||||
|
||||
fill_pathname_application_path(application_dir, sizeof(application_dir));
|
||||
path_basedir(application_dir);
|
||||
path_basedir_wrapper(application_dir);
|
||||
|
||||
src_size = strlcpy(out_path, application_dir, size);
|
||||
retro_assert(src_size < size);
|
||||
@ -122,7 +122,7 @@ void fill_pathname_abbreviate_special(char *out_path,
|
||||
notations [2] = NULL;
|
||||
|
||||
fill_pathname_application_path(application_dir, sizeof(application_dir));
|
||||
path_basedir(application_dir);
|
||||
path_basedir_wrapper(application_dir);
|
||||
|
||||
for (i = 0; candidates[i]; i++)
|
||||
{
|
||||
@ -458,3 +458,79 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fill_short_pathname_representation:
|
||||
* @out_rep : output representation
|
||||
* @in_path : input path
|
||||
* @size : size of output representation
|
||||
*
|
||||
* Generates a short representation of path. It should only
|
||||
* be used for displaying the result; the output representation is not
|
||||
* binding in any meaningful way (for a normal path, this is the same as basename)
|
||||
* In case of more complex URLs, this should cut everything except for
|
||||
* the main image file.
|
||||
*
|
||||
* E.g.: "/path/to/game.img" -> game.img
|
||||
* "/path/to/myarchive.7z#folder/to/game.img" -> game.img
|
||||
*/
|
||||
void fill_short_pathname_representation_wrapper(char* out_rep,
|
||||
const char *in_path, size_t size)
|
||||
{
|
||||
char path_short[PATH_MAX_LENGTH];
|
||||
#ifdef HAVE_COMPRESSION
|
||||
char *last_slash = NULL;
|
||||
#endif
|
||||
|
||||
path_short[0] = '\0';
|
||||
|
||||
fill_pathname(path_short, path_basename(in_path), "",
|
||||
sizeof(path_short));
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
last_slash = find_last_slash(path_short);
|
||||
if (last_slash != NULL)
|
||||
{
|
||||
/* We handle paths like:
|
||||
* /path/to/file.7z#mygame.img
|
||||
* short_name: mygame.img:
|
||||
*
|
||||
* We check whether something is actually
|
||||
* after the hash to avoid going over the buffer.
|
||||
*/
|
||||
retro_assert(strlen(last_slash) > 1);
|
||||
strlcpy(out_rep, last_slash + 1, size);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
fill_short_pathname_representation(out_rep, in_path, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* path_basedir:
|
||||
* @path : path
|
||||
*
|
||||
* Extracts base directory by mutating path.
|
||||
* Keeps trailing '/'.
|
||||
**/
|
||||
void path_basedir_wrapper(char *path)
|
||||
{
|
||||
char *last = NULL;
|
||||
if (strlen(path) < 2)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
/* We want to find the directory with the archive in basedir. */
|
||||
last = (char*)path_get_archive_delim(path);
|
||||
if (last)
|
||||
*last = '\0';
|
||||
#endif
|
||||
|
||||
last = find_last_slash(path);
|
||||
|
||||
if (last)
|
||||
last[1] = '\0';
|
||||
else
|
||||
snprintf(path, 3, ".%s", path_default_slash());
|
||||
}
|
||||
|
@ -100,6 +100,33 @@ enum application_special_type
|
||||
APPLICATION_SPECIAL_DIRECTORY_ASSETS_ZARCH_ICONS
|
||||
};
|
||||
|
||||
/**
|
||||
* fill_short_pathname_representation:
|
||||
* @out_rep : output representation
|
||||
* @in_path : input path
|
||||
* @size : size of output representation
|
||||
*
|
||||
* Generates a short representation of path. It should only
|
||||
* be used for displaying the result; the output representation is not
|
||||
* binding in any meaningful way (for a normal path, this is the same as basename)
|
||||
* In case of more complex URLs, this should cut everything except for
|
||||
* the main image file.
|
||||
*
|
||||
* E.g.: "/path/to/game.img" -> game.img
|
||||
* "/path/to/myarchive.7z#folder/to/game.img" -> game.img
|
||||
*/
|
||||
void fill_short_pathname_representation_wrapper(char* out_rep,
|
||||
const char *in_path, size_t size);
|
||||
|
||||
/**
|
||||
* path_basedir:
|
||||
* @path : path
|
||||
*
|
||||
* Extracts base directory by mutating path.
|
||||
* Keeps trailing '/'.
|
||||
**/
|
||||
void path_basedir_wrapper(char *path);
|
||||
|
||||
const char *file_path_str(enum file_path_enum enum_idx);
|
||||
|
||||
bool fill_pathname_application_data(char *s, size_t len);
|
||||
|
@ -477,13 +477,6 @@ void path_basedir(char *path)
|
||||
if (strlen(path) < 2)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
/* We want to find the directory with the archive in basedir. */
|
||||
last = (char*)path_get_archive_delim(path);
|
||||
if (last)
|
||||
*last = '\0';
|
||||
#endif
|
||||
|
||||
last = find_last_slash(path);
|
||||
|
||||
if (last)
|
||||
@ -721,32 +714,13 @@ void fill_short_pathname_representation(char* out_rep,
|
||||
const char *in_path, size_t size)
|
||||
{
|
||||
char path_short[PATH_MAX_LENGTH];
|
||||
#ifdef HAVE_COMPRESSION
|
||||
char *last_slash = NULL;
|
||||
#endif
|
||||
|
||||
path_short[0] = '\0';
|
||||
|
||||
fill_pathname(path_short, path_basename(in_path), "",
|
||||
sizeof(path_short));
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
last_slash = find_last_slash(path_short);
|
||||
if (last_slash != NULL)
|
||||
{
|
||||
/* We handle paths like:
|
||||
* /path/to/file.7z#mygame.img
|
||||
* short_name: mygame.img:
|
||||
*
|
||||
* We check whether something is actually
|
||||
* after the hash to avoid going over the buffer.
|
||||
*/
|
||||
retro_assert(strlen(last_slash) > 1);
|
||||
strlcpy(out_rep, last_slash + 1, size);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
strlcpy(out_rep, path_short, size);
|
||||
strlcpy(out_rep, path_short, size);
|
||||
}
|
||||
|
||||
void fill_short_pathname_representation_noext(char* out_rep,
|
||||
|
@ -2370,7 +2370,7 @@ static void cb_generic_download(void *task_data,
|
||||
transf->path, sizeof(output_path));
|
||||
|
||||
/* Make sure the directory exists */
|
||||
path_basedir(output_path);
|
||||
path_basedir_wrapper(output_path);
|
||||
|
||||
if (!path_mkdir(output_path))
|
||||
{
|
||||
|
2
paths.c
2
paths.c
@ -237,7 +237,7 @@ void path_set_basename(const char *path)
|
||||
* directory then and the name of srm and states are meaningful.
|
||||
*
|
||||
*/
|
||||
path_basedir(path_main_basename);
|
||||
path_basedir_wrapper(path_main_basename);
|
||||
fill_pathname_dir(path_main_basename, path, "", sizeof(path_main_basename));
|
||||
#endif
|
||||
|
||||
|
@ -1047,7 +1047,7 @@ static void update_firmware_status(void)
|
||||
else
|
||||
{
|
||||
strlcpy(s, path_get(RARCH_PATH_CONTENT) ,sizeof(s));
|
||||
path_basedir(s);
|
||||
path_basedir_wrapper(s);
|
||||
firmware_info.directory.system = s;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <compat/strl.h>
|
||||
|
||||
#include "tasks_internal.h"
|
||||
#include "../file_path_special.h"
|
||||
#include "../verbosity.h"
|
||||
#include "../msg_hash.h"
|
||||
|
||||
@ -98,7 +99,7 @@ static int file_decompressed(const char *name, const char *valid_exts,
|
||||
|
||||
/* Make directory */
|
||||
fill_pathname_join(path, dec->target_dir, name, sizeof(path));
|
||||
path_basedir(path);
|
||||
path_basedir_wrapper(path);
|
||||
|
||||
if (!path_mkdir(path))
|
||||
goto error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user