From 01a9b7a7f88696d579eed5e55831267a6cb4220f Mon Sep 17 00:00:00 2001 From: Dees_Troy Date: Mon, 1 Oct 2012 09:01:03 -0400 Subject: Fix output of version number --- data.cpp | 30 +++++++++++++++++++++++++++++- data.hpp | 1 + gui/action.cpp | 1 - recovery.cpp | 1 - twrp-functions.cpp | 25 ------------------------- twrp-functions.hpp | 1 - 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/data.cpp b/data.cpp index ab240a7a4..f7ad57a79 100644 --- a/data.cpp +++ b/data.cpp @@ -39,6 +39,7 @@ #include "variables.h" #include "data.hpp" #include "partitions.hpp" +#include "twrp-functions.hpp" extern "C" { @@ -814,6 +815,32 @@ int DataManager::GetMagicValue(const string varName, string& value) return -1; } +void DataManager::Output_Version(void) { + string Path, Command; + char version[255]; + + Path = DataManager::GetSettingsStoragePath(); + if (!PartitionManager.Mount_By_Path(Path, false)) { + LOGI("Unable to mount '%s' to write version number.\n", Path.c_str()); + return; + } + Path += "/TWRP/.version"; + if (TWFunc::Path_Exists(Path)) { + Command = "rm -f " + Path; + system(Command.c_str()); + } + FILE *fp = fopen(Path.c_str(), "w"); + if (fp == NULL) { + LOGE("Unable to open '%s'.\n", Path.c_str()); + return; + } + strcpy(version, TW_VERSION_STR); + fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp); + fclose(fp); + sync(); + LOGI("Version number saved to '%s'\n", Path.c_str()); +} + void DataManager::ReadSettingsFile(void) { // Load up the values for TWRP - Sleep to let the card be ready @@ -843,11 +870,12 @@ void DataManager::ReadSettingsFile(void) LOGI("Attempt to load settings from settings file...\n"); LoadValues(settings_file); + Output_Version(); GetValue(TW_HAS_DUAL_STORAGE, has_dual); GetValue(TW_USE_EXTERNAL_STORAGE, use_ext); GetValue(TW_HAS_EXTERNAL, has_ext); if (has_dual != 0 && use_ext == 1) { - // Attempt to sdcard using external storage + // Attempt to switch to using external storage if (!PartitionManager.Mount_Current_Storage(false)) { LOGE("Failed to mount external storage, using internal storage.\n"); // Remount failed, default back to internal storage diff --git a/data.hpp b/data.hpp index ecf4d70d5..98c40fec5 100644 --- a/data.hpp +++ b/data.hpp @@ -49,6 +49,7 @@ public: static void DumpValues(); static void update_tz_environment_variables(); static void SetDefaultValues(); + static void Output_Version(void); // Outputs the version to a file in the TWRP folder static void ReadSettingsFile(void); static string GetCurrentStoragePath(void); diff --git a/gui/action.cpp b/gui/action.cpp index 771c5e74e..afa52d1f8 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -981,7 +981,6 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) DataManager::SetValue(TW_IS_ENCRYPTED, 0); DataManager::ReadSettingsFile(); - TWFunc::Output_Version(); if (OpenRecoveryScript::check_for_script_file()) { ui_print("Processing OpenRecoveryScript file...\n"); if (OpenRecoveryScript::run_script_file() == 0) { diff --git a/recovery.cpp b/recovery.cpp index f6bfd4537..1e1d9a952 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -928,7 +928,6 @@ main(int argc, char **argv) { finish_recovery(NULL); DataManager_ReadSettingsFile(); if (DataManager_GetIntValue(TW_IS_ENCRYPTED) == 0 && OpenRecoveryScript::check_for_script_file()) { - TWFunc::Output_Version(); gui_console_only(); OpenRecoveryScript::run_script_file(); if (1 || OpenRecoveryScript::run_script_file() != 0) { diff --git a/twrp-functions.cpp b/twrp-functions.cpp index 01f854193..b121c8a82 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -387,28 +387,3 @@ void TWFunc::check_and_run_script(const char* script_file, const char* display_n ui_print("\nFinished running %s script.\n", display_name); } } - -void TWFunc::Output_Version(void) { - string Path, Command; - char version[255]; - - Path = DataManager::GetSettingsStoragePath(); - if (!PartitionManager.Mount_By_Path(Path, false)) { - LOGI("Unable to mount '%s' to write version number.\n", Path.c_str()); - return; - } - Path += "/TWRP/.version"; - if (Path_Exists(Path)) { - Command = "rm -f " + Path; - system(Command.c_str()); - } - FILE *fp = fopen(Path.c_str(), "w"); - if (fp == NULL) { - LOGE("Unable to open '%s'.\n", Path.c_str()); - return; - } - strcpy(version, TW_VERSION_STR); - fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp); - fclose(fp); - sync(); -} \ No newline at end of file diff --git a/twrp-functions.hpp b/twrp-functions.hpp index da17e3cd1..b28d04ba5 100644 --- a/twrp-functions.hpp +++ b/twrp-functions.hpp @@ -36,7 +36,6 @@ public: static void twfinish_recovery(const char *send_intent); // Writes the log to last_log static int tw_reboot(RebootCommand command); // Prepares the device for rebooting static void check_and_run_script(const char* script_file, const char* display_name); // checks for the existence of a script, chmods it to 755, then runs it - static void Output_Version(void); // Outputs the version to a file in the TWRP folder private: static void check_and_fclose(FILE *fp, const char *name); -- cgit v1.2.3