mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 15:40:44 +00:00
Merge rarch_compr_file_path.c into file_extract.c
This commit is contained in:
parent
9f8c96daa1
commit
140130dc37
@ -96,7 +96,6 @@ OBJ += frontend/frontend.o \
|
||||
libretro-sdk/string/string_list.o \
|
||||
file_ops.o \
|
||||
libretro-sdk/file/file_path.o \
|
||||
rarch_compr_file_path.o \
|
||||
hash.o \
|
||||
driver.o \
|
||||
settings.o \
|
||||
|
@ -504,3 +504,74 @@ struct string_list *zlib_get_file_list(const char *path)
|
||||
return list;
|
||||
}
|
||||
|
||||
#ifdef HAVE_COMPRESSION
|
||||
/* Generic compressed file loader.
|
||||
* Extracts to buf, unless optional_filename != 0
|
||||
* Then extracts to optional_filename and leaves buf alone.
|
||||
*/
|
||||
long read_compressed_file(const char * path, void **buf,
|
||||
const char* optional_filename)
|
||||
{
|
||||
char archive_path[PATH_MAX_LENGTH], *archive_found = NULL;
|
||||
|
||||
/* Safety check.
|
||||
* If optional_filename and optional_filename exists, we simply return 0,
|
||||
* hoping that optional_filename is the same as requested.
|
||||
*/
|
||||
if (optional_filename)
|
||||
if(path_file_exists(optional_filename))
|
||||
return 0;
|
||||
|
||||
//We split carchive path and relative path:
|
||||
strlcpy(archive_path,path,sizeof(archive_path));
|
||||
archive_found = (char*)strchr(archive_path,'#');
|
||||
rarch_assert(archive_found != NULL);
|
||||
|
||||
//We assure that there is something after the '#' symbol
|
||||
if (strlen(archive_found) <= 1)
|
||||
{
|
||||
/*
|
||||
* This error condition happens for example, when
|
||||
* path = /path/to/file.7z, or
|
||||
* path = /path/to/file.7z#
|
||||
*/
|
||||
RARCH_ERR("Could not extract image path and carchive path from "
|
||||
"path: %s.\n", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//We split the string in two, by putting a \0, where the hash was:
|
||||
*archive_found = '\0';
|
||||
archive_found+=1;
|
||||
|
||||
|
||||
const char* file_ext = path_get_extension(archive_path);
|
||||
#ifdef HAVE_7ZIP
|
||||
if (strcasecmp(file_ext,"7z") == 0)
|
||||
return read_7zip_file(archive_path,archive_found,buf,optional_filename);
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
if (strcasecmp(file_ext,"zip") == 0)
|
||||
return read_zip_file(archive_path,archive_found,buf,optional_filename);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct string_list *compressed_file_list_new(const char *path,
|
||||
const char* ext)
|
||||
{
|
||||
#ifdef HAVE_COMPRESSION
|
||||
const char* file_ext = path_get_extension(path);
|
||||
#ifdef HAVE_7ZIP
|
||||
if (strcasecmp(file_ext,"7z") == 0)
|
||||
return compressed_7zip_file_list_new(path,ext);
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
if (strcasecmp(file_ext,"zip") == 0)
|
||||
return compressed_zip_file_list_new(path,ext);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
@ -21,6 +21,14 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef HAVE_7ZIP
|
||||
#include "decompress/7zip_support.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
#include "decompress/zip_support.h"
|
||||
#endif
|
||||
|
||||
/* Returns true when parsing should continue. False to stop. */
|
||||
typedef bool (*zlib_file_cb)(const char *name,
|
||||
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
||||
|
@ -549,7 +549,6 @@ FILE
|
||||
#include "../libretro-sdk/file/dir_list.c"
|
||||
#include "../libretro-sdk/string/string_list.c"
|
||||
#include "../file_ops.c"
|
||||
#include "../rarch_compr_file_path.c"
|
||||
#include "../libretro-sdk/file/file_list.c"
|
||||
|
||||
/*============================================================
|
||||
|
@ -1,136 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2014-2015 - Timo Strunks
|
||||
* Copyright (C) 2011-2015 - 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 <file/file_path.h>
|
||||
#include <stdlib.h>
|
||||
#include <boolean.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <compat/strl.h>
|
||||
#include <compat/posix_string.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
|
||||
#include "rarch_compr_file_path.h"
|
||||
|
||||
#ifdef __HAIKU__
|
||||
#include <kernel/image.h>
|
||||
#endif
|
||||
|
||||
#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP)
|
||||
#include <unistd.h> /* stat() is defined here */
|
||||
#endif
|
||||
|
||||
#if defined(__CELLOS_LV2__)
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(x) (x & 0040000)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#ifdef _MSC_VER
|
||||
#define setmode _setmode
|
||||
#endif
|
||||
#ifdef _XBOX
|
||||
#include <xtl.h>
|
||||
#define INVALID_FILE_ATTRIBUTES -1
|
||||
#else
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* Generic compressed file loader.
|
||||
* Extracts to buf, unless optional_filename != 0
|
||||
* Then extracts to optional_filename and leaves buf alone.
|
||||
*/
|
||||
#ifdef HAVE_COMPRESSION
|
||||
long read_compressed_file(const char * path, void **buf,
|
||||
const char* optional_filename)
|
||||
{
|
||||
char archive_path[PATH_MAX_LENGTH], *archive_found = NULL;
|
||||
|
||||
/* Safety check.
|
||||
* If optional_filename and optional_filename exists, we simply return 0,
|
||||
* hoping that optional_filename is the same as requested.
|
||||
*/
|
||||
if (optional_filename)
|
||||
if(path_file_exists(optional_filename))
|
||||
return 0;
|
||||
|
||||
//We split carchive path and relative path:
|
||||
strlcpy(archive_path,path,sizeof(archive_path));
|
||||
archive_found = (char*)strchr(archive_path,'#');
|
||||
rarch_assert(archive_found != NULL);
|
||||
|
||||
//We assure that there is something after the '#' symbol
|
||||
if (strlen(archive_found) <= 1)
|
||||
{
|
||||
/*
|
||||
* This error condition happens for example, when
|
||||
* path = /path/to/file.7z, or
|
||||
* path = /path/to/file.7z#
|
||||
*/
|
||||
RARCH_ERR("Could not extract image path and carchive path from "
|
||||
"path: %s.\n", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//We split the string in two, by putting a \0, where the hash was:
|
||||
*archive_found = '\0';
|
||||
archive_found+=1;
|
||||
|
||||
|
||||
const char* file_ext = path_get_extension(archive_path);
|
||||
#ifdef HAVE_7ZIP
|
||||
if (strcasecmp(file_ext,"7z") == 0)
|
||||
return read_7zip_file(archive_path,archive_found,buf,optional_filename);
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
if (strcasecmp(file_ext,"zip") == 0)
|
||||
return read_zip_file(archive_path,archive_found,buf,optional_filename);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct string_list *compressed_file_list_new(const char *path,
|
||||
const char* ext)
|
||||
{
|
||||
#ifdef HAVE_COMPRESSION
|
||||
const char* file_ext = path_get_extension(path);
|
||||
#ifdef HAVE_7ZIP
|
||||
if (strcasecmp(file_ext,"7z") == 0)
|
||||
return compressed_7zip_file_list_new(path,ext);
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
if (strcasecmp(file_ext,"zip") == 0)
|
||||
return compressed_zip_file_list_new(path,ext);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2014-2015 - Timo Strunks
|
||||
* Copyright (C) 2011-2015 - 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 _RARCH_COMPR_FILE_PATH_H
|
||||
#define _RARCH_COMPR_FILE_PATH_H
|
||||
|
||||
#ifdef HAVE_7ZIP
|
||||
#include "decompress/7zip_support.h"
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
#include "decompress/zip_support.h"
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user