ADB Backup: fix adb restore issues

Set Backup_FileName on adb backup to fix restore.
Set read_from_adb after EOF to return properly
from newer adb client prompt.
Create setter and getter for Backup_FileName
for openrecoveryscript.cpp which is not a
friend class.
Fix condition for twrpTar::Get_Size() and adb backup.
Change-Id: I7eb8168fa3416366b996e220cecbc0e1bcec5e8e
diff --git a/adbbu/twadbstream.h b/adbbu/twadbstream.h
index 4e76be1..23d4a1f 100644
--- a/adbbu/twadbstream.h
+++ b/adbbu/twadbstream.h
@@ -21,7 +21,7 @@
 #define TW_ADB_BU_CONTROL "/tmp/twadbbucontrol"		//FIFO for sending control from TWRP to ADB Backup
 #define TW_ADB_TWRP_CONTROL "/tmp/twadbtwrpcontrol"	//FIFO for sending control from ADB Backup to TWRP
 #define TWRP "TWRP"					//Magic Value
-#define ADB_BU_MAX_ERROR 10				//Max amount of errors for while loops
+#define ADB_BU_MAX_ERROR 20				//Max amount of errors for while loops
 
 //ADB Backup Control Commands
 #define TWSTREAMHDR "twstreamheader"			//TWRP Parititon Count Control
diff --git a/adbbu/twrpback.cpp b/adbbu/twrpback.cpp
index 2a227ec..c59fd1c 100644
--- a/adbbu/twrpback.cpp
+++ b/adbbu/twrpback.cpp
@@ -514,7 +514,6 @@
 				return -1;
 			}
 		}
-
 		//If we should read from the adb stream, write commands and data to TWRP
 		if (read_from_adb) {
 			std::string cmdstr;
@@ -547,6 +546,7 @@
 							close_restore_fds();
 							return -1;
 						}
+						read_from_adb = false;
 					}
 					else {
 						adblogwrite("ADB TWENDADB crc header doesn't match\n");
diff --git a/openrecoveryscript.cpp b/openrecoveryscript.cpp
index b45cf0a..faa0f9c 100644
--- a/openrecoveryscript.cpp
+++ b/openrecoveryscript.cpp
@@ -903,6 +903,7 @@
 					part_settings.partition_count = partition_count;
 					part_settings.adbbackup = true;
 					part_settings.adb_compression = twimghdr.compressed;
+					part_settings.Part->Set_Backup_FileName(part_settings.Part->Get_Backup_Name() + "." + part_settings.Part->Current_File_System + ".win");
 					part_settings.total_restore_size += part_settings.Part->Get_Restore_Size(&part_settings);
 					part_settings.PM_Method = PM_RESTORE;
 					ProgressTracking progress(part_settings.total_restore_size);
diff --git a/partition.cpp b/partition.cpp
index 8832909..f523ddf 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -2947,3 +2947,11 @@
 	LOGINFO("Revert_Adopted: no crypto support\n");
 #endif
 }
+
+void TWPartition::Set_Backup_FileName(string fname) {
+	Backup_FileName = fname;
+}
+
+string TWPartition::Get_Backup_Name() {
+	return Backup_Name;
+}
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 8aceec2..0b9918d 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -915,6 +915,10 @@
 bool TWPartitionManager::Restore_Partition(PartitionSettings *part_settings) {
 	time_t Start, Stop;
 
+	if (part_settings->adbbackup) {
+		part_settings->Part->Set_Backup_FileName(part_settings->Part->Backup_Name + "." + part_settings->Part->Current_File_System + ".win");
+	}
+
 	TWFunc::SetPerformanceMode(true);
 
 	time(&Start);
diff --git a/partitions.hpp b/partitions.hpp
index 0f0e6fd..0865c96 100644
--- a/partitions.hpp
+++ b/partitions.hpp
@@ -106,6 +106,8 @@
 	int Decrypt_Adopted();
 	void Revert_Adopted();
 	void Partition_Post_Processing(bool Display_Error);                       // Apply partition specific settings after fstab processed
+	void Set_Backup_FileName(string fname);                                   // Set Backup_FileName for partition
+	string Get_Backup_Name();                                                 // Get Backup_Name for partition
 
 public:
 	string Current_File_System;                                               // Current file system
diff --git a/twrpTar.cpp b/twrpTar.cpp
index 3911733..d86e133 100644
--- a/twrpTar.cpp
+++ b/twrpTar.cpp
@@ -1463,7 +1463,7 @@
 }
 
 unsigned long long twrpTar::get_size() {
-	if (TWFunc::Path_Exists(tarfn) && !part_settings->adbbackup) {
+	if (part_settings->adbbackup || TWFunc::Path_Exists(tarfn)) {
 		LOGINFO("Single archive\n");
 		return uncompressedSize(tarfn);
 	} else {