Fix output of version number
diff --git a/data.cpp b/data.cpp
index ab240a7..f7ad57a 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 @@
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 @@
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 ecf4d70..98c40fe 100644
--- a/data.hpp
+++ b/data.hpp
@@ -49,6 +49,7 @@
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 771c5e7..afa52d1 100644
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -981,7 +981,6 @@
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 f6bfd45..1e1d9a9 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -928,7 +928,6 @@
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 01f8541..b121c8a 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -387,28 +387,3 @@
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 da17e3c..b28d04b 100644
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -36,7 +36,6 @@
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);