Skip to content

Commit

Permalink
custom theme: fix libziparchive loading of custom themes
Browse files Browse the repository at this point in the history
Change-Id: Ia23a9dcd24fcbb61cb5e1df366a4325d20d777b2
  • Loading branch information
epicX67 committed Nov 4, 2021
1 parent a4c5a49 commit e43fd31
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
12 changes: 5 additions & 7 deletions gui/pages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,23 +1226,20 @@ 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;

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;
Expand Down Expand Up @@ -1312,7 +1309,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/");
Expand Down Expand Up @@ -1375,15 +1372,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);
Expand Down
3 changes: 1 addition & 2 deletions gui/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion install/ZipUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions twrp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ 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();

// Reloading Gui
Reload_Gui();
}
Expand All @@ -115,7 +111,6 @@ static void Decrypt_Page(bool SkipDecryption, bool datamedia) {
PartitionManager.Update_System_Details();
// Reloading Gui
Reload_Gui();
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 {
Expand Down Expand Up @@ -251,6 +246,9 @@ static void process_recovery_mode(twrpAdbBuFifo* adb_bu_fifo, bool skip_decrypti
*/

Decrypt_Page(skip_decryption, datamedia);
// Check for and load custom theme if present
TWFunc::check_selinux_support();
gui_loadCustomResources();
PartitionManager.Output_Partition_Logging();

//Save JSON
Expand Down

0 comments on commit e43fd31

Please sign in to comment.