From c38c4c468f6407627ffcede1dccb041608ce85f6 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Wed, 25 Feb 2015 13:58:41 +1000 Subject: [PATCH] Fix directory size calculations --- include/CoolPropTools.h | 15 ++++++++------- src/CoolPropTools.cpp | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/CoolPropTools.h b/include/CoolPropTools.h index a55a2de0..58945c35 100644 --- a/include/CoolPropTools.h +++ b/include/CoolPropTools.h @@ -115,11 +115,12 @@ { return (path == L"." || path == L".."); } - inline unsigned long long CalculateDirSize(const std::wstring &path, std::vector *errVect = NULL, unsigned long long size = 0) + inline unsigned long long CalculateDirSize(const std::wstring &path, std::vector *errVect = NULL) { - WIN32_FIND_DATA data; + unsigned long long size = 0; + WIN32_FIND_DATAW data; HANDLE sh = NULL; - sh = FindFirstFile((path + L"\\*").c_str(), &data); + sh = FindFirstFileW((path + L"\\*").c_str(), &data); if (sh == INVALID_HANDLE_VALUE ) { @@ -135,15 +136,15 @@ if (!IsBrowsePath(data.cFileName)) { // if found object is ... - if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) + if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // directory, then search it recursievly - size = CalculateDirSize(path + L"\\" + data.cFileName, NULL, size); + size += CalculateDirSize(path + L"\\" + data.cFileName, NULL); else // otherwise get object size and add it to directory size - size += (unsigned long long) (data.nFileSizeHigh * (MAXDWORD ) + data.nFileSizeLow); + size += data.nFileSizeHigh * (unsigned long long)(MAXDWORD) + data.nFileSizeLow; } - } while (FindNextFile(sh, &data)); // do + } while (FindNextFileW(sh, &data)); // do FindClose(sh); diff --git a/src/CoolPropTools.cpp b/src/CoolPropTools.cpp index 559cb560..18c83b6a 100644 --- a/src/CoolPropTools.cpp +++ b/src/CoolPropTools.cpp @@ -17,7 +17,7 @@ #include #include -static double ftw_summer; // An evil global variable for the ftw function +static thread_local unsigned long long ftw_summer; // An evil global variable for the ftw function int ftw_function(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf){ ftw_summer += sb->st_size; return 0; /* To tell nftw() to continue */