Support encrypted backup files

Also includes features merged from:

Update twrpTar by kokotas

Revised function entryExists().
Added function to get archive's uncompressed size.
Added option to exclude item(s) from the archive.
Revised forks()

http://review.teamw.in/#/c/590/

Change-Id: I01fa2c81643161984eff2625247af75990684bd9
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 0bed258..a78705b 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -184,6 +184,10 @@
 		printf("Is_Decrypted ");
 	if (Part->Has_Data_Media)
 		printf("Has_Data_Media ");
+	if (Part->Can_Encrypt_Backup)
+		printf("Can_Encrypt_Backup ");
+	if (Part->Use_Userdata_Encryption)
+		printf("Use_Userdata_Encryption ");
 	if (Part->Has_Android_Secure)
 		printf("Has_Android_Secure ");
 	if (Part->Is_Storage)
@@ -532,18 +536,20 @@
 		string strfn;
 		sprintf(filename, "%s%03i", Full_File.c_str(), index);
 		strfn = filename;
-		while (TWFunc::Path_Exists(filename) == true) {
+		while (index < 1000) {
 			md5sum.setfn(filename);
-			if (md5sum.computeMD5() == 0) {
-				if (md5sum.write_md5digest() != 0)
-				{
-					gui_print(" * MD5 Error.\n");
+			if (TWFunc::Path_Exists(filename)) {
+				if (md5sum.computeMD5() == 0) {
+					if (md5sum.write_md5digest() != 0)
+					{
+						gui_print(" * MD5 Error.\n");
+						return false;
+					}
+				} else {
+					gui_print(" * Error computing MD5.\n");
 					return false;
 				}
 			}
-			else {
-				return -1;
-			}
 			index++;
 			sprintf(filename, "%s%03i", Full_File.c_str(), index);
 			strfn = filename;
@@ -902,7 +908,9 @@
 void TWPartitionManager::Set_Restore_Files(string Restore_Name) {
 	// Start with the default values
 	string Restore_List;
-	bool get_date = true;
+	bool get_date = true, check_encryption = true;
+
+	DataManager::SetValue("tw_restore_encrypted", 0);
 
 	DIR* d;
 	d = opendir(Restore_Name.c_str());
@@ -956,10 +964,20 @@
 			extn = ptr;
 		}
 
-		if (strcmp(fstype, "log") == 0) continue;
+		if (fstype == NULL || extn == NULL || strcmp(fstype, "log") == 0) continue;
 		int extnlength = strlen(extn);
-		if (extn == NULL || (extnlength != 3 && extnlength != 6)) continue;
-		if (extnlength == 3 && strncmp(extn, "win", 3) != 0) continue;
+		if (extnlength != 3 && extnlength != 6) continue;
+		if (extnlength >= 3 && strncmp(extn, "win", 3) != 0) continue;
+		//if (extnlength == 6 && strncmp(extn, "win000", 6) != 0) continue;
+
+		if (check_encryption) {
+			string filename = Restore_Name + "/";
+			filename += de->d_name;
+			if (TWFunc::Get_File_Type(filename) == 2) {
+				LOGINFO("'%s' is encrypted\n", filename.c_str());
+				DataManager::SetValue("tw_restore_encrypted", 1);
+			}
+		}
 		if (extnlength == 6 && strncmp(extn, "win000", 6) != 0) continue;
 
 		TWPartition* Part = Find_Partition_By_Path(label);