Convert AOSP commands to ORS for encrypted devices

Change-Id: I6a76a51cd9efd7db67d7abeeb26f9bdd0eebf5a9
diff --git a/openrecoveryscript.cpp b/openrecoveryscript.cpp
index 8e95555..f0efae4 100644
--- a/openrecoveryscript.cpp
+++ b/openrecoveryscript.cpp
@@ -30,6 +30,8 @@
 #include <dirent.h>
 #include <time.h>
 #include <errno.h>
+#include <iostream>
+#include <fstream>
 
 #include "twrp-functions.hpp"
 #include "partitions.hpp"
@@ -38,15 +40,13 @@
 #include "variables.h"
 #include "adb_install.h"
 extern "C" {
-#include "data.h"
-#include "twinstall.h"
-#include "gui/gui.h"
-int TWinstall_zip(const char* path, int* wipe_cache);
+	#include "data.h"
+	#include "twinstall.h"
+	#include "gui/gui.h"
+	int TWinstall_zip(const char* path, int* wipe_cache);
 }
 
 extern RecoveryUI* ui;
-static const char *SCRIPT_FILE_CACHE = "/cache/recovery/openrecoveryscript";
-static const char *SCRIPT_FILE_TMP = "/tmp/openrecoveryscript";
 #define SCRIPT_COMMAND_SIZE 512
 
 int OpenRecoveryScript::check_for_script_file(void) {
@@ -378,6 +378,20 @@
 	return ret_val;
 }
 
+int OpenRecoveryScript::Insert_ORS_Command(string Command) {
+	ofstream ORSfile(SCRIPT_FILE_TMP);
+	if (ORSfile.is_open()) {
+		//if (Command.substr(Command.size() - 1, 1) != "\n")
+		//	Command += "\n";
+		LOGI("Inserting '%s'\n", Command.c_str());
+		ORSfile << Command.c_str();
+		ORSfile.close();
+		return 1;
+	}
+	LOGE("Unable to append '%s' to '%s'\n", Command.c_str(), SCRIPT_FILE_TMP);
+	return 0;
+}
+
 int OpenRecoveryScript::Install_Command(string Zip) {
 	// Install zip
 	string ret_string;