summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDees_Troy <dees_troy@teamw.in>2012-09-27 16:09:41 +0200
committerDees_Troy <dees_troy@teamw.in>2012-09-27 16:40:03 +0200
commitc9ff7a341b03b3013eca57c7554417b623ab6bb0 (patch)
treee8cca26407ec35a3f31823f3bd77c861c51de347
parentPort reboot functions to C++ (diff)
downloadandroid_bootable_recovery-c9ff7a341b03b3013eca57c7554417b623ab6bb0.tar
android_bootable_recovery-c9ff7a341b03b3013eca57c7554417b623ab6bb0.tar.gz
android_bootable_recovery-c9ff7a341b03b3013eca57c7554417b623ab6bb0.tar.bz2
android_bootable_recovery-c9ff7a341b03b3013eca57c7554417b623ab6bb0.tar.lz
android_bootable_recovery-c9ff7a341b03b3013eca57c7554417b623ab6bb0.tar.xz
android_bootable_recovery-c9ff7a341b03b3013eca57c7554417b623ab6bb0.tar.zst
android_bootable_recovery-c9ff7a341b03b3013eca57c7554417b623ab6bb0.zip
-rw-r--r--extra-functions.c48
-rw-r--r--extra-functions.h2
-rw-r--r--gui/action.cpp5
-rw-r--r--openrecoveryscript.cpp4
-rw-r--r--partitionmanager.cpp54
-rw-r--r--partitions.hpp1
6 files changed, 60 insertions, 54 deletions
diff --git a/extra-functions.c b/extra-functions.c
index f202aff33..3735472a3 100644
--- a/extra-functions.c
+++ b/extra-functions.c
@@ -55,51 +55,3 @@ void run_script(const char *str1, const char *str2, const char *str3, const char
}
}
-int check_backup_name(int show_error) {
- // Check the backup name to ensure that it is the correct size and contains only valid characters
- // and that a backup with that name doesn't already exist
- char backup_name[MAX_BACKUP_NAME_LEN];
- char backup_loc[255], tw_image_dir[255];
- int copy_size = strlen(DataManager_GetStrValue(TW_BACKUP_NAME));
- int index, cur_char;
- struct stat st;
-
- // Check size
- if (copy_size > MAX_BACKUP_NAME_LEN) {
- if (show_error)
- LOGE("Backup name is too long.\n");
- return -2;
- }
-
- // Check characters
- strncpy(backup_name, DataManager_GetStrValue(TW_BACKUP_NAME), copy_size);
- if (strcmp(backup_name, "0") == 0)
- return 0; // A "0" (zero) means to use the current timestamp for the backup name
- for (index=0; index<copy_size; index++) {
- cur_char = (int)backup_name[index];
- if (cur_char == 32 || (cur_char >= 48 && cur_char <= 57) || (cur_char >= 65 && cur_char <= 91) || cur_char == 93 || cur_char == 95 || (cur_char >= 97 && cur_char <= 123) || cur_char == 125 || cur_char == 45 || cur_char == 46) {
- // These are valid characters
- // Numbers
- // Upper case letters
- // Lower case letters
- // Space
- // and -_.{}[]
- } else {
- if (show_error)
- LOGE("Backup name '%s' contains invalid character: '%c'\n", backup_name, (char)cur_char);
- return -3;
- }
- }
-
- // Check to make sure that a backup with this name doesn't already exist
- strcpy(backup_loc, DataManager_GetStrValue(TW_BACKUPS_FOLDER_VAR));
- sprintf(tw_image_dir,"%s/%s/.", backup_loc, backup_name);
- if (stat(tw_image_dir, &st) == 0) {
- if (show_error)
- LOGE("A backup with this name already exists.\n");
- return -4;
- }
-
- // No problems found, return 0
- return 0;
-}
diff --git a/extra-functions.h b/extra-functions.h
index 114c9022b..082b806b0 100644
--- a/extra-functions.h
+++ b/extra-functions.h
@@ -6,6 +6,4 @@
void run_script(const char *str1, const char *str2, const char *str3, const char *str4, const char *str5, const char *str6, const char *str7, int request_confirm);
-int check_backup_name(int show_error);
-
#endif // _EXTRAFUNCTIONS_HEADER
diff --git a/gui/action.cpp b/gui/action.cpp
index 7d6686121..4c3d88ed3 100644
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -36,7 +36,6 @@ extern "C" {
#include "../minadbd/adb.h"
int TWinstall_zip(const char* path, int* wipe_cache);
-int check_backup_name(int show_error);
void run_script(const char *str1, const char *str2, const char *str3, const char *str4, const char *str5, const char *str6, const char *str7, int request_confirm);
int gui_console_only();
int gui_start();
@@ -762,7 +761,7 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
if (arg == "backup") {
string Backup_Name;
DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
- if (Backup_Name == "(Current Date)" || Backup_Name == "0" || Backup_Name == "(" || check_backup_name(1) == 0)
+ if (Backup_Name == "(Current Date)" || Backup_Name == "0" || Backup_Name == "(" || PartitionManager.Check_Backup_Name(true) == 0)
ret = PartitionManager.Run_Backup();
else {
operation_end(1, simulate);
@@ -1020,7 +1019,7 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
if (simulate) {
simulate_progress_bar();
} else {
- op_status = check_backup_name(1);
+ op_status = PartitionManager.Check_Backup_Name(true);
if (op_status != 0)
op_status = 1;
}
diff --git a/openrecoveryscript.cpp b/openrecoveryscript.cpp
index bcd4acb28..23641f7f3 100644
--- a/openrecoveryscript.cpp
+++ b/openrecoveryscript.cpp
@@ -198,6 +198,10 @@ int OpenRecoveryScript::run_script_file(void) {
strncpy(value2, tok, line_len - remove_nl);
DataManager_SetStrValue(TW_BACKUP_NAME, value2);
ui_print("Backup folder set to '%s'\n", value2);
+ if (PartitionManager.Check_Backup_Name(true) != 0) {
+ ret_val = 1;
+ continue;
+ }
} else {
char empt[50];
strcpy(empt, "(Current Date)");
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index b267b8b6f..ee199eb85 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -413,6 +413,58 @@ TWPartition* TWPartitionManager::Find_Partition_By_Name(string Name) {
return NULL;
}
+int TWPartitionManager::Check_Backup_Name(bool Display_Error) {
+ // Check the backup name to ensure that it is the correct size and contains only valid characters
+ // and that a backup with that name doesn't already exist
+ char backup_name[MAX_BACKUP_NAME_LEN];
+ char backup_loc[255], tw_image_dir[255];
+ int copy_size;
+ int index, cur_char;
+ string Backup_Name, Backup_Loc;
+
+ DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
+ copy_size = Backup_Name.size();
+ // Check size
+ if (copy_size > MAX_BACKUP_NAME_LEN) {
+ if (Display_Error)
+ LOGE("Backup name is too long.\n");
+ return -2;
+ }
+
+ // Check each character
+ strncpy(backup_name, Backup_Name.c_str(), copy_size);
+ if (strcmp(backup_name, "0") == 0)
+ return 0; // A "0" (zero) means to use the current timestamp for the backup name
+ for (index=0; index<copy_size; index++) {
+ cur_char = (int)backup_name[index];
+ if (cur_char == 32 || (cur_char >= 48 && cur_char <= 57) || (cur_char >= 65 && cur_char <= 91) || cur_char == 93 || cur_char == 95 || (cur_char >= 97 && cur_char <= 123) || cur_char == 125 || cur_char == 45 || cur_char == 46) {
+ // These are valid characters
+ // Numbers
+ // Upper case letters
+ // Lower case letters
+ // Space
+ // and -_.{}[]
+ } else {
+ if (Display_Error)
+ LOGE("Backup name '%s' contains invalid character: '%c'\n", backup_name, (char)cur_char);
+ return -3;
+ }
+ }
+
+ // Check to make sure that a backup with this name doesn't already exist
+ DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, Backup_Loc);
+ strcpy(backup_loc, Backup_Loc.c_str());
+ sprintf(tw_image_dir,"%s/%s/.", backup_loc, backup_name);
+ if (TWFunc::Path_Exists(tw_image_dir)) {
+ if (Display_Error)
+ LOGE("A backup with this name already exists.\n");
+ return -4;
+ }
+
+ // No problems found, return 0
+ return 0;
+}
+
bool TWPartitionManager::Make_MD5(bool generate_md5, string Backup_Folder, string Backup_Filename)
{
char command[512];
@@ -566,7 +618,7 @@ int TWPartitionManager::Run_Backup(void) {
DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, Backup_Folder);
DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
- if (Backup_Name == "(Current Date)" || Backup_Name == "0") {
+ if (Backup_Name == "(Current Date)" || Backup_Name == "0" || Backup_Name.empty()) {
char timestamp[255];
sprintf(timestamp,"%04d-%02d-%02d--%02d-%02d-%02d",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
Backup_Name = timestamp;
diff --git a/partitions.hpp b/partitions.hpp
index fdceba844..bb8f621eb 100644
--- a/partitions.hpp
+++ b/partitions.hpp
@@ -162,6 +162,7 @@ public:
TWPartition* Find_Partition_By_Path(string Path); // Returns a pointer to a partition based on path
TWPartition* Find_Partition_By_Block(string Block); // Returns a pointer to a partition based on block device
TWPartition* Find_Partition_By_Name(string Block); // Returns a pointer to a partition based on name
+ virtual int Check_Backup_Name(bool Display_Error); // Checks the current backup name to ensure that it is valid
virtual int Run_Backup(); // Initiates a backup in the current storage
virtual int Run_Restore(string Restore_Name); // Restores a backup
virtual void Set_Restore_Files(string Restore_Name); // Used to gather a list of available backup partitions for the user to select for a restore