From 92815950242057c6e91f9a15ce50c2a1c0416235 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 28 Mar 2015 21:05:00 +0100 Subject: [PATCH] Create zlib_perform_mode --- android/phoenix/jni/Android.mk | 2 +- android/phoenix/jni/apk-extract/apk-extract.c | 37 ++++--------------- libretro-common/file/file_extract.c | 34 +++++++++++++++++ libretro-common/include/file/file_extract.h | 4 ++ 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/android/phoenix/jni/Android.mk b/android/phoenix/jni/Android.mk index 780bac2599..c4465faefd 100644 --- a/android/phoenix/jni/Android.mk +++ b/android/phoenix/jni/Android.mk @@ -5,7 +5,7 @@ LOCAL_MODULE := retroarch-jni RARCH_DIR := ../../.. LOCAL_CFLAGS += -std=gnu99 -Wall -DHAVE_LOGGER -DRARCH_DUMMY_LOG -DHAVE_ZLIB -DHAVE_MMAP -DRARCH_INTERNAL LOCAL_LDLIBS := -llog -lz -LOCAL_SRC_FILES := apk-extract/apk-extract.c $(RARCH_DIR)/file_extract.c $(RARCH_DIR)/libretro-common/file/file_path.c $(RARCH_DIR)/file_ops.c $(RARCH_DIR)/libretro-common/string/string_list.c $(RARCH_DIR)/libretro-common/compat/compat.c +LOCAL_SRC_FILES := apk-extract/apk-extract.c $(RARCH_DIR)/libretro-common/file/file_extract.c $(RARCH_DIR)/libretro-common/file/file_path.c $(RARCH_DIR)/file_ops.c $(RARCH_DIR)/libretro-common/string/string_list.c $(RARCH_DIR)/libretro-common/compat/compat.c LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(RARCH_DIR)/libretro-common/include/ diff --git a/android/phoenix/jni/apk-extract/apk-extract.c b/android/phoenix/jni/apk-extract/apk-extract.c index eb8684cae9..630176b9cb 100644 --- a/android/phoenix/jni/apk-extract/apk-extract.c +++ b/android/phoenix/jni/apk-extract/apk-extract.c @@ -1,5 +1,4 @@ -#include "../../../../file_extract.h" -#include "../../../../file_ops.h" +#include #include #include @@ -47,35 +46,15 @@ static int zlib_cb(const char *name, const char *valid_exts, RARCH_LOG("Extracting %s -> %s ...\n", name, path); - switch (cmode) + if (!zlib_perform_mode(path, valid_exts, + cdata, cmode, csize, size, crc32, userdata)) { - case 0: /* Uncompressed */ - if (!write_file(path, cdata, size)) - { - RARCH_ERR("Failed to write file: %s.\n", path); - return 0; - } - break; - - case 8: /* Deflate */ - { - int ret = 0; - zlib_file_handle_t handle = {0}; - if (!zlib_inflate_data_to_file_init(&handle, cdata, csize, size)) - goto error; - - do{ - ret = zlib_inflate_data_to_file_iterate(handle.stream); - }while(ret == 0); - - if (!zlib_inflate_data_to_file(&handle, ret, path, valid_exts, - cdata, csize, size, crc32)) - goto error; - } - break; - - default: + if (cmode == 0) + { + RARCH_ERR("Failed to write file: %s.\n", path); return 0; + } + goto error; } return 1; diff --git a/libretro-common/file/file_extract.c b/libretro-common/file/file_extract.c index 6c00288826..99287ae26a 100644 --- a/libretro-common/file/file_extract.c +++ b/libretro-common/file/file_extract.c @@ -727,3 +727,37 @@ struct string_list *zlib_get_file_list(const char *path, const char *valid_exts) return list; } + +bool zlib_perform_mode(const char *path, const char *valid_exts, + const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size, + uint32_t crc32, void *userdata) +{ + switch (cmode) + { + case 0: /* Uncompressed */ + if (!zlib_write_file(path, cdata, size)) + return false; + break; + + case 8: /* Deflate */ + { + int ret = 0; + zlib_file_handle_t handle = {0}; + if (!zlib_inflate_data_to_file_init(&handle, cdata, csize, size)) + return false; + + do{ + ret = zlib_inflate_data_to_file_iterate(handle.stream); + }while(ret == 0); + + if (!zlib_inflate_data_to_file(&handle, ret, path, valid_exts, + cdata, csize, size, crc32)) + return false; + } + break; + default: + return false; + } + + return true; +} diff --git a/libretro-common/include/file/file_extract.h b/libretro-common/include/file/file_extract.h index cb15113df9..e305c9da28 100644 --- a/libretro-common/include/file/file_extract.h +++ b/libretro-common/include/file/file_extract.h @@ -106,6 +106,10 @@ 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); +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);