122 lines
4.6 KiB
C
Raw Normal View History

/* Copyright (C) 2010-2015 The RetroArch team
2013-01-21 23:51:56 +01:00
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (file_extract.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
*/
#ifndef FILE_EXTRACT_H__
#define FILE_EXTRACT_H__
#include <boolean.h>
2013-01-21 23:51:56 +01:00
#include <stddef.h>
#include <stdint.h>
2013-01-21 23:51:56 +01:00
2015-03-28 18:30:09 +01:00
typedef struct zlib_handle
{
void *stream;
uint8_t *data;
uint32_t real_checksum;
} zlib_file_handle_t;
2014-09-07 05:47:18 +02:00
/* Returns true when parsing should continue. False to stop. */
typedef int (*zlib_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);
uint32_t zlib_crc32_calculate(const uint8_t *data, size_t length);
uint32_t zlib_crc32_adjust(uint32_t crc, uint8_t data);
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).
**/
bool zlib_parse_file(const char *file, const char *valid_exts,
zlib_file_cb file_cb, void *userdata);
2015-01-09 15:46:22 +01:00
/**
* zlib_extract_first_content_file:
* @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).
**/
2014-09-07 05:47:18 +02:00
bool zlib_extract_first_content_file(char *zip_path, size_t zip_path_size,
const char *valid_exts, const char *extraction_dir);
2015-01-09 15:46:22 +01:00
/**
* zlib_get_file_list:
* @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.
**/
struct string_list *zlib_get_file_list(const char *path, const char *valid_exts);
2013-01-21 23:51:56 +01:00
bool zlib_inflate_data_to_file_init(
zlib_file_handle_t *handle,
const uint8_t *cdata, uint32_t csize, uint32_t size);
int zlib_inflate_data_to_file_iterate(void *data);
2015-01-09 15:46:22 +01:00
/**
* zlib_inflate_data_to_file:
* @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).
**/
int zlib_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
2015-03-28 21:05:00 +01:00
bool zlib_perform_mode(const char *name, const char *valid_exts,
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_new(void);
void zlib_stream_free(void *data);
2013-01-21 23:51:56 +01:00
#endif