Fix backup and restore after autodetection for SAR

This reverts commit 8a411c8d257bf37a31907fc44be7cedf447aad7f.

 * Always use "/system" to interact with the frontend and replace it
   with the detected path before taking actions.
 * Don't replace the pretty display name and backup name set during
   processing fstab after wipe. This improves UX and ensures that the
   system backup is always named system.ext4.win despite the actual
   mount point is /system_root so TWRP is able to recover either SAR or
   non-SAR backups.

Change-Id: Ie2594d2678d0c75ce25c0d1087d47b035b3f10e9
diff --git a/openrecoveryscript.cpp b/openrecoveryscript.cpp
index 6d76298..903bc6c 100755
--- a/openrecoveryscript.cpp
+++ b/openrecoveryscript.cpp
@@ -148,8 +148,8 @@
 				// Wipe
 				if (strcmp(value, "cache") == 0 || strcmp(value, "/cache") == 0) {
 					PartitionManager.Wipe_By_Path("/cache");
-				} else if (strcmp(value, PartitionManager.Get_Android_Root_Path().c_str()) == 0 || strcmp(value, PartitionManager.Get_Android_Root_Path().c_str()) == 0) {
-					PartitionManager.Wipe_By_Path(PartitionManager.Get_Android_Root_Path());
+				} else if (strcmp(value, "system") == 0 || strcmp(value, "/system") == 0 || strcmp(value, PartitionManager.Get_Android_Root_Path().c_str()) == 0) {
+					PartitionManager.Wipe_By_Path("/system");
 				} else if (strcmp(value, "dalvik") == 0 || strcmp(value, "dalvick") == 0 || strcmp(value, "dalvikcache") == 0 || strcmp(value, "dalvickcache") == 0) {
 					PartitionManager.Wipe_Dalvik_Cache();
 				} else if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) {
@@ -253,8 +253,8 @@
 					gui_msg(Msg("set_restore_opt=Setting restore options: '{1}':")(value2));
 					line_len = strlen(value2);
 					for (i=0; i<line_len; i++) {
-						if ((value2[i] == 'S' || value2[i] == 's') && Partition_List.find(PartitionManager.Get_Android_Root_Path() + ';') != string::npos) {
-							Restore_List += PartitionManager.Get_Android_Root_Path() + ';';
+						if ((value2[i] == 'S' || value2[i] == 's') && Partition_List.find("/system;") != string::npos) {
+							Restore_List += "/system;";
 							gui_msg("system=System");
 						} else if ((value2[i] == 'D' || value2[i] == 'd') && Partition_List.find("/data;") != string::npos) {
 							Restore_List += "/data;";
@@ -543,7 +543,7 @@
 	line_len = Options.size();
 	for (i=0; i<line_len; i++) {
 		if (Options.substr(i, 1) == "S" || Options.substr(i, 1) == "s") {
-			Backup_List += PartitionManager.Get_Android_Root_Path() + ';';
+			Backup_List += "/system;";
 			gui_msg("system=System");
 		} else if (Options.substr(i, 1) == "D" || Options.substr(i, 1) == "d") {
 			Backup_List += "/data;";
diff --git a/partition.cpp b/partition.cpp
index 646959c..9ed0ebc 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -417,12 +417,10 @@
 		else
 			return true;
 	} else if (Mount_Point == "auto") {
-		Mount_Point = "/auto";
-		char autoi[5];
-		sprintf(autoi, "%i", auto_index);
-		Mount_Point += autoi;
+		Mount_Point = "/auto" + to_string(auto_index);
 		Backup_Path = Mount_Point;
 		Storage_Path = Mount_Point;
+		Backup_Name = Mount_Point.substr(1);
 		auto_index++;
 		Setup_File_System(Display_Error);
 		Display_Name = "Storage";
@@ -442,8 +440,10 @@
 	} else if (Is_File_System(Fstab_File_System)) {
 		Find_Actual_Block_Device();
 		Setup_File_System(Display_Error);
+		Backup_Name = Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1);
 		if (Mount_Point == "/" || Mount_Point == "/system" || Mount_Point == "/system_root") {
 			Display_Name = "System";
+			Backup_Name = "system";
 			Backup_Display_Name = Display_Name;
 			Storage_Name = Display_Name;
 			Wipe_Available_in_GUI = true;
@@ -1092,8 +1092,6 @@
 
 	// Make the mount point folder if it doesn't exist
 	Make_Dir(Mount_Point, Display_Error);
-	Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1);
-	Backup_Name = Display_Name;
 	Backup_Method = BM_FILES;
 }
 
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index f63b3f3..873b292 100755
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -599,6 +599,8 @@
 	std::vector<TWPartition*>::iterator iter;
 	string Local_Path = TWFunc::Get_Root_Path(Path);
 
+	if (Local_Path == "/system")
+		Local_Path = Get_Android_Root_Path();
 	for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
 		if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path))
 			return (*iter);
@@ -1273,8 +1275,12 @@
 				Part->Backup_FileName.resize(Part->Backup_FileName.size() - strlen(extn) + 3);
 			}
 
-			if (!Part->Is_SubPartition)
-				Restore_List += Part->Backup_Path + ";";
+			if (!Part->Is_SubPartition) {
+				if (Part->Backup_Path == Get_Android_Root_Path())
+					Restore_List += "/system;";
+				else
+					Restore_List += Part->Backup_Path + ";";
+			}
 		}
 		closedir(d);
 	}
@@ -1297,6 +1303,8 @@
 	bool found = false;
 	string Local_Path = TWFunc::Get_Root_Path(Path);
 
+	if (Local_Path == "/system")
+		Local_Path = Get_Android_Root_Path();
 	// Iterate through all partitions
 	for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
 		if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) {