Merge tag 'android-11.0.0_r16' into android-10.0

Android 11.0.0 release 16 - twrp bringup patch
diff --git a/gui/Android.bp b/gui/Android.bp
new file mode 100644
index 0000000..94d429b
--- /dev/null
+++ b/gui/Android.bp
@@ -0,0 +1,83 @@
+bootstrap_go_package {

+    name: "soong-libguitwrp_defaults",

+    pkgPath: "bootable/recovery/gui",

+    deps: [

+        "soong",

+        "soong-android",

+        "soong-cc"

+    ],

+    srcs: [

+        "libguitwrp_defaults.go"

+    ],

+    pluginFor: ["soong_build"]

+}

+

+libguitwrp_defaults {

+    name: "libguitwrp_defaults"

+}

+

+cc_library_static {

+    name: "libguitwrp",

+    defaults: ["libguitwrp_defaults"],

+    cflags: [

+        "-fno-strict-aliasing", 

+        "-Wno-implicit-fallthrough",

+        "-D_USE_SYSTEM_ZIPARCHIVE"

+    ],

+    include_dirs: [

+        "bootable/recovery/crypto/scrypt/lib/util",

+        "bootable/recovery/otautil/include",

+        "bootable/recovery/install/include",

+        "system/core/libziparchive/include",

+        "bootable/recovery/recovery_ui/include",

+        "bootable/recovery/fuse_sideload/include",

+        "bootable/recovery/twrpinstall",

+        "bootable/recovery/twrpinstall/include",

+        "bionic",

+        "system/core/base/include",

+        "system/core/include",

+        "system/core/libpixelflinger/include",

+        "external/freetype/include"

+

+    ],

+    srcs: [ 

+        "gui.cpp",

+        "resources.cpp",

+        "pages.cpp",

+        "text.cpp",

+        "image.cpp",

+        "action.cpp",

+        "console.cpp",

+        "fill.cpp",

+        "button.cpp",

+        "checkbox.cpp",

+        "fileselector.cpp",

+        "progressbar.cpp",

+        "animation.cpp",

+        "object.cpp",

+        "slider.cpp",

+        "slidervalue.cpp",

+        "listbox.cpp",

+        "keyboard.cpp",

+        "input.cpp",

+        "blanktimer.cpp",

+        "partitionlist.cpp",

+        "mousecursor.cpp",

+        "scrolllist.cpp",

+        "patternpassword.cpp",

+        "textbox.cpp",

+        "terminal.cpp",

+        "twmsg.cpp"

+    ],

+    shared_libs: [

+        "libminuitwrp",

+        "libc",

+        "libstdc++",

+        "libaosprecovery",

+        "libselinux",

+        "libziparchive"

+    ],

+    static_libs: [

+        "libotautil"

+    ]

+}
\ No newline at end of file
diff --git a/gui/Android.mk b/gui/Android.mk
index b49b94d..450748d 100755
--- a/gui/Android.mk
+++ b/gui/Android.mk
@@ -1,140 +1,10 @@
 LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_CFLAGS := -fno-strict-aliasing -Wno-implicit-fallthrough
