diff options
Diffstat (limited to 'gui/action.cpp')
-rw-r--r-- | gui/action.cpp | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/gui/action.cpp b/gui/action.cpp index d54ea0a03..953439906 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -98,18 +98,18 @@ ActionThread::~ActionThread() pthread_mutex_destroy(&m_act_lock); } -void ActionThread::threadActions(GUIAction *act, size_t start_index) +void ActionThread::threadActions(GUIAction *act) { pthread_mutex_lock(&m_act_lock); if (m_thread_running) { pthread_mutex_unlock(&m_act_lock); - LOGERR("Another threaded action is already running -- not running actions '%s' and following\n", act->mActions[start_index].mFunction.c_str()); + LOGERR("Another threaded action is already running -- not running %u actions starting with '%s'\n", + act->mActions.size(), act->mActions[0].mFunction.c_str()); } else { m_thread_running = true; pthread_mutex_unlock(&m_act_lock); ThreadData *d = new ThreadData; d->act = act; - d->start_index = start_index; pthread_create(&m_thread, NULL, &ActionThread_work_wrapper, d); } @@ -121,7 +121,7 @@ void ActionThread::run(void *data) GUIAction* act = d->act; std::vector<GUIAction::Action>::iterator it; - for (it = act->mActions.begin() + d->start_index; it != act->mActions.end(); ++it) + for (it = act->mActions.begin(); it != act->mActions.end(); ++it) act->doAction(*it); pthread_mutex_lock(&m_act_lock); @@ -201,6 +201,7 @@ GUIAction::GUIAction(xml_node<>* node) mf["decrypt_backup"] = &GUIAction::decrypt_backup; mf["repair"] = &GUIAction::repair; mf["changefilesystem"] = &GUIAction::changefilesystem; + mf["flashimage"] = &GUIAction::flashimage; } // First, get the action @@ -324,7 +325,7 @@ void GUIAction::simulate_progress_bar(void) } } -int GUIAction::flash_zip(std::string filename, std::string pageName, int* wipe_cache) +int GUIAction::flash_zip(std::string filename, int* wipe_cache) { int ret_val = 0; @@ -336,15 +337,9 @@ int GUIAction::flash_zip(std::string filename, std::string pageName, int* wipe_c return -1; } - // We're going to jump to this page first, like a loading page - gui_changePage(pageName); - if (!PartitionManager.Mount_By_Path(filename, true)) return -1; - // TODO: why again? - gui_changePage(pageName); - if (simulate) { simulate_progress_bar(); } else { @@ -380,18 +375,24 @@ int GUIAction::doActions() if (mActions.size() < 1) return -1; + bool needThread = false; std::vector<Action>::iterator it; for (it = mActions.begin(); it != mActions.end(); ++it) { if (needsToRunInSeparateThread(*it)) { - // run all remaining actions in a separate thread - action_thread.threadActions(this, it - mActions.begin()); - // ...and we're done here + needThread = true; break; } - - doAction(*it); + } + if (needThread) + { + action_thread.threadActions(this); + } + else + { + for (it = mActions.begin(); it != mActions.end(); ++it) + doAction(*it); } return 0; @@ -937,29 +938,33 @@ void GUIAction::reinject_after_flash() int GUIAction::flash(std::string arg) { int i, ret_val = 0, wipe_cache = 0; + // We're going to jump to this page first, like a loading page + gui_changePage(arg); for (i=0; i<zip_queue_index; i++) { operation_start("Flashing"); DataManager::SetValue("tw_filename", zip_queue[i]); DataManager::SetValue(TW_ZIP_INDEX, (i + 1)); TWFunc::SetPerformanceMode(true); - ret_val = flash_zip(zip_queue[i], arg, &wipe_cache); + ret_val = flash_zip(zip_queue[i], &wipe_cache); TWFunc::SetPerformanceMode(false); if (ret_val != 0) { gui_print("Error flashing zip '%s'\n", zip_queue[i].c_str()); - i = 10; // Error flashing zip - exit queue ret_val = 1; + break; } } zip_queue_index = 0; - DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); - if (wipe_cache) + if (wipe_cache) { + gui_print("One or more zip requested a cache wipe\nWiping cache now.\n"); PartitionManager.Wipe_By_Path("/cache"); + } reinject_after_flash(); PartitionManager.Update_System_Details(); operation_end(ret_val); + DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); return 0; } @@ -1645,6 +1650,24 @@ int GUIAction::stopmtp(std::string arg) return 0; } +int GUIAction::flashimage(std::string arg) +{ + int op_status = 0; + + operation_start("Flash Image"); + string path, filename, full_filename; + DataManager::GetValue("tw_zip_location", path); + DataManager::GetValue("tw_file", filename); + full_filename = path + "/" + filename; + if (PartitionManager.Flash_Image(full_filename)) + op_status = 0; // success + else + op_status = 1; // fail + + operation_end(op_status); + return 0; +} + int GUIAction::getKeyByName(std::string key) { if (key == "home") return KEY_HOME; |