blob: 361a676b29a96ef006476435303ad02e45360f5d [file] [log] [blame]
jrior001aad03112014-07-05 10:31:21 -04001/*update
Dees_Troya13d74f2013-03-24 08:54:55 -05002 Copyright 2013 bigbiff/Dees_Troy TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
Dees_Troy51a0e822012-09-05 15:24:24 -040018
19#include <stdarg.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <fcntl.h>
24#include <sys/stat.h>
25#include <sys/time.h>
26#include <sys/mman.h>
27#include <sys/types.h>
28#include <sys/ioctl.h>
29#include <linux/input.h>
30#include <time.h>
31#include <unistd.h>
32#include <stdlib.h>
Dees_Troy657c3092012-09-10 20:32:10 -040033#include <sys/wait.h>
Dees_Troy83bd4832013-05-04 12:39:56 +000034#include <dirent.h>
Vojtech Bocek03fd6c52014-03-13 18:46:34 +010035#include <pwd.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040036
37#include <string>
38#include <sstream>
39#include "../partitions.hpp"
Dees_Troy38bd7602012-09-14 13:33:53 -040040#include "../twrp-functions.hpp"
Dees_Troy812660f2012-09-20 09:55:17 -040041#include "../openrecoveryscript.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040042
Dees_Troy43d8b002012-09-17 16:00:01 -040043#include "../adb_install.h"
thatcc8ddca2015-01-03 01:59:36 +010044#include "../fuse_sideload.h"
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070045#ifndef TW_NO_SCREEN_TIMEOUT
bigbiff bigbiff8a68c312013-02-10 14:28:30 -050046#include "blanktimer.hpp"
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070047#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040048extern "C" {
Dees_Troy2673cec2013-04-02 20:22:16 +000049#include "../twcommon.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040050#include "../minuitwrp/minui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040051#include "../variables.h"
Dees_Troy32c8eb82012-09-11 15:28:06 -040052#include "../twinstall.h"
Dees_Troy2673cec2013-04-02 20:22:16 +000053#include "cutils/properties.h"
Dees_Troy43d8b002012-09-17 16:00:01 -040054#include "../minadbd/adb.h"
Ethan Yonker24813422014-11-07 17:19:07 -060055#include "../adb_install.h"
Ethan Yonker4b94cfd2014-12-11 10:00:45 -060056#include "../set_metadata.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040057};
58
59#include "rapidxml.hpp"
60#include "objects.hpp"
61
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070062#ifndef TW_NO_SCREEN_TIMEOUT
bigbiff bigbiff8a68c312013-02-10 14:28:30 -050063extern blanktimer blankTimer;
Ricardo Gomezc9ecd442013-07-05 16:13:52 -070064#endif
Dees_Troy43d8b002012-09-17 16:00:01 -040065
Dees_Troy51a0e822012-09-05 15:24:24 -040066void curtainClose(void);
67
that3f7b1ac2014-12-30 11:30:13 +010068GUIAction::mapFunc GUIAction::mf;
69static string zip_queue[10];
70static int zip_queue_index;
71static pthread_t terminal_command;
thatcc8ddca2015-01-03 01:59:36 +010072pid_t sideload_child_pid;
that3f7b1ac2014-12-30 11:30:13 +010073
Dees_Troy51a0e822012-09-05 15:24:24 -040074GUIAction::GUIAction(xml_node<>* node)
Vojtech Bocekede51c52014-02-07 23:58:09 +010075 : GUIObject(node)
Dees_Troy51a0e822012-09-05 15:24:24 -040076{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 xml_node<>* child;
78 xml_node<>* actions;
79 xml_attribute<>* attr;
Dees_Troy51a0e822012-09-05 15:24:24 -040080
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 if (!node) return;
Dees_Troy51a0e822012-09-05 15:24:24 -040082
that3f7b1ac2014-12-30 11:30:13 +010083 if (mf.empty()) {
84 mf["reboot"] = &GUIAction::reboot;
85 mf["home"] = &GUIAction::home;
86 mf["key"] = &GUIAction::key;
87 mf["page"] = &GUIAction::page;
88 mf["reload"] = &GUIAction::reload;
89 mf["readBackup"] = &GUIAction::readBackup;
90 mf["set"] = &GUIAction::set;
91 mf["clear"] = &GUIAction::clear;
92 mf["mount"] = &GUIAction::mount;
93 mf["unmount"] = &GUIAction::unmount;
94 mf["umount"] = &GUIAction::unmount;
95 mf["restoredefaultsettings"] = &GUIAction::restoredefaultsettings;
96 mf["copylog"] = &GUIAction::copylog;
97 mf["compute"] = &GUIAction::compute;
98 mf["addsubtract"] = &GUIAction::compute;
99 mf["setguitimezone"] = &GUIAction::setguitimezone;
100 mf["overlay"] = &GUIAction::overlay;
101 mf["queuezip"] = &GUIAction::queuezip;
102 mf["cancelzip"] = &GUIAction::cancelzip;
103 mf["queueclear"] = &GUIAction::queueclear;
104 mf["sleep"] = &GUIAction::sleep;
105 mf["appenddatetobackupname"] = &GUIAction::appenddatetobackupname;
106 mf["generatebackupname"] = &GUIAction::generatebackupname;
107 mf["checkpartitionlist"] = &GUIAction::checkpartitionlist;
108 mf["getpartitiondetails"] = &GUIAction::getpartitiondetails;
109 mf["screenshot"] = &GUIAction::screenshot;
110 mf["setbrightness"] = &GUIAction::setbrightness;
111
112 // threaded actions
113 mf["fileexists"] = &GUIAction::fileexists;
114 mf["flash"] = &GUIAction::flash;
115 mf["wipe"] = &GUIAction::wipe;
116 mf["refreshsizes"] = &GUIAction::refreshsizes;
117 mf["nandroid"] = &GUIAction::nandroid;
118 mf["fixpermissions"] = &GUIAction::fixpermissions;
119 mf["dd"] = &GUIAction::dd;
120 mf["partitionsd"] = &GUIAction::partitionsd;
121 mf["installhtcdumlock"] = &GUIAction::installhtcdumlock;
122 mf["htcdumlockrestoreboot"] = &GUIAction::htcdumlockrestoreboot;
123 mf["htcdumlockreflashrecovery"] = &GUIAction::htcdumlockreflashrecovery;
124 mf["cmd"] = &GUIAction::cmd;
125 mf["terminalcommand"] = &GUIAction::terminalcommand;
126 mf["killterminal"] = &GUIAction::killterminal;
127 mf["reinjecttwrp"] = &GUIAction::reinjecttwrp;
128 mf["checkbackupname"] = &GUIAction::checkbackupname;
129 mf["decrypt"] = &GUIAction::decrypt;
130 mf["adbsideload"] = &GUIAction::adbsideload;
131 mf["adbsideloadcancel"] = &GUIAction::adbsideloadcancel;
132 mf["openrecoveryscript"] = &GUIAction::openrecoveryscript;
133 mf["installsu"] = &GUIAction::installsu;
134 mf["fixsu"] = &GUIAction::fixsu;
135 mf["decrypt_backup"] = &GUIAction::decrypt_backup;
136 mf["repair"] = &GUIAction::repair;
137 mf["changefilesystem"] = &GUIAction::changefilesystem;
138 mf["startmtp"] = &GUIAction::startmtp;
139 mf["stopmtp"] = &GUIAction::stopmtp;
140 }
141
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200142 // First, get the action
143 actions = node->first_node("actions");
144 if (actions) child = actions->first_node("action");
145 else child = node->first_node("action");
Dees_Troy51a0e822012-09-05 15:24:24 -0400146
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200147 if (!child) return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400148
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200149 while (child)
150 {
151 Action action;
Dees_Troy51a0e822012-09-05 15:24:24 -0400152
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200153 attr = child->first_attribute("function");
154 if (!attr) return;
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500155
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200156 action.mFunction = attr->value();
157 action.mArg = child->value();
158 mActions.push_back(action);
Dees_Troy51a0e822012-09-05 15:24:24 -0400159
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200160 child = child->next_sibling("action");
161 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400162
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200163 // Now, let's get either the key or region
164 child = node->first_node("touch");
165 if (child)
166 {
167 attr = child->first_attribute("key");
168 if (attr)
169 {
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100170 std::vector<std::string> keys = TWFunc::Split_String(attr->value(), "+");
171 for(size_t i = 0; i < keys.size(); ++i)
172 {
173 const int key = getKeyByName(keys[i]);
174 mKeys[key] = false;
175 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200176 }
177 else
178 {
179 attr = child->first_attribute("x");
180 if (!attr) return;
181 mActionX = atol(attr->value());
182 attr = child->first_attribute("y");
183 if (!attr) return;
184 mActionY = atol(attr->value());
185 attr = child->first_attribute("w");
186 if (!attr) return;
187 mActionW = atol(attr->value());
188 attr = child->first_attribute("h");
189 if (!attr) return;
190 mActionH = atol(attr->value());
191 }
192 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400193}
194
195int GUIAction::NotifyTouch(TOUCH_STATE state, int x, int y)
196{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200197 if (state == TOUCH_RELEASE)
198 doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400199
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200200 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400201}
202
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100203int GUIAction::NotifyKey(int key, bool down)
Dees_Troy51a0e822012-09-05 15:24:24 -0400204{
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100205 if (mKeys.empty())
206 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400207
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100208 std::map<int, bool>::iterator itr = mKeys.find(key);
209 if(itr == mKeys.end())
210 return 0;
211
212 bool prevState = itr->second;
213 itr->second = down;
214
215 // If there is only one key for this action, wait for key up so it
216 // doesn't trigger with multi-key actions.
217 // Else, check if all buttons are pressed, then consume their release events
218 // so they don't trigger one-button actions and reset mKeys pressed status
219 if(mKeys.size() == 1) {
220 if(!down && prevState)
221 doActions();
222 } else if(down) {
223 for(itr = mKeys.begin(); itr != mKeys.end(); ++itr) {
224 if(!itr->second)
225 return 0;
226 }
227
228 // Passed, all req buttons are pressed, reset them and consume release events
229 HardwareKeyboard *kb = PageManager::GetHardwareKeyboard();
230 for(itr = mKeys.begin(); itr != mKeys.end(); ++itr) {
231 kb->ConsumeKeyRelease(itr->first);
232 itr->second = false;
233 }
234
235 doActions();
236 }
237
Dees_Troy51a0e822012-09-05 15:24:24 -0400238 return 0;
239}
240
Vojtech Bocek07220562014-02-08 02:05:33 +0100241int GUIAction::NotifyVarChange(const std::string& varName, const std::string& value)
Dees_Troy51a0e822012-09-05 15:24:24 -0400242{
Vojtech Bocek07220562014-02-08 02:05:33 +0100243 GUIObject::NotifyVarChange(varName, value);
244
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100245 if (varName.empty() && !isConditionValid() && mKeys.empty() && !mActionW)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200246 doActions();
Vojtech Bocek07220562014-02-08 02:05:33 +0100247 else if((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue())
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200248 doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400249
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200250 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400251}
252
253void GUIAction::simulate_progress_bar(void)
254{
Dees_Troy2673cec2013-04-02 20:22:16 +0000255 gui_print("Simulating actions...\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400256 for (int i = 0; i < 5; i++)
257 {
258 usleep(500000);
259 DataManager::SetValue("ui_progress", i * 20);
260 }
261}
262
that3f7b1ac2014-12-30 11:30:13 +0100263int GUIAction::flash_zip(std::string filename, std::string pageName, int* wipe_cache)
Dees_Troy51a0e822012-09-05 15:24:24 -0400264{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200265 int ret_val = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400266
267 DataManager::SetValue("ui_progress", 0);
268
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200269 if (filename.empty())
270 {
271 LOGERR("No file specified.\n");
272 return -1;
273 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400274
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200275 // We're going to jump to this page first, like a loading page
276 gui_changePage(pageName);
Dees_Troy51a0e822012-09-05 15:24:24 -0400277
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200278 if (!PartitionManager.Mount_By_Path(filename, true))
Dees_Troy657c3092012-09-10 20:32:10 -0400279 return -1;
280
that3f7b1ac2014-12-30 11:30:13 +0100281 // TODO: why again?
Ethan Yonker57e35872014-11-07 14:52:22 -0600282 gui_changePage(pageName);
Dees_Troy51a0e822012-09-05 15:24:24 -0400283
Dees_Troy51a0e822012-09-05 15:24:24 -0400284 if (simulate) {
285 simulate_progress_bar();
286 } else {
Dees_Troy657c3092012-09-10 20:32:10 -0400287 ret_val = TWinstall_zip(filename.c_str(), wipe_cache);
Dees_Troy51a0e822012-09-05 15:24:24 -0400288
289 // Now, check if we need to ensure TWRP remains installed...
290 struct stat st;
291 if (stat("/sbin/installTwrp", &st) == 0)
292 {
293 DataManager::SetValue("tw_operation", "Configuring TWRP");
294 DataManager::SetValue("tw_partition", "");
Dees_Troy2673cec2013-04-02 20:22:16 +0000295 gui_print("Configuring TWRP...\n");
Vojtech Bocek05534202013-09-11 08:11:56 +0200296 if (TWFunc::Exec_Cmd("/sbin/installTwrp reinstall") < 0)
Dees_Troy51a0e822012-09-05 15:24:24 -0400297 {
Dees_Troy2673cec2013-04-02 20:22:16 +0000298 gui_print("Unable to configure TWRP with this kernel.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400299 }
300 }
301 }
302
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200303 // Done
304 DataManager::SetValue("ui_progress", 100);
305 DataManager::SetValue("ui_progress", 0);
306 return ret_val;
Dees_Troy51a0e822012-09-05 15:24:24 -0400307}
308
309int GUIAction::doActions()
310{
that3f7b1ac2014-12-30 11:30:13 +0100311 if (mActions.size() < 1)
312 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400313
that3f7b1ac2014-12-30 11:30:13 +0100314 std::vector<Action>::iterator it;
315 for (it = mActions.begin(); it != mActions.end(); ++it)
316 doAction(*it);
Dees_Troy51a0e822012-09-05 15:24:24 -0400317
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200318 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400319}
320
that3f7b1ac2014-12-30 11:30:13 +0100321int GUIAction::doAction(Action action)
Dees_Troy51a0e822012-09-05 15:24:24 -0400322{
that3f7b1ac2014-12-30 11:30:13 +0100323 DataManager::GetValue(TW_SIMULATE_ACTIONS, simulate);
Dees_Troy51a0e822012-09-05 15:24:24 -0400324
that3f7b1ac2014-12-30 11:30:13 +0100325 std::string function = gui_parse_text(action.mFunction);
326 std::string arg = gui_parse_text(action.mArg);
Dees_Troy51a0e822012-09-05 15:24:24 -0400327
that3f7b1ac2014-12-30 11:30:13 +0100328 // find function and execute it
329 mapFunc::const_iterator funcitr = mf.find(function);
330 if (funcitr != mf.end())
331 return (this->*funcitr->second)(arg);
332
333 LOGERR("Unknown action '%s'\n", function.c_str());
334 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400335}
336
337void GUIAction::operation_start(const string operation_name)
338{
that3f7b1ac2014-12-30 11:30:13 +0100339 LOGINFO("operation_start: '%s'\n", operation_name.c_str());
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000340 time(&Start);
Dees_Troy51a0e822012-09-05 15:24:24 -0400341 DataManager::SetValue(TW_ACTION_BUSY, 1);
342 DataManager::SetValue("ui_progress", 0);
343 DataManager::SetValue("tw_operation", operation_name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400344 DataManager::SetValue("tw_operation_state", 0);
Ethan Yonkerd83c9ea2015-01-02 15:22:31 -0600345 DataManager::SetValue("tw_operation_status", 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400346}
347
that3f7b1ac2014-12-30 11:30:13 +0100348void GUIAction::operation_end(const int operation_status)
Dees_Troy51a0e822012-09-05 15:24:24 -0400349{
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000350 time_t Stop;
Dees_Troy51a0e822012-09-05 15:24:24 -0400351 int simulate_fail;
Dees_Troy51a0e822012-09-05 15:24:24 -0400352 DataManager::SetValue("ui_progress", 100);
353 if (simulate) {
354 DataManager::GetValue(TW_SIMULATE_FAIL, simulate_fail);
355 if (simulate_fail != 0)
356 DataManager::SetValue("tw_operation_status", 1);
357 else
358 DataManager::SetValue("tw_operation_status", 0);
359 } else {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500360 if (operation_status != 0) {
Dees_Troy51a0e822012-09-05 15:24:24 -0400361 DataManager::SetValue("tw_operation_status", 1);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500362 }
363 else {
Dees_Troy51a0e822012-09-05 15:24:24 -0400364 DataManager::SetValue("tw_operation_status", 0);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500365 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400366 }
367 DataManager::SetValue("tw_operation_state", 1);
368 DataManager::SetValue(TW_ACTION_BUSY, 0);
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700369#ifndef TW_NO_SCREEN_TIMEOUT
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500370 blankTimer.resetTimerAndUnblank();
Ricardo Gomezc9ecd442013-07-05 16:13:52 -0700371#endif
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000372 time(&Stop);
373 if ((int) difftime(Stop, Start) > 10)
Ethan Yonker03db3262014-02-05 08:02:06 -0600374 DataManager::Vibrate("tw_action_vibrate");
that3f7b1ac2014-12-30 11:30:13 +0100375 LOGINFO("operation_end - status=%d\n", operation_status);
Dees_Troy51a0e822012-09-05 15:24:24 -0400376}
377
that3f7b1ac2014-12-30 11:30:13 +0100378int GUIAction::reboot(std::string arg)
Dees_Troy51a0e822012-09-05 15:24:24 -0400379{
that3f7b1ac2014-12-30 11:30:13 +0100380 //curtainClose(); this sometimes causes a crash
Dees_Troy51a0e822012-09-05 15:24:24 -0400381
that3f7b1ac2014-12-30 11:30:13 +0100382 sync();
383 DataManager::SetValue("tw_gui_done", 1);
384 DataManager::SetValue("tw_reboot_arg", arg);
Dees_Troy51a0e822012-09-05 15:24:24 -0400385
that3f7b1ac2014-12-30 11:30:13 +0100386 return 0;
387}
Dees_Troy51a0e822012-09-05 15:24:24 -0400388
that3f7b1ac2014-12-30 11:30:13 +0100389int GUIAction::home(std::string arg)
390{
391 PageManager::SelectPackage("TWRP");
392 gui_changePage("main");
393 return 0;
394}
Dees_Troy51a0e822012-09-05 15:24:24 -0400395
that3f7b1ac2014-12-30 11:30:13 +0100396int GUIAction::key(std::string arg)
397{
398 const int key = getKeyByName(arg);
399 PageManager::NotifyKey(key, true);
400 PageManager::NotifyKey(key, false);
401 return 0;
402}
403
404int GUIAction::page(std::string arg)
405{
406 std::string page_name = gui_parse_text(arg);
407 return gui_changePage(page_name);
408}
409
410int GUIAction::reload(std::string arg)
411{
412 int check = 0, ret_val = 0;
413 std::string theme_path;
414
415 operation_start("Reload Theme");
416 theme_path = DataManager::GetSettingsStoragePath();
417 if (PartitionManager.Mount_By_Path(theme_path.c_str(), 1) < 0) {
418 LOGERR("Unable to mount %s during reload function startup.\n", theme_path.c_str());
419 check = 1;
420 }
421
422 theme_path += "/TWRP/theme/ui.zip";
423 if (check != 0 || PageManager::ReloadPackage("TWRP", theme_path) != 0)
Dees_Troy6ef66352013-02-21 08:26:57 -0600424 {
that3f7b1ac2014-12-30 11:30:13 +0100425 // Loading the custom theme failed - try loading the stock theme
426 LOGINFO("Attempting to reload stock theme...\n");
427 if (PageManager::ReloadPackage("TWRP", "/res/ui.xml"))
Dees_Troy51a0e822012-09-05 15:24:24 -0400428 {
that3f7b1ac2014-12-30 11:30:13 +0100429 LOGERR("Failed to load base packages.\n");
430 ret_val = 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400431 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400432 }
that3f7b1ac2014-12-30 11:30:13 +0100433 operation_end(ret_val);
434 return 0;
435}
Dees_Troy51a0e822012-09-05 15:24:24 -0400436
that3f7b1ac2014-12-30 11:30:13 +0100437int GUIAction::readBackup(std::string arg)
438{
439 string Restore_Name;
440 DataManager::GetValue("tw_restore", Restore_Name);
441 PartitionManager.Set_Restore_Files(Restore_Name);
442 return 0;
443}
444
445int GUIAction::set(std::string arg)
446{
447 if (arg.find('=') != string::npos)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200448 {
that3f7b1ac2014-12-30 11:30:13 +0100449 string varName = arg.substr(0, arg.find('='));
450 string value = arg.substr(arg.find('=') + 1, string::npos);
Dees_Troy51a0e822012-09-05 15:24:24 -0400451
that3f7b1ac2014-12-30 11:30:13 +0100452 DataManager::GetValue(value, value);
453 DataManager::SetValue(varName, value);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200454 }
that3f7b1ac2014-12-30 11:30:13 +0100455 else
456 DataManager::SetValue(arg, "1");
457 return 0;
458}
Dees_Troy51a0e822012-09-05 15:24:24 -0400459
that3f7b1ac2014-12-30 11:30:13 +0100460int GUIAction::clear(std::string arg)
461{
462 DataManager::SetValue(arg, "0");
463 return 0;
464}
Dees_Troy51a0e822012-09-05 15:24:24 -0400465
that3f7b1ac2014-12-30 11:30:13 +0100466int GUIAction::mount(std::string arg)
467{
468 if (arg == "usb") {
469 DataManager::SetValue(TW_ACTION_BUSY, 1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400470 if (!simulate)
that3f7b1ac2014-12-30 11:30:13 +0100471 PartitionManager.usb_storage_enable();
472 else
473 gui_print("Simulating actions...\n");
474 } else if (!simulate) {
475 PartitionManager.Mount_By_Path(arg, true);
476 PartitionManager.Add_MTP_Storage(arg);
477 } else
478 gui_print("Simulating actions...\n");
479 return 0;
480}
481
482int GUIAction::unmount(std::string arg)
483{
484 if (arg == "usb") {
485 if (!simulate)
486 PartitionManager.usb_storage_disable();
487 else
488 gui_print("Simulating actions...\n");
489 DataManager::SetValue(TW_ACTION_BUSY, 0);
490 } else if (!simulate) {
491 PartitionManager.UnMount_By_Path(arg, true);
492 } else
493 gui_print("Simulating actions...\n");
494 return 0;
495}
496
497int GUIAction::restoredefaultsettings(std::string arg)
498{
499 operation_start("Restore Defaults");
500 if (simulate) // Simulated so that people don't accidently wipe out the "simulation is on" setting
501 gui_print("Simulating actions...\n");
502 else {
503 DataManager::ResetDefaults();
504 PartitionManager.Update_System_Details();
505 PartitionManager.Mount_Current_Storage(true);
506 }
507 operation_end(0);
508 return 0;
509}
510
511int GUIAction::copylog(std::string arg)
512{
513 operation_start("Copy Log");
514 if (!simulate)
515 {
516 string dst;
517 PartitionManager.Mount_Current_Storage(true);
518 dst = DataManager::GetCurrentStoragePath() + "/recovery.log";
519 TWFunc::copy_file("/tmp/recovery.log", dst.c_str(), 0755);
520 tw_set_default_metadata(dst.c_str());
521 sync();
522 gui_print("Copied recovery log to %s.\n", DataManager::GetCurrentStoragePath().c_str());
523 } else
524 simulate_progress_bar();
525 operation_end(0);
526 return 0;
527}
528
529
530int GUIAction::compute(std::string arg)
531{
532 if (arg.find("+") != string::npos)
533 {
534 string varName = arg.substr(0, arg.find('+'));
535 string string_to_add = arg.substr(arg.find('+') + 1, string::npos);
536 int amount_to_add = atoi(string_to_add.c_str());
537 int value;
538
539 DataManager::GetValue(varName, value);
540 DataManager::SetValue(varName, value + amount_to_add);
Dees_Troy51a0e822012-09-05 15:24:24 -0400541 return 0;
542 }
that3f7b1ac2014-12-30 11:30:13 +0100543 if (arg.find("-") != string::npos)
Dees_Troy51a0e822012-09-05 15:24:24 -0400544 {
that3f7b1ac2014-12-30 11:30:13 +0100545 string varName = arg.substr(0, arg.find('-'));
546 string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos);
547 int amount_to_subtract = atoi(string_to_subtract.c_str());
548 int value;
Dees_Troy51a0e822012-09-05 15:24:24 -0400549
that3f7b1ac2014-12-30 11:30:13 +0100550 DataManager::GetValue(varName, value);
551 value -= amount_to_subtract;
552 if (value <= 0)
553 value = 0;
554 DataManager::SetValue(varName, value);
555 return 0;
556 }
557 if (arg.find("*") != string::npos)
558 {
559 string varName = arg.substr(0, arg.find('*'));
560 string multiply_by_str = gui_parse_text(arg.substr(arg.find('*') + 1, string::npos));
561 int multiply_by = atoi(multiply_by_str.c_str());
562 int value;
563
564 DataManager::GetValue(varName, value);
565 DataManager::SetValue(varName, value*multiply_by);
566 return 0;
567 }
568 if (arg.find("/") != string::npos)
569 {
570 string varName = arg.substr(0, arg.find('/'));
571 string divide_by_str = gui_parse_text(arg.substr(arg.find('/') + 1, string::npos));
572 int divide_by = atoi(divide_by_str.c_str());
573 int value;
574
575 if(divide_by != 0)
576 {
Dees_Troy51a0e822012-09-05 15:24:24 -0400577 DataManager::GetValue(varName, value);
that3f7b1ac2014-12-30 11:30:13 +0100578 DataManager::SetValue(varName, value/divide_by);
Dees_Troy51a0e822012-09-05 15:24:24 -0400579 }
580 return 0;
581 }
that3f7b1ac2014-12-30 11:30:13 +0100582 LOGERR("Unable to perform compute '%s'\n", arg.c_str());
583 return -1;
584}
Dees_Troy51a0e822012-09-05 15:24:24 -0400585
that3f7b1ac2014-12-30 11:30:13 +0100586int GUIAction::setguitimezone(std::string arg)
587{
588 string SelectedZone;
589 DataManager::GetValue(TW_TIME_ZONE_GUISEL, SelectedZone); // read the selected time zone into SelectedZone
590 string Zone = SelectedZone.substr(0, SelectedZone.find(';')); // parse to get time zone
591 string DSTZone = SelectedZone.substr(SelectedZone.find(';') + 1, string::npos); // parse to get DST component
592
593 int dst;
594 DataManager::GetValue(TW_TIME_ZONE_GUIDST, dst); // check wether user chose to use DST
595
596 string offset;
597 DataManager::GetValue(TW_TIME_ZONE_GUIOFFSET, offset); // pull in offset
598
599 string NewTimeZone = Zone;
600 if (offset != "0")
601 NewTimeZone += ":" + offset;
602
603 if (dst != 0)
604 NewTimeZone += DSTZone;
605
606 DataManager::SetValue(TW_TIME_ZONE_VAR, NewTimeZone);
607 DataManager::update_tz_environment_variables();
608 return 0;
609}
610
611int GUIAction::overlay(std::string arg)
612{
613 return gui_changeOverlay(arg);
614}
615
616int GUIAction::queuezip(std::string arg)
617{
618 if (zip_queue_index >= 10) {
619 gui_print("Maximum zip queue reached!\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400620 return 0;
621 }
that3f7b1ac2014-12-30 11:30:13 +0100622 DataManager::GetValue("tw_filename", zip_queue[zip_queue_index]);
623 if (strlen(zip_queue[zip_queue_index].c_str()) > 0) {
624 zip_queue_index++;
Dees_Troy51a0e822012-09-05 15:24:24 -0400625 DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
that3f7b1ac2014-12-30 11:30:13 +0100626 }
627 return 0;
628}
629
630int GUIAction::cancelzip(std::string arg)
631{
632 if (zip_queue_index <= 0) {
633 gui_print("Minimum zip queue reached!\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400634 return 0;
that3f7b1ac2014-12-30 11:30:13 +0100635 } else {
636 zip_queue_index--;
637 DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
Dees_Troy51a0e822012-09-05 15:24:24 -0400638 }
that3f7b1ac2014-12-30 11:30:13 +0100639 return 0;
640}
Dees_Troy51a0e822012-09-05 15:24:24 -0400641
that3f7b1ac2014-12-30 11:30:13 +0100642int GUIAction::queueclear(std::string arg)
643{
644 zip_queue_index = 0;
645 DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
646 return 0;
647}
Dees_Troy51a0e822012-09-05 15:24:24 -0400648
that3f7b1ac2014-12-30 11:30:13 +0100649int GUIAction::sleep(std::string arg)
650{
651 operation_start("Sleep");
652 usleep(atoi(arg.c_str()));
653 operation_end(0);
654 return 0;
655}
Dees Troyb21cc642013-09-10 17:36:41 +0000656
that3f7b1ac2014-12-30 11:30:13 +0100657int GUIAction::appenddatetobackupname(std::string arg)
658{
659 operation_start("AppendDateToBackupName");
660 string Backup_Name;
661 DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
662 Backup_Name += TWFunc::Get_Current_Date();
663 if (Backup_Name.size() > MAX_BACKUP_NAME_LEN)
664 Backup_Name.resize(MAX_BACKUP_NAME_LEN);
665 DataManager::SetValue(TW_BACKUP_NAME, Backup_Name);
666 operation_end(0);
667 return 0;
668}
Ethan Yonker87c7bac2014-05-25 21:41:08 -0500669
that3f7b1ac2014-12-30 11:30:13 +0100670int GUIAction::generatebackupname(std::string arg)
671{
672 operation_start("GenerateBackupName");
673 TWFunc::Auto_Generate_Backup_Name();
674 operation_end(0);
675 return 0;
676}
Ethan Yonker87c7bac2014-05-25 21:41:08 -0500677
that3f7b1ac2014-12-30 11:30:13 +0100678int GUIAction::checkpartitionlist(std::string arg)
679{
680 string Wipe_List, wipe_path;
681 int count = 0;
Ethan Yonker87c7bac2014-05-25 21:41:08 -0500682
that3f7b1ac2014-12-30 11:30:13 +0100683 DataManager::GetValue("tw_wipe_list", Wipe_List);
684 LOGINFO("checkpartitionlist list '%s'\n", Wipe_List.c_str());
685 if (!Wipe_List.empty()) {
686 size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos);
687 while (end_pos != string::npos && start_pos < Wipe_List.size()) {
688 wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos);
689 LOGINFO("checkpartitionlist wipe_path '%s'\n", wipe_path.c_str());
690 if (wipe_path == "/and-sec" || wipe_path == "DALVIK" || wipe_path == "INTERNAL") {
691 // Do nothing
Dees_Troy51a0e822012-09-05 15:24:24 -0400692 } else {
that3f7b1ac2014-12-30 11:30:13 +0100693 count++;
694 }
695 start_pos = end_pos + 1;
696 end_pos = Wipe_List.find(";", start_pos);
697 }
698 DataManager::SetValue("tw_check_partition_list", count);
699 } else {
700 DataManager::SetValue("tw_check_partition_list", 0);
701 }
702 return 0;
703}
Dees_Troy51a0e822012-09-05 15:24:24 -0400704
that3f7b1ac2014-12-30 11:30:13 +0100705int GUIAction::getpartitiondetails(std::string arg)
706{
707 string Wipe_List, wipe_path;
708 int count = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400709
that3f7b1ac2014-12-30 11:30:13 +0100710 DataManager::GetValue("tw_wipe_list", Wipe_List);
711 LOGINFO("getpartitiondetails list '%s'\n", Wipe_List.c_str());
712 if (!Wipe_List.empty()) {
713 size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos);
714 while (end_pos != string::npos && start_pos < Wipe_List.size()) {
715 wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos);
716 LOGINFO("getpartitiondetails wipe_path '%s'\n", wipe_path.c_str());
717 if (wipe_path == "/and-sec" || wipe_path == "DALVIK" || wipe_path == "INTERNAL") {
718 // Do nothing
719 } else {
720 DataManager::SetValue("tw_partition_path", wipe_path);
721 break;
722 }
723 start_pos = end_pos + 1;
724 end_pos = Wipe_List.find(";", start_pos);
725 }
726 if (!wipe_path.empty()) {
727 TWPartition* Part = PartitionManager.Find_Partition_By_Path(wipe_path);
728 if (Part) {
729 unsigned long long mb = 1048576;
Dees_Troya13d74f2013-03-24 08:54:55 -0500730
that3f7b1ac2014-12-30 11:30:13 +0100731 DataManager::SetValue("tw_partition_name", Part->Display_Name);
732 DataManager::SetValue("tw_partition_mount_point", Part->Mount_Point);
733 DataManager::SetValue("tw_partition_file_system", Part->Current_File_System);
734 DataManager::SetValue("tw_partition_size", Part->Size / mb);
735 DataManager::SetValue("tw_partition_used", Part->Used / mb);
736 DataManager::SetValue("tw_partition_free", Part->Free / mb);
737 DataManager::SetValue("tw_partition_backup_size", Part->Backup_Size / mb);
738 DataManager::SetValue("tw_partition_removable", Part->Removable);
739 DataManager::SetValue("tw_partition_is_present", Part->Is_Present);
740
741 if (Part->Can_Repair())
742 DataManager::SetValue("tw_partition_can_repair", 1);
743 else
744 DataManager::SetValue("tw_partition_can_repair", 0);
745 if (TWFunc::Path_Exists("/sbin/mkdosfs"))
746 DataManager::SetValue("tw_partition_vfat", 1);
747 else
748 DataManager::SetValue("tw_partition_vfat", 0);
749 if (TWFunc::Path_Exists("/sbin/mkfs.exfat"))
750 DataManager::SetValue("tw_partition_exfat", 1);
751 else
752 DataManager::SetValue("tw_partition_exfat", 0);
753 if (TWFunc::Path_Exists("/sbin/mkfs.f2fs"))
754 DataManager::SetValue("tw_partition_f2fs", 1);
755 else
756 DataManager::SetValue("tw_partition_f2fs", 0);
757 if (TWFunc::Path_Exists("/sbin/mke2fs"))
758 DataManager::SetValue("tw_partition_ext", 1);
759 else
760 DataManager::SetValue("tw_partition_ext", 0);
761 return 0;
762 } else {
763 LOGERR("Unable to locate partition: '%s'\n", wipe_path.c_str());
764 }
765 }
766 }
767 DataManager::SetValue("tw_partition_name", "");
768 DataManager::SetValue("tw_partition_file_system", "");
769 return 0;
770}
771
772int GUIAction::screenshot(std::string arg)
773{
774 time_t tm;
775 char path[256];
776 int path_len;
777 uid_t uid = -1;
778 gid_t gid = -1;
779
780 struct passwd *pwd = getpwnam("media_rw");
781 if(pwd) {
782 uid = pwd->pw_uid;
783 gid = pwd->pw_gid;
784 }
785
786 const std::string storage = DataManager::GetCurrentStoragePath();
787 if(PartitionManager.Is_Mounted_By_Path(storage)) {
788 snprintf(path, sizeof(path), "%s/Pictures/Screenshots/", storage.c_str());
789 } else {
790 strcpy(path, "/tmp/");
791 }
792
793 if(!TWFunc::Create_Dir_Recursive(path, 0666, uid, gid))
794 return 0;
795
796 tm = time(NULL);
797 path_len = strlen(path);
798
799 // Screenshot_2014-01-01-18-21-38.png
800 strftime(path+path_len, sizeof(path)-path_len, "Screenshot_%Y-%m-%d-%H-%M-%S.png", localtime(&tm));
801
802 int res = gr_save_screenshot(path);
803 if(res == 0) {
804 chmod(path, 0666);
805 chown(path, uid, gid);
806
807 gui_print("Screenshot was saved to %s\n", path);
808
809 // blink to notify that the screenshow was taken
810 gr_color(255, 255, 255, 255);
811 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
812 gr_flip();
813 gui_forceRender();
814 } else {
815 LOGERR("Failed to take a screenshot!\n");
816 }
817 return 0;
818}
819
820int GUIAction::setbrightness(std::string arg)
821{
822 return TWFunc::Set_Brightness(arg);
823}
824
825int GUIAction::fileexists(std::string arg)
826{
827 struct stat st;
828 string newpath = arg + "/.";
829
830 operation_start("FileExists");
831 if (stat(arg.c_str(), &st) == 0 || stat(newpath.c_str(), &st) == 0)
832 operation_end(0);
833 else
834 operation_end(1);
835 return 0;
836}
837
thatcc8ddca2015-01-03 01:59:36 +0100838void GUIAction::reinject_after_flash()
839{
840 if (DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) {
841 operation_start("ReinjectTWRP");
842 gui_print("Injecting TWRP into boot image...\n");
843 if (simulate) {
844 simulate_progress_bar();
845 } else {
846 TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
847 if (Boot == NULL || Boot->Current_File_System != "emmc")
848 TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
849 else {
850 string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device;
851 TWFunc::Exec_Cmd(injectcmd);
852 }
853 gui_print("TWRP injection complete.\n");
854 }
855 }
856}
857
that3f7b1ac2014-12-30 11:30:13 +0100858int GUIAction::flash(std::string arg)
859{
860 int i, ret_val = 0, wipe_cache = 0;
861 for (i=0; i<zip_queue_index; i++) {
862 operation_start("Flashing");
863 DataManager::SetValue("tw_filename", zip_queue[i]);
864 DataManager::SetValue(TW_ZIP_INDEX, (i + 1));
865
866 TWFunc::SetPerformanceMode(true);
867 ret_val = flash_zip(zip_queue[i], arg, &wipe_cache);
868 TWFunc::SetPerformanceMode(false);
869 if (ret_val != 0) {
870 gui_print("Error flashing zip '%s'\n", zip_queue[i].c_str());
871 i = 10; // Error flashing zip - exit queue
872 ret_val = 1;
873 }
874 }
875 zip_queue_index = 0;
876 DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
877
878 if (wipe_cache)
879 PartitionManager.Wipe_By_Path("/cache");
880
thatcc8ddca2015-01-03 01:59:36 +0100881 reinject_after_flash();
that3f7b1ac2014-12-30 11:30:13 +0100882 PartitionManager.Update_System_Details();
883 operation_end(ret_val);
884 return 0;
885}
886
887int GUIAction::wipe(std::string arg)
888{
889 operation_start("Format");
890 DataManager::SetValue("tw_partition", arg);
891
892 int ret_val = false;
893
894 if (simulate) {
895 simulate_progress_bar();
896 } else {
897 if (arg == "data")
898 ret_val = PartitionManager.Factory_Reset();
899 else if (arg == "battery")
900 ret_val = PartitionManager.Wipe_Battery_Stats();
901 else if (arg == "rotate")
902 ret_val = PartitionManager.Wipe_Rotate_Data();
903 else if (arg == "dalvik")
904 ret_val = PartitionManager.Wipe_Dalvik_Cache();
905 else if (arg == "DATAMEDIA") {
906 ret_val = PartitionManager.Format_Data();
907 } else if (arg == "INTERNAL") {
908 int has_datamedia, dual_storage;
909
910 DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia);
911 if (has_datamedia) {
912 ret_val = PartitionManager.Wipe_Media_From_Data();
913 } else {
914 ret_val = PartitionManager.Wipe_By_Path(DataManager::GetSettingsStoragePath());
915 }
916 } else if (arg == "EXTERNAL") {
917 string External_Path;
918
919 DataManager::GetValue(TW_EXTERNAL_PATH, External_Path);
920 ret_val = PartitionManager.Wipe_By_Path(External_Path);
921 } else if (arg == "ANDROIDSECURE") {
922 ret_val = PartitionManager.Wipe_Android_Secure();
923 } else if (arg == "LIST") {
924 string Wipe_List, wipe_path;
925 bool skip = false;
926 ret_val = true;
927 TWPartition* wipe_part = NULL;
928
929 DataManager::GetValue("tw_wipe_list", Wipe_List);
930 LOGINFO("wipe list '%s'\n", Wipe_List.c_str());
931 if (!Wipe_List.empty()) {
932 size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos);
933 while (end_pos != string::npos && start_pos < Wipe_List.size()) {
934 wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos);
935 LOGINFO("wipe_path '%s'\n", wipe_path.c_str());
936 if (wipe_path == "/and-sec") {
937 if (!PartitionManager.Wipe_Android_Secure()) {
938 LOGERR("Unable to wipe android secure\n");
939 ret_val = false;
940 break;
941 } else {
942 skip = true;
943 }
944 } else if (wipe_path == "DALVIK") {
945 if (!PartitionManager.Wipe_Dalvik_Cache()) {
946 LOGERR("Failed to wipe dalvik\n");
947 ret_val = false;
948 break;
949 } else {
950 skip = true;
951 }
952 } else if (wipe_path == "INTERNAL") {
953 if (!PartitionManager.Wipe_Media_From_Data()) {
954 ret_val = false;
955 break;
956 } else {
957 skip = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500958 }
959 }
that3f7b1ac2014-12-30 11:30:13 +0100960 if (!skip) {
961 if (!PartitionManager.Wipe_By_Path(wipe_path)) {
962 LOGERR("Unable to wipe '%s'\n", wipe_path.c_str());
963 ret_val = false;
964 break;
965 } else if (wipe_path == DataManager::GetSettingsStoragePath()) {
966 arg = wipe_path;
967 }
Dees_Troy38bd7602012-09-14 13:33:53 -0400968 } else {
that3f7b1ac2014-12-30 11:30:13 +0100969 skip = false;
Dees_Troy38bd7602012-09-14 13:33:53 -0400970 }
that3f7b1ac2014-12-30 11:30:13 +0100971 start_pos = end_pos + 1;
972 end_pos = Wipe_List.find(";", start_pos);
Dees_Troy51a0e822012-09-05 15:24:24 -0400973 }
974 }
that3f7b1ac2014-12-30 11:30:13 +0100975 } else
976 ret_val = PartitionManager.Wipe_By_Path(arg);
977#ifdef TW_OEM_BUILD
978 if (arg == DataManager::GetSettingsStoragePath()) {
979 // If we wiped the settings storage path, recreate the TWRP folder and dump the settings
980 string Storage_Path = DataManager::GetSettingsStoragePath();
Dees_Troy51a0e822012-09-05 15:24:24 -0400981
that3f7b1ac2014-12-30 11:30:13 +0100982 if (PartitionManager.Mount_By_Path(Storage_Path, true)) {
983 LOGINFO("Making TWRP folder and saving settings.\n");
984 Storage_Path += "/TWRP";
985 mkdir(Storage_Path.c_str(), 0777);
986 DataManager::Flush();
Dees_Troy51a0e822012-09-05 15:24:24 -0400987 } else {
that3f7b1ac2014-12-30 11:30:13 +0100988 LOGERR("Unable to recreate TWRP folder and save settings.\n");
989 }
990 }
991#endif
992 }
993 PartitionManager.Update_System_Details();
994 if (ret_val)
995 ret_val = 0; // 0 is success
996 else
997 ret_val = 1; // 1 is failure
998 operation_end(ret_val);
999 return 0;
1000}
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +00001001
that3f7b1ac2014-12-30 11:30:13 +01001002int GUIAction::refreshsizes(std::string arg)
1003{
1004 operation_start("Refreshing Sizes");
1005 if (simulate) {
1006 simulate_progress_bar();
1007 } else
1008 PartitionManager.Update_System_Details();
1009 operation_end(0);
1010 return 0;
1011}
1012
1013int GUIAction::nandroid(std::string arg)
1014{
1015 operation_start("Nandroid");
1016 int ret = 0;
1017
1018 if (simulate) {
1019 DataManager::SetValue("tw_partition", "Simulation");
1020 simulate_progress_bar();
1021 } else {
1022 if (arg == "backup") {
1023 string Backup_Name;
1024 DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
1025 if (Backup_Name == "(Auto Generate)" || Backup_Name == "(Current Date)" || Backup_Name == "0" || Backup_Name == "(" || PartitionManager.Check_Backup_Name(true) == 0) {
1026 ret = PartitionManager.Run_Backup();
1027 }
1028 else {
1029 operation_end(1);
1030 return -1;
1031
1032 }
1033 DataManager::SetValue(TW_BACKUP_NAME, "(Auto Generate)");
1034 } else if (arg == "restore") {
1035 string Restore_Name;
1036 DataManager::GetValue("tw_restore", Restore_Name);
1037 ret = PartitionManager.Run_Restore(Restore_Name);
1038 } else {
1039 operation_end(1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001040 return -1;
1041 }
1042 }
Dees_Troy83bd4832013-05-04 12:39:56 +00001043 DataManager::SetValue("tw_encrypt_backup", 0);
Dees_Troy43d8b002012-09-17 16:00:01 -04001044 if (ret == false)
1045 ret = 1; // 1 for failure
1046 else
1047 ret = 0; // 0 for success
that3f7b1ac2014-12-30 11:30:13 +01001048 operation_end(ret);
Dees_Troy83bd4832013-05-04 12:39:56 +00001049 return 0;
that3f7b1ac2014-12-30 11:30:13 +01001050}
Dees_Troy51a0e822012-09-05 15:24:24 -04001051
that3f7b1ac2014-12-30 11:30:13 +01001052int GUIAction::fixpermissions(std::string arg)
1053{
1054 operation_start("Fix Permissions");
1055 LOGINFO("fix permissions started!\n");
1056 if (simulate) {
1057 simulate_progress_bar();
1058 } else {
1059 int op_status = PartitionManager.Fix_Permissions();
1060 if (op_status != 0)
1061 op_status = 1; // failure
1062 operation_end(op_status);
1063 }
1064 return 0;
1065}
1066
1067int GUIAction::dd(std::string arg)
1068{
1069 operation_start("imaging");
1070
1071 if (simulate) {
1072 simulate_progress_bar();
1073 } else {
1074 string cmd = "dd " + arg;
1075 TWFunc::Exec_Cmd(cmd);
1076 }
1077 operation_end(0);
1078 return 0;
1079}
1080
1081int GUIAction::partitionsd(std::string arg)
1082{
1083 operation_start("Partition SD Card");
1084 int ret_val = 0;
1085
1086 if (simulate) {
1087 simulate_progress_bar();
1088 } else {
1089 int allow_partition;
1090 DataManager::GetValue(TW_ALLOW_PARTITION_SDCARD, allow_partition);
1091 if (allow_partition == 0) {
1092 gui_print("This device does not have a real SD Card!\nAborting!\n");
1093 } else {
1094 if (!PartitionManager.Partition_SDCard())
1095 ret_val = 1; // failed
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001096 }
that3f7b1ac2014-12-30 11:30:13 +01001097 }
1098 operation_end(ret_val);
1099 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -04001100
that3f7b1ac2014-12-30 11:30:13 +01001101}
Dees_Troy51a0e822012-09-05 15:24:24 -04001102
that3f7b1ac2014-12-30 11:30:13 +01001103int GUIAction::installhtcdumlock(std::string arg)
1104{
1105 operation_start("Install HTC Dumlock");
1106 if (simulate) {
1107 simulate_progress_bar();
1108 } else
1109 TWFunc::install_htc_dumlock();
Dees_Troy51a0e822012-09-05 15:24:24 -04001110
that3f7b1ac2014-12-30 11:30:13 +01001111 operation_end(0);
1112 return 0;
1113}
Dees_Troy51a0e822012-09-05 15:24:24 -04001114
that3f7b1ac2014-12-30 11:30:13 +01001115int GUIAction::htcdumlockrestoreboot(std::string arg)
1116{
1117 operation_start("HTC Dumlock Restore Boot");
1118 if (simulate) {
1119 simulate_progress_bar();
1120 } else
1121 TWFunc::htc_dumlock_restore_original_boot();
Dees_Troy51a0e822012-09-05 15:24:24 -04001122
that3f7b1ac2014-12-30 11:30:13 +01001123 operation_end(0);
1124 return 0;
1125}
Dees_Troy51a0e822012-09-05 15:24:24 -04001126
that3f7b1ac2014-12-30 11:30:13 +01001127int GUIAction::htcdumlockreflashrecovery(std::string arg)
1128{
1129 operation_start("HTC Dumlock Reflash Recovery");
1130 if (simulate) {
1131 simulate_progress_bar();
1132 } else
1133 TWFunc::htc_dumlock_reflash_recovery_to_boot();
Dees_Troy51a0e822012-09-05 15:24:24 -04001134
that3f7b1ac2014-12-30 11:30:13 +01001135 operation_end(0);
1136 return 0;
1137}
Dees_Troy51a0e822012-09-05 15:24:24 -04001138
that3f7b1ac2014-12-30 11:30:13 +01001139int GUIAction::cmd(std::string arg)
1140{
1141 int op_status = 0;
1142
1143 operation_start("Command");
1144 LOGINFO("Running command: '%s'\n", arg.c_str());
1145 if (simulate) {
1146 simulate_progress_bar();
1147 } else {
1148 op_status = TWFunc::Exec_Cmd(arg);
1149 if (op_status != 0)
1150 op_status = 1;
1151 }
1152
1153 operation_end(op_status);
1154 return 0;
1155}
1156
1157int GUIAction::terminalcommand(std::string arg)
1158{
1159 int op_status = 0;
1160 string cmdpath, command;
1161
1162 DataManager::GetValue("tw_terminal_location", cmdpath);
1163 operation_start("CommandOutput");
1164 gui_print("%s # %s\n", cmdpath.c_str(), arg.c_str());
1165 if (simulate) {
1166 simulate_progress_bar();
1167 operation_end(op_status);
1168 } else {
1169 command = "cd \"" + cmdpath + "\" && " + arg + " 2>&1";;
1170 LOGINFO("Actual command is: '%s'\n", command.c_str());
1171 DataManager::SetValue("tw_terminal_command_thread", command);
1172 DataManager::SetValue("tw_terminal_state", 1);
1173 DataManager::SetValue("tw_background_thread_running", 1);
1174 op_status = pthread_create(&terminal_command, NULL, command_thread, NULL);
1175 if (op_status != 0) {
1176 LOGERR("Error starting terminal command thread, %i.\n", op_status);
Dees_Troy51a0e822012-09-05 15:24:24 -04001177 DataManager::SetValue("tw_terminal_state", 0);
1178 DataManager::SetValue("tw_background_thread_running", 0);
that3f7b1ac2014-12-30 11:30:13 +01001179 operation_end(1);
Dees_Troy51a0e822012-09-05 15:24:24 -04001180 }
that3f7b1ac2014-12-30 11:30:13 +01001181 }
1182 return 0;
1183}
1184
1185int GUIAction::killterminal(std::string arg)
1186{
1187 int op_status = 0;
1188
1189 LOGINFO("Sending kill command...\n");
1190 operation_start("KillCommand");
1191 DataManager::SetValue("tw_operation_status", 0);
1192 DataManager::SetValue("tw_operation_state", 1);
1193 DataManager::SetValue("tw_terminal_state", 0);
1194 DataManager::SetValue("tw_background_thread_running", 0);
1195 DataManager::SetValue(TW_ACTION_BUSY, 0);
1196 return 0;
1197}
1198
1199int GUIAction::reinjecttwrp(std::string arg)
1200{
1201 int op_status = 0;
1202 operation_start("ReinjectTWRP");
1203 gui_print("Injecting TWRP into boot image...\n");
1204 if (simulate) {
1205 simulate_progress_bar();
1206 } else {
1207 TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
1208 gui_print("TWRP injection complete.\n");
1209 }
1210
1211 operation_end(op_status);
1212 return 0;
1213}
1214
1215int GUIAction::checkbackupname(std::string arg)
1216{
1217 int op_status = 0;
1218
1219 operation_start("CheckBackupName");
1220 if (simulate) {
1221 simulate_progress_bar();
1222 } else {
1223 op_status = PartitionManager.Check_Backup_Name(true);
1224 if (op_status != 0)
1225 op_status = 1;
1226 }
1227
1228 operation_end(op_status);
1229 return 0;
1230}
1231
1232int GUIAction::decrypt(std::string arg)
1233{
1234 int op_status = 0;
1235
1236 operation_start("Decrypt");
1237 if (simulate) {
1238 simulate_progress_bar();
1239 } else {
1240 string Password;
1241 DataManager::GetValue("tw_crypto_password", Password);
1242 op_status = PartitionManager.Decrypt_Device(Password);
1243 if (op_status != 0)
1244 op_status = 1;
1245 else {
1246 int load_theme = 1;
1247
1248 DataManager::SetValue(TW_IS_ENCRYPTED, 0);
1249
1250 if (load_theme) {
1251 int has_datamedia;
1252
1253 // Check for a custom theme and load it if exists
1254 DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia);
1255 if (has_datamedia != 0) {
1256 struct stat st;
1257 int check = 0;
1258 std::string theme_path;
1259
1260 if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) {
1261 LOGERR("Failed to get default contexts and file mode for storage files.\n");
1262 } else {
1263 LOGINFO("Got default contexts and file mode for storage files.\n");
1264 }
1265
1266 theme_path = DataManager::GetSettingsStoragePath();
1267 if (PartitionManager.Mount_By_Path(theme_path.c_str(), 1) < 0) {
1268 LOGERR("Unable to mount %s during reload function startup.\n", theme_path.c_str());
1269 check = 1;
1270 }
1271
1272 theme_path += "/TWRP/theme/ui.zip";
1273 if (check == 0 && stat(theme_path.c_str(), &st) == 0) {
1274 if (PageManager::ReloadPackage("TWRP", theme_path) != 0)
1275 {
1276 // Loading the custom theme failed - try loading the stock theme
1277 LOGINFO("Attempting to reload stock theme...\n");
1278 if (PageManager::ReloadPackage("TWRP", "/res/ui.xml"))
1279 {
1280 LOGERR("Failed to load base packages.\n");
1281 }
1282 }
1283 }
1284 }
1285 }
1286 }
1287 }
1288
1289 operation_end(op_status);
1290 return 0;
1291}
1292
thatcc8ddca2015-01-03 01:59:36 +01001293void* GUIAction::sideload_thread_fn(void *cookie)
that3f7b1ac2014-12-30 11:30:13 +01001294{
thatcc8ddca2015-01-03 01:59:36 +01001295 gui_print("Starting ADB sideload feature...\n");
1296 bool mtp_was_enabled = TWFunc::Toggle_MTP(false);
1297 GUIAction* this_ = (GUIAction*) cookie;
that3f7b1ac2014-12-30 11:30:13 +01001298
thatcc8ddca2015-01-03 01:59:36 +01001299 // wait for the adb connection
1300 int ret = apply_from_adb("/", &sideload_child_pid);
1301 DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui now that the zip install is going to start
1302
1303 if (ret != 0) {
1304 if (ret == -2)
1305 gui_print("You need adb 1.0.32 or newer to sideload to this device.\n");
1306 ret = 1; // failure
that3f7b1ac2014-12-30 11:30:13 +01001307 } else {
1308 int wipe_cache = 0;
1309 int wipe_dalvik = 0;
that3f7b1ac2014-12-30 11:30:13 +01001310 DataManager::GetValue("tw_wipe_dalvik", wipe_dalvik);
thatcc8ddca2015-01-03 01:59:36 +01001311
1312 if (TWinstall_zip(FUSE_SIDELOAD_HOST_PATHNAME, &wipe_cache) == 0) {
1313 if (wipe_cache || DataManager::GetIntValue("tw_wipe_cache"))
1314 PartitionManager.Wipe_By_Path("/cache");
1315 if (wipe_dalvik)
1316 PartitionManager.Wipe_Dalvik_Cache();
that3f7b1ac2014-12-30 11:30:13 +01001317 } else {
thatcc8ddca2015-01-03 01:59:36 +01001318 ret = 1; // failure
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04001319 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001320 }
thatcc8ddca2015-01-03 01:59:36 +01001321 if (sideload_child_pid) {
1322 LOGINFO("Signaling child sideload process to exit.\n");
1323 struct stat st;
1324 // Calling stat() on this magic filename signals the minadbd
1325 // subprocess to shut down.
1326 stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st);
1327 int status;
1328 LOGINFO("Waiting for child sideload process to exit.\n");
1329 waitpid(sideload_child_pid, &status, 0);
1330 }
1331
1332 TWFunc::Toggle_MTP(mtp_was_enabled);
1333 this_->reinject_after_flash();
1334 this_->operation_end(ret);
1335 return NULL;
1336}
1337
1338int GUIAction::adbsideload(std::string arg)
1339{
1340 operation_start("Sideload");
1341 if (simulate) {
1342 simulate_progress_bar();
1343 operation_end(0);
1344 } else {
1345 // we need to start a thread to allow the operation to be cancelable
1346 pthread_t sideload_thread;
1347 int rc = pthread_create(&sideload_thread, NULL, sideload_thread_fn, this);
1348 if (rc != 0) {
1349 LOGERR("Error starting sideload thread, rc=%i.\n", rc);
1350 operation_end(1);
1351 }
1352 }
that3f7b1ac2014-12-30 11:30:13 +01001353 return 0;
1354}
1355
1356int GUIAction::adbsideloadcancel(std::string arg)
1357{
that3f7b1ac2014-12-30 11:30:13 +01001358 struct stat st;
1359 DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui
1360 gui_print("Cancelling ADB sideload...\n");
thatcc8ddca2015-01-03 01:59:36 +01001361 LOGINFO("Signaling child sideload process to exit.\n");
1362 // Calling stat() on this magic filename signals the minadbd
1363 // subprocess to shut down.
1364 stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st);
1365 if (!sideload_child_pid) {
1366 LOGERR("Unable to get child ID\n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001367 return 0;
1368 }
thatcc8ddca2015-01-03 01:59:36 +01001369 ::sleep(1);
1370 LOGINFO("Killing child sideload process.\n");
1371 kill(sideload_child_pid, SIGTERM);
1372 int status;
1373 LOGINFO("Waiting for child sideload process to exit.\n");
1374 waitpid(sideload_child_pid, &status, 0);
1375 sideload_child_pid = 0;
1376 operation_end(1);
that3f7b1ac2014-12-30 11:30:13 +01001377 DataManager::SetValue("tw_page_done", "1"); // For OpenRecoveryScript support
1378 return 0;
1379}
1380
1381int GUIAction::openrecoveryscript(std::string arg)
1382{
1383 operation_start("OpenRecoveryScript");
1384 if (simulate) {
1385 simulate_progress_bar();
1386 } else {
1387 // Check for the SCRIPT_FILE_TMP first as these are AOSP recovery commands
1388 // that we converted to ORS commands during boot in recovery.cpp.
1389 // Run those first.
1390 int reboot = 0;
1391 if (TWFunc::Path_Exists(SCRIPT_FILE_TMP)) {
1392 gui_print("Processing AOSP recovery commands...\n");
1393 if (OpenRecoveryScript::run_script_file() == 0) {
1394 reboot = 1;
1395 }
1396 }
1397 // Check for the ORS file in /cache and attempt to run those commands.
1398 if (OpenRecoveryScript::check_for_script_file()) {
1399 gui_print("Processing OpenRecoveryScript file...\n");
1400 if (OpenRecoveryScript::run_script_file() == 0) {
1401 reboot = 1;
1402 }
1403 }
1404 if (reboot) {
1405 usleep(2000000); // Sleep for 2 seconds before rebooting
1406 TWFunc::tw_reboot(rb_system);
1407 } else {
1408 DataManager::SetValue("tw_page_done", 1);
1409 }
1410 }
1411 return 0;
1412}
1413
1414int GUIAction::installsu(std::string arg)
1415{
1416 int op_status = 0;
1417
1418 operation_start("Install SuperSU");
1419 if (simulate) {
1420 simulate_progress_bar();
1421 } else {
1422 if (!TWFunc::Install_SuperSU())
1423 op_status = 1;
1424 }
1425
1426 operation_end(op_status);
1427 return 0;
1428}
1429
1430int GUIAction::fixsu(std::string arg)
1431{
1432 int op_status = 0;
1433
1434 operation_start("Fixing Superuser Permissions");
1435 if (simulate) {
1436 simulate_progress_bar();
1437 } else {
1438 LOGERR("Fixing su permissions was deprecated from TWRP.\n");
1439 LOGERR("4.3+ ROMs with SELinux will always lose su perms.\n");
1440 }
1441
1442 operation_end(op_status);
1443 return 0;
1444}
1445
1446int GUIAction::decrypt_backup(std::string arg)
1447{
1448 int op_status = 0;
1449
1450 operation_start("Try Restore Decrypt");
1451 if (simulate) {
1452 simulate_progress_bar();
1453 } else {
1454 string Restore_Path, Filename, Password;
1455 DataManager::GetValue("tw_restore", Restore_Path);
1456 Restore_Path += "/";
1457 DataManager::GetValue("tw_restore_password", Password);
1458 TWFunc::SetPerformanceMode(true);
1459 if (TWFunc::Try_Decrypting_Backup(Restore_Path, Password))
1460 op_status = 0; // success
1461 else
1462 op_status = 1; // fail
1463 TWFunc::SetPerformanceMode(false);
1464 }
1465
1466 operation_end(op_status);
1467 return 0;
1468}
1469
1470int GUIAction::repair(std::string arg)
1471{
1472 int op_status = 0;
1473
1474 operation_start("Repair Partition");
1475 if (simulate) {
1476 simulate_progress_bar();
1477 } else {
1478 string part_path;
1479 DataManager::GetValue("tw_partition_mount_point", part_path);
1480 if (PartitionManager.Repair_By_Path(part_path, true)) {
1481 op_status = 0; // success
1482 } else {
1483 LOGERR("Error repairing file system.\n");
1484 op_status = 1; // fail
1485 }
1486 }
1487
1488 operation_end(op_status);
1489 return 0;
1490}
1491
1492int GUIAction::changefilesystem(std::string arg)
1493{
1494 int op_status = 0;
1495
1496 operation_start("Change File System");
1497 if (simulate) {
1498 simulate_progress_bar();
1499 } else {
1500 string part_path, file_system;
1501 DataManager::GetValue("tw_partition_mount_point", part_path);
1502 DataManager::GetValue("tw_action_new_file_system", file_system);
1503 if (PartitionManager.Wipe_By_Path(part_path, file_system)) {
1504 op_status = 0; // success
1505 } else {
1506 LOGERR("Error changing file system.\n");
1507 op_status = 1; // fail
1508 }
1509 }
1510 PartitionManager.Update_System_Details();
1511 operation_end(op_status);
1512 return 0;
1513}
1514
1515int GUIAction::startmtp(std::string arg)
1516{
1517 int op_status = 0;
1518
1519 operation_start("Start MTP");
1520 if (PartitionManager.Enable_MTP())
1521 op_status = 0; // success
1522 else
1523 op_status = 1; // fail
1524
1525 operation_end(op_status);
1526 return 0;
1527}
1528
1529int GUIAction::stopmtp(std::string arg)
1530{
1531 int op_status = 0;
1532
1533 operation_start("Stop MTP");
1534 if (PartitionManager.Disable_MTP())
1535 op_status = 0; // success
1536 else
1537 op_status = 1; // fail
1538
1539 operation_end(op_status);
1540 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -04001541}
1542
1543int GUIAction::getKeyByName(std::string key)
1544{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001545 if (key == "home") return KEY_HOME;
1546 else if (key == "menu") return KEY_MENU;
1547 else if (key == "back") return KEY_BACK;
1548 else if (key == "search") return KEY_SEARCH;
1549 else if (key == "voldown") return KEY_VOLUMEDOWN;
1550 else if (key == "volup") return KEY_VOLUMEUP;
1551 else if (key == "power") {
Dees_Troy51a0e822012-09-05 15:24:24 -04001552 int ret_val;
1553 DataManager::GetValue(TW_POWER_BUTTON, ret_val);
1554 if (!ret_val)
1555 return KEY_POWER;
1556 else
1557 return ret_val;
1558 }
1559
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001560 return atol(key.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -04001561}
1562
1563void* GUIAction::command_thread(void *cookie)
1564{
1565 string command;
1566 FILE* fp;
1567 char line[512];
1568
1569 DataManager::GetValue("tw_terminal_command_thread", command);
Dees_Troy8170a922012-09-18 15:40:25 -04001570 fp = popen(command.c_str(), "r");
Dees_Troy51a0e822012-09-05 15:24:24 -04001571 if (fp == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001572 LOGERR("Error opening command to run.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -04001573 } else {
1574 int fd = fileno(fp), has_data = 0, check = 0, keep_going = -1, bytes_read = 0;
1575 struct timeval timeout;
1576 fd_set fdset;
1577
1578 while(keep_going)
1579 {
1580 FD_ZERO(&fdset);
1581 FD_SET(fd, &fdset);
1582 timeout.tv_sec = 0;
1583 timeout.tv_usec = 400000;
1584 has_data = select(fd+1, &fdset, NULL, NULL, &timeout);
1585 if (has_data == 0) {
1586 // Timeout reached
1587 DataManager::GetValue("tw_terminal_state", check);
1588 if (check == 0) {
1589 keep_going = 0;
1590 }
1591 } else if (has_data < 0) {
1592 // End of execution
1593 keep_going = 0;
1594 } else {
1595 // Try to read output
Dees_Troy4be841b2012-09-26 14:07:15 -04001596 memset(line, 0, sizeof(line));
Dees_Troy51a0e822012-09-05 15:24:24 -04001597 bytes_read = read(fd, line, sizeof(line));
1598 if (bytes_read > 0)
Dees_Troy2673cec2013-04-02 20:22:16 +00001599 gui_print("%s", line); // Display output
Dees_Troy51a0e822012-09-05 15:24:24 -04001600 else
1601 keep_going = 0; // Done executing
1602 }
1603 }
1604 fclose(fp);
1605 }
1606 DataManager::SetValue("tw_operation_status", 0);
1607 DataManager::SetValue("tw_operation_state", 1);
1608 DataManager::SetValue("tw_terminal_state", 0);
1609 DataManager::SetValue("tw_background_thread_running", 0);
1610 DataManager::SetValue(TW_ACTION_BUSY, 0);
1611 return NULL;
1612}