From 43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f Mon Sep 17 00:00:00 2001 From: Dees_Troy Date: Mon, 17 Sep 2012 16:00:01 -0400 Subject: Update backup and restore code, adb sideload Fixed a problem with using make_ext4fs by making its lib a dynamic lib. Added ADB sideload zip install feature - no way to cancel it yet. Improve backup and restore code. --- twrp-functions.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'twrp-functions.cpp') diff --git a/twrp-functions.cpp b/twrp-functions.cpp index ccf0540a1..b393f2b03 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "twrp-functions.hpp" #include "partitions.hpp" @@ -162,3 +163,73 @@ void TWFunc::htc_dumlock_reflash_recovery_to_boot(void) { __system("htcdumlock recovery noreboot"); ui_print("Recovery is flashed to boot.\n"); } + +int TWFunc::Recursive_Mkdir(string Path) { + string pathCpy = Path; + string wholePath; + size_t pos = pathCpy.find("/", 2); + + while (pos != string::npos) + { + wholePath = pathCpy.substr(0, pos); + if (mkdir(wholePath.c_str(), 0777) && errno != EEXIST) { + LOGE("Unable to create folder: %s (errno=%d)\n", wholePath.c_str(), errno); + return false; + } + + pos = pathCpy.find("/", pos + 1); + } + if (mkdir(wholePath.c_str(), 0777) && errno != EEXIST) + return false; + return true; +} + +unsigned long long TWFunc::Get_Folder_Size(string Path, bool Display_Error) { + DIR* d; + struct dirent* de; + struct stat st; + char path2[1024], filename[1024]; + unsigned long long dusize = 0; + + // Make a copy of path in case the data in the pointer gets overwritten later + strcpy(path2, Path.c_str()); + + d = opendir(path2); + if (d == NULL) + { + LOGE("error opening '%s'\n", path2); + return 0; + } + + while ((de = readdir(d)) != NULL) + { + if (de->d_type == DT_DIR && strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) + { + strcpy(filename, path2); + strcat(filename, "/"); + strcat(filename, de->d_name); + dusize += Get_Folder_Size(filename, Display_Error); + } + else if (de->d_type == DT_REG) + { + strcpy(filename, path2); + strcat(filename, "/"); + strcat(filename, de->d_name); + stat(filename, &st); + dusize += (unsigned long long)(st.st_size); + } + } + closedir(d); + + return dusize; +} + +bool TWFunc::Path_Exists(string Path) { + // Check to see if the Path exists + struct statfs st; + + if (statfs(Path.c_str(), &st) != 0) + return false; + else + return true; +} \ No newline at end of file -- cgit v1.2.3