AB/Non AB Devices: updates for moving cache

This patchset updates all the places we touch cache on AB devices
and non AB devices so that we can write to the appropriate
location. AB devices removed the cache partition and moved it to
/data/cache.

Change-Id: I485ec205a604f1f07ceb7700ae9c4e720fd55c3e
diff --git a/openrecoveryscript.cpp b/openrecoveryscript.cpp
old mode 100644
new mode 100755
index 86c90a6..d4d4da5
--- a/openrecoveryscript.cpp
+++ b/openrecoveryscript.cpp
@@ -62,17 +62,18 @@
 #define SCRIPT_COMMAND_SIZE 512
 
 int OpenRecoveryScript::check_for_script_file(void) {
-	if (!PartitionManager.Mount_By_Path(SCRIPT_FILE_CACHE, false)) {
-		LOGINFO("Unable to mount /cache for OpenRecoveryScript support.\n");
-		gui_msg(Msg(msg::kError, "unable_to_mount=Unable to mount {1}")(SCRIPT_FILE_CACHE));
+	std::string orsFile = TWFunc::get_cache_dir() + "/recovery/openrecoveryscript";
+	if (!PartitionManager.Mount_By_Path(orsFile, false)) {
+		LOGINFO("Unable to mount %s for OpenRecoveryScript support.\n", TWFunc::get_cache_dir().c_str());
+		gui_msg(Msg(msg::kError, "unable_to_mount=Unable to mount {1}")(TWFunc::get_cache_dir()));
 		return 0;
 	}
-	if (TWFunc::Path_Exists(SCRIPT_FILE_CACHE)) {
-		LOGINFO("Script file found: '%s'\n", SCRIPT_FILE_CACHE);
+	if (TWFunc::Path_Exists(orsFile)) {
+		LOGINFO("Script file found: '%s'\n", orsFile.c_str());
 		// Copy script file to /tmp
-		TWFunc::copy_file(SCRIPT_FILE_CACHE, SCRIPT_FILE_TMP, 0755);
-		// Delete the file from /cache
-		unlink(SCRIPT_FILE_CACHE);
+		TWFunc::copy_file(orsFile, SCRIPT_FILE_TMP, 0755);
+		// Delete the file from cache
+		unlink(orsFile.c_str());
 		return 1;
 	}
 	return 0;
@@ -655,6 +656,10 @@
 		gui_msg("decrypt_cmd=Attempting to decrypt data partition via command line.");
 		if (PartitionManager.Decrypt_Device(pass) == 0) {
 			// set_page_done = 1;  // done by singleaction_page anyway
+			std::string orsFile = TWFunc::get_cache_dir() + "/openrecoveryscript";
+			if (TWFunc::Path_Exists(orsFile)) {
+				Run_OpenRecoveryScript_Action();
+			}
 		}
 	} else if (OpenRecoveryScript::Insert_ORS_Command(command)) {
 		OpenRecoveryScript::run_script_file();