From 83298f53756f41f56ed7c6c42bb2df0d30221c60 Mon Sep 17 00:00:00 2001 From: bigbiff Date: Wed, 13 Oct 2021 19:24:42 -0400 Subject: [PATCH] custom theme: fix libziparchive loading of custom themes Change-Id: Ia23a9dcd24fcbb61cb5e1df366a4325d20d777b2 --- gui/pages.cpp | 12 +++++------- gui/resources.cpp | 3 +-- install/ZipUtil.cpp | 3 ++- twrp.cpp | 8 +++----- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/gui/pages.cpp b/gui/pages.cpp index 3145c15f..bc4a9360 100755 --- a/gui/pages.cpp +++ b/gui/pages.cpp @@ -1225,15 +1225,13 @@ char* PageManager::LoadFileToBuffer(std::string filename, ZipArchiveHandle packa } else { LOGINFO("PageManager::LoadFileToBuffer loading filename: '%s' from zip\n", filename.c_str()); ZipEntry binary_entry; - if (FindEntry(package, filename, &binary_entry) == 0) { - // if (!package->EntryExists(filename)) { + if (FindEntry(package, filename, &binary_entry) != 0) { LOGERR("Unable to locate '%s' in zip file\n", filename.c_str()); return NULL; } // Allocate the buffer for the file len = binary_entry.uncompressed_length; - // len = package->GetUncompressedSize(filename); buffer = (char*) malloc(len + 1); if (!buffer) return NULL; @@ -1241,7 +1239,6 @@ char* PageManager::LoadFileToBuffer(std::string filename, ZipArchiveHandle packa int32_t err = ExtractToMemory(package, &binary_entry, reinterpret_cast(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; @@ -1311,7 +1308,7 @@ void PageManager::LoadLanguageList(ZipArchiveHandle package) { TWFunc::removeDir(TWRES "customlanguages", true); if (package) { TWFunc::Recursive_Mkdir(TWRES "customlanguages"); - ExtractPackageRecursive(package, "", TWRES "customlanguages", nullptr, nullptr); + ExtractPackageRecursive(package, "/", TWRES "customlanguages", nullptr, nullptr); // package->ExtractRecursive("languages", TWRES "customlanguages/"); LoadLanguageListDir(TWRES "customlanguages/"); @@ -1374,15 +1371,16 @@ int PageManager::LoadPackage(std::string name, std::string package, std::string tw_y_offset = 0; tw_w_offset = 0; tw_h_offset = 0; - if (!TWFunc::Path_Exists(package)) + if (!TWFunc::Path_Exists(package)) { return -1; + } ZipArchiveHandle Zip; int err = OpenArchive(package.c_str(), &Zip); if (err != 0) return -1; - + ctx.zip = Zip; mainxmlfilename = "ui.xml"; LoadLanguageList(ctx.zip); diff --git a/gui/resources.cpp b/gui/resources.cpp index cf677f61..744a8533 100755 --- a/gui/resources.cpp +++ b/gui/resources.cpp @@ -58,13 +58,12 @@ int Resource::ExtractResource(ZipArchiveHandle pZip, std::string folderName, std std::string src = folderName + "/" + fileName + fileExtn; ZipEntry binary_entry; - if (FindEntry(pZip, src, &binary_entry) != 0) { + 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; diff --git a/install/ZipUtil.cpp b/install/ZipUtil.cpp index c7b6b3d3..75acad9d 100755 --- a/install/ZipUtil.cpp +++ b/install/ZipUtil.cpp @@ -54,9 +54,10 @@ bool ExtractPackageRecursive(ZipArchiveHandle zip, const std::string& zip_path, if (!zip_path.empty() && zip_path.back() != '/') { prefix_path += '/'; } - const std::string zip_prefix(prefix_path.c_str()); + const std::string zip_prefix(prefix_path.c_str()); int ret = StartIteration(zip, &cookie, zip_prefix, nullptr); + if (ret != 0) { LOG(ERROR) << "failed to start iterating zip entries."; return false; diff --git a/twrp.cpp b/twrp.cpp index 96446b20..51099147 100644 --- a/twrp.cpp +++ b/twrp.cpp @@ -85,15 +85,10 @@ static void Decrypt_Page(bool SkipDecryption, bool datamedia) { DataManager::SetValue("tw_crypto_user_id", "0"); if (gui_startPage("decrypt", 1, 1) != 0) { LOGERR("Failed to start decrypt GUI page.\n"); - } else { - // Check for and load custom theme if present - TWFunc::check_selinux_support(); - gui_loadCustomResources(); } } } else if (datamedia) { PartitionManager.Update_System_Details(); - TWFunc::check_selinux_support(); if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) { LOGINFO("Failed to get default contexts and file mode for storage files.\n"); } else { @@ -221,6 +216,9 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti #endif Decrypt_Page(skip_decryption, datamedia); + // Check for and load custom theme if present + TWFunc::check_selinux_support(); + gui_loadCustomResources(); PartitionManager.Output_Partition_Logging(); // Fixup the RTC clock on devices which require it