-
-LOCAL_SRC_FILES := \
-    gui.cpp \
-    resources.cpp \
-    pages.cpp \
-    text.cpp \
-    image.cpp \
-    action.cpp \
-    console.cpp \
-    fill.cpp \
-    button.cpp \
-    checkbox.cpp \
-    fileselector.cpp \
-    progressbar.cpp \
-    animation.cpp \
-    object.cpp \
-    slider.cpp \
-    slidervalue.cpp \
-    listbox.cpp \
-    keyboard.cpp \
-    input.cpp \
-    blanktimer.cpp \
-    partitionlist.cpp \
-    mousecursor.cpp \
-    scrolllist.cpp \
-    patternpassword.cpp \
-    textbox.cpp \
-    terminal.cpp \
-    twmsg.cpp
-
-ifneq ($(TW_DELAY_TOUCH_INIT_MS),)
-    LOCAL_CFLAGS += -DTW_DELAY_TOUCH_INIT_MS=$(TW_DELAY_TOUCH_INIT_MS)
-endif
-
-ifneq ($(TWRP_CUSTOM_KEYBOARD),)
-    LOCAL_SRC_FILES += $(TWRP_CUSTOM_KEYBOARD)
-else
-    LOCAL_SRC_FILES += hardwarekeyboard.cpp
-endif
-
-LOCAL_SHARED_LIBRARIES += libminuitwrp libc libstdc++ libaosprecovery libselinux
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/../otautil/include
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/../twrpinstall/include
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 26; echo $$?),0)
-    LOCAL_SHARED_LIBRARIES += libziparchive
-    LOCAL_STATIC_LIBRARIES += libotautil libtwrpinstall
-    ifneq ($(TW_INCLUDE_CRYPTO),)
-        LOCAL_C_INCLUDES += bootable/recovery/crypto/fscrypt
-    endif
-    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 28; echo $$?),0)
-        LOCAL_C_INCLUDES += $(LOCAL_PATH)/../install/include \
-            system/core/libziparchive/include/ \
-            $(LOCAL_PATH)/../recovery_ui/include \
-            $(LOCAL_PATH)/../fuse_sideload/include
-        LOCAL_CFLAGS += -D_USE_SYSTEM_ZIPARCHIVE
-    else
-        LOCAL_C_INCLUDES += $(LOCAL_PATH)/../install28/ \
-            $(LOCAL_PATH)/../fuse_sideload28/
-        LOCAL_CFLAGS += -DUSE_28_INSTALL -DUSE_OTAUTIL_ZIPARCHIVE
-    endif
-else
-    LOCAL_SHARED_LIBRARIES += libminzip
-    LOCAL_CFLAGS += -DUSE_MINZIP
-endif
-ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)
-    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -le 28; echo $$?),0)
-        LOCAL_C_INCLUDES += system/extras/ext4_utils \
-            system/extras/ext4_utils/include \
-            $(LOCAL_PATH)/../crypto/ext4crypt
-        LOCAL_SHARED_LIBRARIES += libext4_utils
-    endif
-endif
-
-LOCAL_MODULE := libguitwrp
-
-#TWRP_EVENT_LOGGING := true
-ifeq ($(TWRP_EVENT_LOGGING), true)
-    LOCAL_CFLAGS += -D_EVENT_LOGGING
-endif
-ifneq ($(TW_USE_KEY_CODE_TOUCH_SYNC),)
-    LOCAL_CFLAGS += -DTW_USE_KEY_CODE_TOUCH_SYNC=$(TW_USE_KEY_CODE_TOUCH_SYNC)
-endif
-ifneq ($(TW_OZIP_DECRYPT_KEY),)
-    LOCAL_CFLAGS += -DTW_OZIP_DECRYPT_KEY=\"$(TW_OZIP_DECRYPT_KEY)\"
-else
-    LOCAL_CFLAGS += -DTW_OZIP_DECRYPT_KEY=0
-endif
-ifneq ($(TW_NO_SCREEN_BLANK),)
-    LOCAL_CFLAGS += -DTW_NO_SCREEN_BLANK
-endif
-ifneq ($(TW_NO_SCREEN_TIMEOUT),)
-    LOCAL_CFLAGS += -DTW_NO_SCREEN_TIMEOUT
-endif
-ifeq ($(TW_OEM_BUILD), true)
-    LOCAL_CFLAGS += -DTW_OEM_BUILD
-endif
-ifneq ($(TW_X_OFFSET),)
-    LOCAL_CFLAGS += -DTW_X_OFFSET=$(TW_X_OFFSET)
-endif
-ifneq ($(TW_Y_OFFSET),)
-    LOCAL_CFLAGS += -DTW_Y_OFFSET=$(TW_Y_OFFSET)
-endif
-ifneq ($(TW_W_OFFSET),)
-    LOCAL_CFLAGS += -DTW_W_OFFSET=$(TW_W_OFFSET)
-endif
-ifneq ($(TW_H_OFFSET),)
-    LOCAL_CFLAGS += -DTW_H_OFFSET=$(TW_H_OFFSET)
-endif
-ifeq ($(TW_ROUND_SCREEN), true)
-    LOCAL_CFLAGS += -DTW_ROUND_SCREEN
-endif
-
-LOCAL_C_INCLUDES += \
-    bionic \
-    system/core/base/include \
-    system/core/include \
-    system/core/libpixelflinger/include \
-    external/freetype/include
-
-ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
-    LOCAL_C_INCLUDES += external/stlport/stlport
-    LOCAL_CFLAGS += -DUSE_FUSE_SIDELOAD22
-endif
-
-LOCAL_CFLAGS += -DTWRES=\"$(TWRES_PATH)\"
-
-include $(BUILD_STATIC_LIBRARY)
 
 # Transfer in the resources for the device
 include $(CLEAR_VARS)
 LOCAL_MODULE := twrp
 LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
