190 lines
6.2 KiB
C
Raw Normal View History

/* Copyright (C) 2010-2015 The RetroArch team
2013-01-21 23:51:56 +01:00
*
* ---------------------------------------------------------------------------------------
2016-01-24 07:29:11 +01:00
* The following license statement only applies to this file (file_archive.h).
* ---------------------------------------------------------------------------------------
2013-01-21 23:51:56 +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-01-24 07:29:11 +01:00
#ifndef FILE_ARCHIVE_H__
#define FILE_ARCHIVE_H__
2013-01-21 23:51:56 +01: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
enum zlib_transfer_type
{
ZLIB_TRANSFER_NONE = 0,
ZLIB_TRANSFER_INIT,
ZLIB_TRANSFER_ITERATE,
ZLIB_TRANSFER_DEINIT,
2015-06-26 18:35:35 +02:00
ZLIB_TRANSFER_DEINIT_ERROR
};
struct zlib_file_backend
{
void *(*stream_new)(void);
const char *ident;
};
typedef struct zlib_transfer
{
void *handle;
const uint8_t *footer;
const uint8_t *directory;
const uint8_t *data;
int32_t zip_size;
enum zlib_transfer_type type;
const struct zlib_file_backend *backend;
} zlib_transfer_t;
typedef struct zlib_handle
{
void *stream;
uint8_t *data;
uint32_t real_checksum;
const struct zlib_file_backend *backend;
} zlib_file_handle_t;
2014-09-07 05:47:18 +02:00
/* Returns true when parsing should continue. False to stop. */
2016-01-24 07:42:46 +01:00
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,
uint32_t crc32, void *userdata);
2016-01-24 07:42:46 +01:00
uint32_t file_archive_crc32_calculate(uint32_t crc, const uint8_t *data, size_t length);
2015-01-09 15:46:22 +01:00
/**
* zlib_parse_file:
* @file : filename path of archive
* @valid_exts : Valid extensions of archive to be parsed.
* If NULL, allow all.
2015-01-09 15:46:22 +01:00
* @file_cb : file_cb function pointer
* @userdata : userdata to pass to file_cb function pointer.
*
* Low-level file parsing. Enumerates over all files and calls
* file_cb with userdata.
*
* Returns: true (1) on success, otherwise false (0).
**/
2016-01-24 07:42:46 +01:00
bool file_archive_parse_file(const char *file, const char *valid_exts,
file_archive_file_cb file_cb, void *userdata);
int file_archive_parse_file_iterate(
zlib_transfer_t *state,
bool *returnerr,
2015-05-27 01:03:49 +02:00
const char *file,
const char *valid_exts,
file_archive_file_cb file_cb,
void *userdata);
2015-05-27 01:03:49 +02:00
void file_archive_parse_file_iterate_stop(zlib_transfer_t *state);
int file_archive_parse_file_progress(zlib_transfer_t *state);
2015-01-09 15:46:22 +01:00
/**
2016-01-24 07:42:46 +01:00
* file_archive_extract_first_content_file:
2015-01-09 15:46:22 +01:00
* @zip_path : filename path to ZIP archive.
* @zip_path_size : size of ZIP archive.
* @valid_exts : valid extensions for a content file.
* @extraction_directory : the directory to extract temporary
* unzipped content to.
*
* Extract first content file from archive.
*
* Returns : true (1) on success, otherwise false (0).
**/
2016-01-24 07:42:46 +01:00
bool file_archive_extract_first_content_file(char *zip_path, size_t zip_path_size,
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
* @valid_exts : Valid extensions of archive to be parsed.
* If NULL, allow all.
2015-01-09 15:46:22 +01:00
*
* Returns: string listing of files from archive on success, otherwise NULL.
**/
2016-01-24 07:42:46 +01: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_inflate_data_to_file_init(
zlib_file_handle_t *handle,
const uint8_t *cdata, uint32_t csize, uint32_t size);
2016-01-24 07:42:46 +01:00
int file_archive_inflate_data_to_file_iterate(void *data);
2015-01-09 15:46:22 +01:00
/**
2016-01-24 07:42:46 +01:00
* file_archive_inflate_data_to_file:
2015-01-09 15:46:22 +01:00
* @path : filename path of archive.
* @cdata : input data.
* @csize : size of input data.
* @size : output file size
* @checksum : CRC32 checksum from input data.
*
* Decompress data to file.
*
* Returns: true (1) on success, otherwise false (0).
**/
2016-01-24 07:42:46 +01:00
int file_archive_inflate_data_to_file(zlib_file_handle_t *handle,
int ret, const char *path, const char *valid_exts,
const uint8_t *cdata, uint32_t csize, uint32_t size, uint32_t checksum);
2013-10-14 18:10:17 +02: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,
uint32_t crc32, void *userdata);
struct string_list *compressed_file_list_new(const char *filename,
const char* ext);
void zlib_stream_free(void *data);
2015-03-29 16:28:06 +02:00
void zlib_deflate_init(void *data, int level);
int zlib_deflate_data_to_file(void *data);
void zlib_stream_deflate_free(void *data);
2016-01-24 07:42:46 +01:00
bool file_archive_inflate_init(void *data);
2015-03-29 14:30:53 +02:00
2015-03-29 15:35:55 +02:00
void zlib_set_stream(void *data,
uint32_t avail_in,
uint32_t avail_out,
const uint8_t *next_in,
uint8_t *next_out
);
2015-03-29 15:52:17 +02:00
uint32_t zlib_stream_get_avail_in(void *data);
uint32_t zlib_stream_get_avail_out(void *data);
uint64_t zlib_stream_get_total_out(void *data);
void zlib_stream_decrement_total_out(void *data,
unsigned subtraction);
const struct zlib_file_backend *file_archive_get_default_file_backend(void);
const struct zlib_file_backend zlib_backend;
2013-01-21 23:51:56 +01:00
#endif