diff options
author | Dees_Troy <dees_troy@teamw.in> | 2012-09-17 22:00:01 +0200 |
---|---|---|
committer | Dees_Troy <dees_troy@teamw.in> | 2012-09-17 22:06:12 +0200 |
commit | 43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f (patch) | |
tree | 58d02c17fb5487c361244a69a8a9850337638f2d /twrp-functions.cpp | |
parent | Move to shared libmincrypt (diff) | |
download | android_bootable_recovery-43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f.tar android_bootable_recovery-43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f.tar.gz android_bootable_recovery-43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f.tar.bz2 android_bootable_recovery-43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f.tar.lz android_bootable_recovery-43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f.tar.xz android_bootable_recovery-43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f.tar.zst android_bootable_recovery-43d8b0077072ff4ef5ffa07be5dcbf7a73fe499f.zip |
Diffstat (limited to '')
-rw-r--r-- | twrp-functions.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
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 <vector> #include <dirent.h> #include <time.h> +#include <errno.h> #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 |