+LOCAL_MODULE_CLASS := DATA
 LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)$(TWRES_PATH)
 
 # The extra blank line before *** is intentional to ensure it ends up on its own line
@@ -228,5 +98,7 @@
 	cp -fr $(TWRP_THEME_LOC)/* $(TARGET_RECOVERY_ROOT_OUT)$(TWRES_PATH)
 
 LOCAL_GENERATED_SOURCES := $(TWRP_RES_GEN)
-LOCAL_SRC_FILES := twrp $(TWRP_RES_GEN)
+#LOCAL_SRC_FILES := twrp
+LOCAL_SRC_FILES := $(TWRP_RES_GEN)
+$(warning LOCAL_SRC_FILES: $(LOCAL_SRC_FILES))
 include $(BUILD_PREBUILT)
diff --git a/gui/action.cpp b/gui/action.cpp
index b0f0027..597bb61 100755
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -52,7 +52,7 @@
 #include "../twcommon.h"
 #include "../variables.h"
 #include "cutils/properties.h"
-#include "install/adb_install.h"
+#include "twinstall/adb_install.h"
 };
 #include "set_metadata.h"
 #include "../minuitwrp/minui.h"
diff --git a/gui/libguitwrp_defaults.go b/gui/libguitwrp_defaults.go
new file mode 100644
index 0000000..8abec95
--- /dev/null
+++ b/gui/libguitwrp_defaults.go
@@ -0,0 +1,118 @@
+package libgui_defaults

+

+import (

+	"android/soong/android"

+	"android/soong/cc"

+)

+

+func globalFlags(ctx android.BaseContext) []string {

+	var cflags []string

+

+	if ctx.AConfig().Getenv("TW_DELAY_TOUCH_INIT_MS") != "" {

+		cflags = append(cflags, "-DTW_DELAY_TOUCH_INIT_MS="+ctx.AConfig().Getenv("TW_DELAY_TOUCH_INIT_MS"))

+	}

+

+	if ctx.AConfig().Getenv("TW_EVENT_LOGGING") == "true" {

+		cflags = append(cflags, "-D_EVENT_LOGGING")

+	}

+

+	if ctx.AConfig().Getenv("TW_USE_KEY_CODE_TOUCH_SYNC") != "" {

+		cflags = append(cflags, "DTW_USE_KEY_CODE_TOUCH_SYNC="+ctx.AConfig().Getenv("TW_USE_KEY_CODE_TOUCH_SYNC"))

+	}

+

+	if ctx.AConfig().Getenv("TW_OZIP_DECRYPT_KEY") != "" {

+		cflags = append(cflags, "-DTW_OZIP_DECRYPT_KEY=\""+ctx.AConfig().Getenv("TW_OZIP_DECRYPT_KEY")+"\"")

+	} else {

+		cflags = append(cflags, "-DTW_OZIP_DECRYPT_KEY=0")

+	}

+

+	if ctx.AConfig().Getenv("TW_NO_SCREEN_BLANK") != "" {

+		cflags = append(cflags, "-DTW_NO_SCREEN_BLANK")

+	}

+

+	if ctx.AConfig().Getenv("TW_NO_SCREEN_TIMEOUT") != "" {

+		cflags = append(cflags, "-DTW_NO_SCREEN_TIMEOUT")

+	}

+

+	if ctx.AConfig().Getenv("TW_OEM_BUILD") != "" {

+		cflags = append(cflags, "-DTW_OEM_BUILD")

+	}

+

+	if ctx.AConfig().Getenv("TW_X_OFFSET") != "" {

+		cflags = append(cflags, "-DTW_X_OFFSET="+ctx.AConfig().Getenv("TW_X_OFFSET"))

+	}

+

+	if ctx.AConfig().Getenv("TW_Y_OFFSET") != "" {

+		cflags = append(cflags, "-DTW_Y_OFFSET="+ctx.AConfig().Getenv("TW_Y_OFFSET"))

+	}

+

+	if ctx.AConfig().Getenv("TW_W_OFFSET") != "" {

+		cflags = append(cflags, "-DTW_W_OFFSET="+ctx.AConfig().Getenv("TW_W_OFFSET"))

+	}

+

+	if ctx.AConfig().Getenv("TW_H_OFFSET") != "" {

+		cflags = append(cflags, "-DTW_H_OFFSET="+ctx.AConfig().Getenv("TW_H_OFFSET"))

+	}

+

+	if ctx.AConfig().Getenv("TW_ROUND_SCREEN") == "true" {

+		cflags = append(cflags, "-DTW_ROUND_SCREEN")

+	}

+

+	cflags = append(cflags, "-DTWRES=\""+ctx.AConfig().Getenv("TWRES_PATH")+"\"")

+

+	return cflags

+}

+

+func globalSrcs(ctx android.BaseContext) []string {

+	var srcs []string

+

+	if ctx.AConfig().Getenv("TWRP_CUSTOM_KEYBOARD") != "" {

+		srcs = append(srcs, ctx.AConfig().Getenv("TWRP_CUSTOM_KEYBOARD"))

+	} else {

+		srcs = append(srcs, "hardwarekeyboard.cpp")

+	}

+	return srcs

+}

+

+func globalIncludes(ctx android.BaseContext) []string {

+	var includes []string

+

+	if ctx.AConfig().Getenv("TW_INCLUDE_CRYPTO") != "" {

+		includes = append(includes, "bootable/recovery/crypto/fscrypt")

+	}

+

+	return includes

+}

+

+func libGuiDefaults(ctx android.LoadHookContext) {

+	type props struct {

+		Target struct {

+			Android struct {

+				Cflags  []string

+				Enabled *bool

+			}

+		}

+		Cflags       []string

+		Srcs         []string

+		Include_dirs []string

+	}

+

+	p := &props{}

+	p.Cflags = globalFlags(ctx)

+	s := globalSrcs(ctx)

+	p.Srcs = s

+	i := globalIncludes(ctx)

+	p.Include_dirs = i

+	ctx.AppendProperties(p)

+}

+

+func init() {

+	android.RegisterModuleType("libguitwrp_defaults", libGuiDefaultsFactory)

+}

+

+func libGuiDefaultsFactory() android.Module {

+	module := cc.DefaultsFactory()

+	android.AddLoadHook(module, libGuiDefaults)

+

+	return module

+}

diff --git a/gui/pages.cpp b/gui/pages.cpp
index a3047bb..c274c4b 100755
--- a/gui/pages.cpp
+++ b/gui/pages.cpp
@@ -39,21 +39,14 @@
 #include <string>
 #include <algorithm>
 
-#ifdef USE_MINZIP
-#include "../minzip/SysUtil.h"
-#else
-#ifdef USE_OTAUTIL_ZIPARCHIVE
-#include <otautil/SysUtil.h>
-#else
+
 #include <ziparchive/zip_archive.h>
-#endif
-#endif
+#include "ZipUtil.h"
 
 extern "C" {
 #include "../twcommon.h"
 #include "gui.h"
 }
-#include "zipwrap.hpp"
 #include "../minuitwrp/minui.h"
 
 #include "rapidxml.hpp"
@@ -674,7 +667,7 @@
 // transient data for loading themes
 struct LoadingContext
 {
-	ZipWrap* zip; // zip to load theme from, or NULL for the stock theme
+	ZipArchiveHandle zip; // zip to load theme from, or NULL for the stock theme
 	std::set<std::string> filenames; // to detect cyclic includes
 	std::string basepath; // if zip is NULL, base path to load includes from with trailing slash, otherwise empty
 	std::vector<xml_document<>*> xmldocs; // all loaded xml docs
@@ -816,7 +809,7 @@
 	}
 }
 
-int PageSet::LoadLanguage(char* languageFile, ZipWrap* package)
+int PageSet::LoadLanguage(char* languageFile, ZipArchiveHandle package)
 {
 	xml_document<> lang;
 	xml_node<>* parent;
@@ -1192,11 +1185,11 @@
 	mResources->AddStringResource(resource_source, resource_name, value);
 }
 
-char* PageManager::LoadFileToBuffer(std::string filename, ZipWrap* package) {
+char* PageManager::LoadFileToBuffer(std::string filename, ZipArchiveHandle package) {
 	size_t len;
 	char* buffer = NULL;
 
-	if (!package) {
+	if (package) {
 		// We can try to load the XML directly...
 		LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' directly\n", filename.c_str());
 		struct stat st;
@@ -1229,18 +1222,24 @@
 		close(fd);
 	} else {
 		LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' from zip\n", filename.c_str());
-		if (!package->EntryExists(filename)) {
+		ZipEntry binary_entry;
+		if (FindEntry(package, filename, &binary_entry) == 0) {
+		// if (!package->EntryExists(filename)) {
 			LOGERR("Unable to locate '%s' in zip file\n", filename.c_str());
 			return NULL;
 		}
 
 		// Allocate the buffer for the file
-		len = package->GetUncompressedSize(filename);
+		len = binary_entry.uncompressed_length;
+		// len = package->GetUncompressedSize(filename);
 		buffer = (char*) malloc(len + 1);
 		if (!buffer)
 			return NULL;
 
-		if (!package->ExtractToBuffer(filename, (unsigned char*) buffer)) {
+		int32_t err =
+			ExtractToMemory(package, &binary_entry, reinterpret_cast<uint8_t*>(buffer), len);
+		if (err != 0) {
+		// if (!package->ExtractToBuffer(filename, (unsigned char*) buffer)) {
 			LOGERR("Unable to extract '%s'\n", filename.c_str());
 			free(buffer);
 			return NULL;
@@ -1304,13 +1303,15 @@
 	closedir(d);
 }
 
-void PageManager::LoadLanguageList(ZipWrap* package) {
+void PageManager::LoadLanguageList(ZipArchiveHandle package) {
 	Language_List.clear();
 	if (TWFunc::Path_Exists(TWRES "customlanguages"))
 		TWFunc::removeDir(TWRES "customlanguages", true);
 	if (package) {
 		TWFunc::Recursive_Mkdir(TWRES "customlanguages");
-		package->ExtractRecursive("languages", TWRES "customlanguages/");
+		ExtractPackageRecursive(package, "", TWRES "customlanguages", nullptr, nullptr);
+
+		// package->ExtractRecursive("languages", TWRES "customlanguages/");
 		LoadLanguageListDir(TWRES "customlanguages/");
 	} else {
 		LoadLanguageListDir(TWRES "languages/");
@@ -1338,12 +1339,10 @@
 int PageManager::LoadPackage(std::string name, std::string package, std::string startpage)
 {
 	std::string mainxmlfilename = package;
-	ZipWrap zip;
 	char* languageFile = NULL;
 	char* baseLanguageFile = NULL;
 	PageSet* pageSet = NULL;
 	int ret;
-	MemMapping map;
 
 	mReloadTheme = false;
 	mStartPage = startpage;
@@ -1375,22 +1374,14 @@
 		tw_h_offset = 0;
 		if (!TWFunc::Path_Exists(package))
 			return -1;
-#ifdef USE_MINZIP
-		if (sysMapFile(package.c_str(), &map) != 0) {
-#else
-		if (!map.MapFile(package)) {
-#endif
-			LOGERR("Failed to map '%s'\n", package.c_str());
-			goto error;
-		}
-		if (!zip.Open(package.c_str(), &map)) {
-			LOGERR("Unable to open zip archive '%s'\n", package.c_str());
-#ifdef USE_MINZIP
-			sysReleaseMap(&map);
-#endif
-			goto error;
-		}
-		ctx.zip = &zip;
+
+		ZipArchiveHandle Zip;
+		int err = OpenArchive(package.c_str(), &Zip);
+
+		if (err != 0)
+			return -1;
+		
+		ctx.zip = Zip;
 		mainxmlfilename = "ui.xml";
 		LoadLanguageList(ctx.zip);
 		languageFile = LoadFileToBuffer("languages/en.xml", ctx.zip);
@@ -1428,22 +1419,9 @@
 	mCurrentSet = pageSet;
 
 	if (ctx.zip) {
-		ctx.zip->Close();
-#ifdef USE_MINZIP
-		sysReleaseMap(&map);
-#endif
+		CloseArchive(ctx.zip);
 	}
 	return ret;
-
-error:
-	// Sometimes we get here without a real error
-	if (ctx.zip) {
-		ctx.zip->Close();
-#ifdef USE_MINZIP
-		sysReleaseMap(&map);
-#endif
-	}
-	return -1;
 }
 
 PageSet* PageManager::FindPackage(std::string name)
diff --git a/gui/pages.hpp b/gui/pages.hpp
index 8c5edaf..7688604 100755
--- a/gui/pages.hpp
+++ b/gui/pages.hpp
@@ -21,10 +21,10 @@
 #ifndef _PAGES_HEADER_HPP
 #define _PAGES_HEADER_HPP
 
-#include "zipwrap.hpp"
 #include <vector>
 #include <map>
 #include <string>
+#include "ziparchive/zip_archive.h"
 #include "rapidxml.hpp"
 #include "gui.hpp"
 using namespace rapidxml;
@@ -116,7 +116,7 @@
 
 public:
 	int Load(LoadingContext& ctx, const std::string& filename);
-	int LoadLanguage(char* languageFile, ZipWrap* package);
+	int LoadLanguage(char* languageFile, ZipArchiveHandle package);
 	void MakeEmergencyConsoleIfNeeded();
 
 	Page* FindPage(std::string name);
@@ -155,8 +155,8 @@
 {
 public:
 	// Used by GUI
-	static char* LoadFileToBuffer(std::string filename, ZipWrap* package);
-	static void LoadLanguageList(ZipWrap* package);
+	static char* LoadFileToBuffer(std::string filename, ZipArchiveHandle package);
+	static void LoadLanguageList(ZipArchiveHandle package);
 	static void LoadLanguage(std::string filename);
 	static int LoadPackage(std::string name, std::string package, std::string startpage);
 	static PageSet* SelectPackage(std::string name);
diff --git a/gui/resources.cpp b/gui/resources.cpp
index 5efa093..9c4eec1 100755
--- a/gui/resources.cpp
+++ b/gui/resources.cpp
@@ -29,8 +29,9 @@
 #include <iostream>
 #include <iomanip>
 #include <fcntl.h>
+#include <ziparchive/zip_archive.h>
+#include <android-base/unique_fd.h>
 
-#include "zipwrap.hpp"
 extern "C" {
 #include "../twcommon.h"
 #include "gui.h"
@@ -44,24 +45,36 @@
 
 #define TMP_RESOURCE_NAME   "/tmp/extract.bin"
 
-Resource::Resource(xml_node<>* node, ZipWrap* pZip __unused)
+Resource::Resource(xml_node<>* node, ZipArchiveHandle pZip __unused)
 {
 	if (node && node->first_attribute("name"))
 		mName = node->first_attribute("name")->value();
 }
 
-int Resource::ExtractResource(ZipWrap* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile)
+int Resource::ExtractResource(ZipArchiveHandle pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile)
 {
 	if (!pZip)
 		return -1;
 
 	std::string src = folderName + "/" + fileName + fileExtn;
-	if (!pZip->ExtractEntry(src, destFile, 0666))
+	ZipEntry binary_entry;
+	if (FindEntry(pZip, src, &binary_entry) != 0) {
+		android::base::unique_fd fd(
+			open(destFile.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0666));
+		if (fd == -1) {
+			return -1;
+		}
+		// if (!pZip->ExtractEntry(src, destFile, 0666))
+		int32_t err = ExtractEntryToFile(pZip, &binary_entry, fd);
+		if (err != 0)
+			return -1;
+	} else {
 		return -1;
+	}
 	return 0;
 }
 
-void Resource::LoadImage(ZipWrap* pZip, std::string file, gr_surface* surface)
+void Resource::LoadImage(ZipArchiveHandle pZip, std::string file, gr_surface* surface)
 {
 	int rc = 0;
 	if (ExtractResource(pZip, "images", file, ".png", TMP_RESOURCE_NAME) == 0)
@@ -107,7 +120,7 @@
 	}
 }
 
-FontResource::FontResource(xml_node<>* node, ZipWrap* pZip)
+FontResource::FontResource(xml_node<>* node, ZipArchiveHandle pZip)
  : Resource(node, pZip)
 {
 	origFontSize = 0;
@@ -115,7 +128,7 @@
 	LoadFont(node, pZip);
 }
 
-void FontResource::LoadFont(xml_node<>* node, ZipWrap* pZip)
+void FontResource::LoadFont(xml_node<>* node, ZipArchiveHandle pZip)
 {
 	std::string file;
 	xml_attribute<>* attr;
@@ -182,7 +195,7 @@
 	origFont = NULL;
 }
 
-void FontResource::Override(xml_node<>* node, ZipWrap* pZip) {
+void FontResource::Override(xml_node<>* node, ZipArchiveHandle pZip) {
 	if (!origFont) {
 		origFont = mFont;
 	} else if (mFont) {
@@ -197,7 +210,7 @@
 	DeleteFont();
 }
 
-ImageResource::ImageResource(xml_node<>* node, ZipWrap* pZip)
+ImageResource::ImageResource(xml_node<>* node, ZipArchiveHandle pZip)
  : Resource(node, pZip)
 {
 	std::string file;
@@ -228,7 +241,7 @@
 		res_free_surface(mSurface);
 }
 
-AnimationResource::AnimationResource(xml_node<>* node, ZipWrap* pZip)
+AnimationResource::AnimationResource(xml_node<>* node, ZipArchiveHandle pZip)
  : Resource(node, pZip)
 {
 	std::string file;
@@ -349,7 +362,7 @@
 	mStrings[resource_name] = res;
 }
 
-void ResourceManager::LoadResources(xml_node<>* resList, ZipWrap* pZip, std::string resource_source)
+void ResourceManager::LoadResources(xml_node<>* resList, ZipArchiveHandle pZip, std::string resource_source)
 {
 	if (!resList)
 		return;
diff --git a/gui/resources.hpp b/gui/resources.hpp
index e709e33..aeacd19 100755
--- a/gui/resources.hpp
+++ b/gui/resources.hpp
@@ -25,7 +25,7 @@
 #include <vector>
 #include <map>
 #include "rapidxml.hpp"
-#include "zipwrap.hpp"
+#include "ziparchive/zip_archive.h"
 #include "../minuitwrp/truetype.hpp"
 
 extern "C" {
@@ -36,7 +36,7 @@
 class Resource
 {
 public:
-	Resource(xml_node<>* node, ZipWrap* pZip);
+	Resource(xml_node<>* node, ZipArchiveHandle pZip);
 	virtual ~Resource() {}
 
 public:
@@ -46,27 +46,27 @@
 	std::string mName;
 
 protected:
-	static int ExtractResource(ZipWrap* pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
-	static void LoadImage(ZipWrap* pZip, std::string file, gr_surface* surface);
+	static int ExtractResource(ZipArchiveHandle pZip, std::string folderName, std::string fileName, std::string fileExtn, std::string destFile);
+	static void LoadImage(ZipArchiveHandle pZip, std::string file, gr_surface* surface);
 	static void CheckAndScaleImage(gr_surface source, gr_surface* destination, int retain_aspect);
 };
 
 class FontResource : public Resource
 {
 public:
-	FontResource(xml_node<>* node, ZipWrap* pZip);
+	FontResource(xml_node<>* node, ZipArchiveHandle pZip);
 	virtual ~FontResource();
 
 public:
 	void* GetResource() { return mFont; }
 	int GetHeight() { return twrpTruetype::gr_ttf_getMaxFontHeight(mFont); }
-	void Override(xml_node<>* node, ZipWrap* pZip);
+	void Override(xml_node<>* node, ZipArchiveHandle pZip);
 
 protected:
 	void* mFont;
 
 private:
-	void LoadFont(xml_node<>* node, ZipWrap* pZip);
+	void LoadFont(xml_node<>* node, ZipArchiveHandle pZip);
 	void DeleteFont();
 
 private:
@@ -77,7 +77,7 @@
 class ImageResource : public Resource
 {
 public:
-	ImageResource(xml_node<>* node, ZipWrap* pZip);
+	ImageResource(xml_node<>* node, ZipArchiveHandle pZip);
 	virtual ~ImageResource();
 
 public:
@@ -92,7 +92,7 @@
 class AnimationResource : public Resource
 {
 public:
-	AnimationResource(xml_node<>* node, ZipWrap* pZip);
+	AnimationResource(xml_node<>* node, ZipArchiveHandle pZip);
 	virtual ~AnimationResource();
 
 public:
@@ -112,7 +112,7 @@
 	ResourceManager();
 	virtual ~ResourceManager();
 	void AddStringResource(std::string resource_source, std::string resource_name, std::string value);
-	void LoadResources(xml_node<>* resList, ZipWrap* pZip, std::string resource_source);
+	void LoadResources(xml_node<>* resList, ZipArchiveHandle pZip, std::string resource_source);
 
 public:
 	FontResource* FindFont(const std::string& name) const;