2016-03-20 16:14:40 +01:00
|
|
|
/* Copyright (C) 2010-2016 The RetroArch team
|
2013-01-21 23:51:56 +01:00
|
|
|
*
|
2015-03-28 20:14:19 +01:00
|
|
|
* ---------------------------------------------------------------------------------------
|
2016-03-20 16:14:40 +01:00
|
|
|
* The following license statement only applies to this file (archive_file.h).
|
2015-03-28 20:14:19 +01:00
|
|
|
* ---------------------------------------------------------------------------------------
|
2013-01-21 23:51:56 +01:00
|
|
|
*
|
2015-03-28 20:14:19 +01:00
|
|
|
* Permission is hereby granted, free of charge,
|
|
|
|
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2013-01-21 23:51:56 +01:00
|
|
|
*/
|
|
|
|
|
2016-03-20 16:14:40 +01:00
|
|
|
#ifndef LIBRETRO_SDK_ARCHIVE_FILE_H__
|
|
|
|
#define LIBRETRO_SDK_ARCHIVE_FILE_H__
|
2013-01-21 23:51:56 +01:00
|
|
|
|
2013-10-05 18:07:38 +02:00
|
|
|
#include <stdint.h>
|
2015-09-15 18:59:40 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <boolean.h>
|
2013-01-21 23:51:56 +01:00
|
|
|
|
2016-09-21 02:30:21 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <direct.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2016-09-18 15:20:27 -04:00
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
|
2016-01-24 22:17:11 +01:00
|
|
|
enum file_archive_transfer_type
|
2015-05-27 01:36:15 +02:00
|
|
|
{
|
2016-09-18 00:38:59 -04:00
|
|
|
ARCHIVE_TRANSFER_NONE = 0,
|
|
|
|
ARCHIVE_TRANSFER_INIT,
|
|
|
|
ARCHIVE_TRANSFER_ITERATE,
|
|
|
|
ARCHIVE_TRANSFER_DEINIT,
|
|
|
|
ARCHIVE_TRANSFER_DEINIT_ERROR
|
2015-05-27 01:36:15 +02:00
|
|
|
};
|
|
|
|
|
2016-01-24 22:17:11 +01:00
|
|
|
typedef struct file_archive_handle
|
2016-01-24 21:23:33 +01:00
|
|
|
{
|
|
|
|
void *stream;
|
2016-09-18 00:38:59 -04:00
|
|
|
uint8_t *data;
|
2016-01-24 21:23:33 +01:00
|
|
|
uint32_t real_checksum;
|
2016-01-24 22:17:11 +01:00
|
|
|
const struct file_archive_file_backend *backend;
|
|
|
|
} file_archive_file_handle_t;
|
2016-01-24 21:23:33 +01:00
|
|
|
|
2016-09-19 18:26:16 +02:00
|
|
|
typedef struct file_archive_file_data file_archive_file_data_t;
|
2016-09-19 12:06:07 -04:00
|
|
|
|
2016-09-18 00:38:59 -04:00
|
|
|
typedef struct file_archive_transfer
|
|
|
|
{
|
2016-09-19 12:06:07 -04:00
|
|
|
file_archive_file_data_t *handle;
|
2016-09-18 00:38:59 -04:00
|
|
|
void *stream;
|
|
|
|
const uint8_t *footer;
|
|
|
|
const uint8_t *directory;
|
|
|
|
const uint8_t *data;
|
|
|
|
int32_t archive_size;
|
|
|
|
enum file_archive_transfer_type type;
|
|
|
|
const struct file_archive_file_backend *backend;
|
|
|
|
} file_archive_transfer_t;
|
|
|
|
|
|
|
|
enum file_archive_compression_mode
|
|
|
|
{
|
|
|
|
ARCHIVE_MODE_UNCOMPRESSED = 0,
|
|
|
|
ARCHIVE_MODE_COMPRESSED = 8
|
|
|
|
};
|
|
|
|
|
2016-09-18 15:20:27 -04:00
|
|
|
struct decomp_state_t
|
|
|
|
{
|
|
|
|
char *opt_file;
|
|
|
|
char *needle;
|
|
|
|
void **buf;
|
|
|
|
size_t size;
|
|
|
|
bool found;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *source_file;
|
|
|
|
char *subdir;
|
|
|
|
char *target_dir;
|
|
|
|
char *target_file;
|
|
|
|
char *valid_ext;
|
|
|
|
|
|
|
|
char *callback_error;
|
|
|
|
|
|
|
|
file_archive_transfer_t archive;
|
|
|
|
} decompress_state_t;
|
|
|
|
|
2016-09-18 00:38:59 -04:00
|
|
|
struct archive_extract_userdata
|
|
|
|
{
|
|
|
|
char *archive_path;
|
|
|
|
char *first_extracted_file_path;
|
2016-09-18 21:04:05 -04:00
|
|
|
char *extracted_file_path;
|
2016-09-18 00:38:59 -04:00
|
|
|
const char *extraction_directory;
|
|
|
|
size_t archive_path_size;
|
|
|
|
struct string_list *ext;
|
|
|
|
struct string_list *list;
|
|
|
|
bool found_file;
|
2016-09-18 21:04:05 -04:00
|
|
|
bool list_only;
|
2016-09-18 00:38:59 -04:00
|
|
|
void *context;
|
2016-09-18 15:20:27 -04:00
|
|
|
char archive_name[PATH_MAX_LENGTH];
|
|
|
|
uint32_t crc;
|
|
|
|
struct decomp_state_t decomp_state;
|
2016-09-18 16:05:33 -04:00
|
|
|
decompress_state_t *dec;
|
2016-09-18 00:38:59 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Returns true when parsing should continue. False to stop. */
|
|
|
|
typedef int (*file_archive_file_cb)(const char *name, const char *valid_exts,
|
|
|
|
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
2016-09-18 15:20:27 -04:00
|
|
|
uint32_t crc32, struct archive_extract_userdata *userdata);
|
2016-09-18 00:38:59 -04:00
|
|
|
|
2016-01-24 22:17:11 +01:00
|
|
|
struct file_archive_file_backend
|
2016-01-24 19:57:31 +01:00
|
|
|
{
|
|
|
|
void *(*stream_new)(void);
|
2016-01-24 20:01:35 +01:00
|
|
|
void (*stream_free)(void *);
|
2016-01-24 21:06:53 +01:00
|
|
|
void (*stream_set)(void *, uint32_t, uint32_t,
|
|
|
|
const uint8_t *, uint8_t *);
|
2016-01-24 20:08:57 +01:00
|
|
|
uint32_t (*stream_get_avail_in)(void*);
|
|
|
|
uint32_t (*stream_get_avail_out)(void*);
|
|
|
|
uint64_t (*stream_get_total_out)(void*);
|
|
|
|
void (*stream_decrement_total_out)(void *, unsigned);
|
2016-01-24 20:18:52 +01:00
|
|
|
bool (*stream_decompress_init)(void *);
|
2016-01-24 21:23:33 +01:00
|
|
|
bool (*stream_decompress_data_to_file_init)(
|
2016-01-24 22:17:11 +01:00
|
|
|
file_archive_file_handle_t *, const uint8_t *, uint32_t, uint32_t);
|
2016-01-24 21:26:02 +01:00
|
|
|
int (*stream_decompress_data_to_file_iterate)(void *);
|
|
|
|
void (*stream_compress_init)(void *, int);
|
2016-01-24 20:12:12 +01:00
|
|
|
void (*stream_compress_free)(void *);
|
2016-01-24 20:15:17 +01:00
|
|
|
int (*stream_compress_data_to_file)(void *);
|
2016-01-24 21:50:28 +01:00
|
|
|
uint32_t (*stream_crc_calculate)(uint32_t, const uint8_t *, size_t);
|
2016-09-18 00:38:59 -04:00
|
|
|
int (*compressed_file_read)(const char *path, const char *needle, void **buf,
|
|
|
|
const char *optional_outfile);
|
|
|
|
int (*archive_parse_file_init)(
|
|
|
|
file_archive_transfer_t *state,
|
|
|
|
const char *file);
|
|
|
|
int (*archive_parse_file_iterate_step)(
|
|
|
|
file_archive_transfer_t *state,
|
|
|
|
const char *valid_exts,
|
2016-09-18 15:20:27 -04:00
|
|
|
struct archive_extract_userdata *userdata,
|
2016-09-18 00:38:59 -04:00
|
|
|
file_archive_file_cb file_cb);
|
2016-01-24 19:57:31 +01:00
|
|
|
const char *ident;
|
|
|
|
};
|
|
|
|
|
2016-01-24 18:53:37 +01:00
|
|
|
int file_archive_parse_file_iterate(
|
2016-01-24 22:17:11 +01:00
|
|
|
file_archive_transfer_t *state,
|
2016-01-24 18:53:37 +01:00
|
|
|
bool *returnerr,
|
2015-05-27 01:03:49 +02:00
|
|
|
const char *file,
|
2016-01-24 18:53:37 +01:00
|
|
|
const char *valid_exts,
|
|
|
|
file_archive_file_cb file_cb,
|
2016-09-18 15:20:27 -04:00
|
|
|
struct archive_extract_userdata *userdata);
|
2015-05-27 01:03:49 +02:00
|
|
|
|
2016-01-24 22:17:11 +01:00
|
|
|
void file_archive_parse_file_iterate_stop(file_archive_transfer_t *state);
|
2015-07-05 10:23:21 -03:00
|
|
|
|
2016-01-24 22:17:11 +01:00
|
|
|
int file_archive_parse_file_progress(file_archive_transfer_t *state);
|
2015-11-30 10:41:35 -03:00
|
|
|
|
2015-01-09 15:46:22 +01:00
|
|
|
/**
|
2016-09-18 21:04:05 -04:00
|
|
|
* file_archive_extract_file:
|
2016-09-19 18:38:33 -04:00
|
|
|
* @archive_path : filename path to ZIP archive.
|
|
|
|
* @archive_path_size : size of ZIP archive.
|
2016-09-18 00:38:59 -04:00
|
|
|
* @valid_exts : valid extensions for a file.
|
2016-09-19 18:38:33 -04:00
|
|
|
* @extraction_directory : the directory to extract the temporary
|
|
|
|
* file to.
|
2015-01-09 15:46:22 +01:00
|
|
|
*
|
2016-09-18 21:04:05 -04:00
|
|
|
* Extract file from archive. If no file inside the archive is
|
|
|
|
* specified, the first file found will be used.
|
2015-01-09 15:46:22 +01:00
|
|
|
*
|
|
|
|
* Returns : true (1) on success, otherwise false (0).
|
|
|
|
**/
|
2016-09-19 18:38:33 -04:00
|
|
|
bool file_archive_extract_file(char *archive_path, size_t archive_path_size,
|
2016-01-24 05:41:41 +01:00
|
|
|
const char *valid_exts, const char *extraction_dir,
|
|
|
|
char *out_path, size_t len);
|
2014-09-07 05:47:18 +02:00
|
|
|
|
2015-01-09 15:46:22 +01:00
|
|
|
/**
|
2016-01-24 07:42:46 +01:00
|
|
|
* file_archive_get_file_list:
|
2015-01-09 15:46:22 +01:00
|
|
|
* @path : filename path of archive
|
2016-09-18 00:38:59 -04:00
|
|
|
* @valid_exts : Valid extensions of archive to be parsed.
|
2015-01-30 20:41:54 +01:00
|
|
|
* If NULL, allow all.
|
2015-01-09 15:46:22 +01:00
|
|
|
*
|
|
|
|
* Returns: string listing of files from archive on success, otherwise NULL.
|
|
|
|
**/
|
2016-09-18 00:38:59 -04:00
|
|
|
struct string_list* file_archive_get_file_list(const char *path, const char *valid_exts);
|
2013-01-21 23:51:56 +01:00
|
|
|
|
2016-01-24 07:42:46 +01:00
|
|
|
bool file_archive_perform_mode(const char *name, const char *valid_exts,
|
2015-03-28 21:05:00 +01:00
|
|
|
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
2016-09-18 15:20:27 -04:00
|
|
|
uint32_t crc32, struct archive_extract_userdata *userdata);
|
2015-03-28 21:05:00 +01:00
|
|
|
|
2016-01-24 22:17:11 +01:00
|
|
|
void file_archive_deflate_init(void *data, int level);
|
2015-03-29 16:28:06 +02:00
|
|
|
|
2016-09-18 00:38:59 -04:00
|
|
|
int file_archive_compressed_read(
|
|
|
|
const char* path, void **buf,
|
|
|
|
const char* optional_filename, ssize_t *length);
|
|
|
|
|
|
|
|
struct string_list* file_archive_file_list_new(const char *path,
|
|
|
|
const char *ext);
|
|
|
|
|
|
|
|
struct string_list* file_archive_filename_split(const char *path);
|
|
|
|
|
2016-09-19 12:06:07 -04:00
|
|
|
const uint8_t* file_archive_data(file_archive_file_data_t *data);
|
2016-09-18 00:38:59 -04:00
|
|
|
|
|
|
|
int file_archive_parse_file_init(file_archive_transfer_t *state,
|
|
|
|
const char *file);
|
|
|
|
|
2016-09-19 12:06:07 -04:00
|
|
|
void file_archive_free(file_archive_file_data_t *data);
|
2016-09-18 00:38:59 -04:00
|
|
|
|
|
|
|
const struct file_archive_file_backend* file_archive_get_zlib_file_backend(void);
|
|
|
|
const struct file_archive_file_backend* file_archive_get_7z_file_backend(void);
|
|
|
|
|
|
|
|
const struct file_archive_file_backend* file_archive_get_file_backend(const char *path);
|
2016-01-24 19:48:25 +01:00
|
|
|
|
2016-01-26 05:59:52 +01:00
|
|
|
extern const struct file_archive_file_backend zlib_backend;
|
2016-09-18 00:38:59 -04:00
|
|
|
extern const struct file_archive_file_backend sevenzip_backend;
|
2016-01-24 06:18:39 +01:00
|
|
|
|
2013-01-21 23:51:56 +01:00
|
|
|
#endif
|
|
|
|
|