|
|
@@ -189,9 +189,118 @@ typedef struct FILE_LAYOUT_ENTRY {
|
|
|
} FILE_LAYOUT_ENTRY, *PFILE_LAYOUT_ENTRY;
|
|
|
|
|
|
//Premise: Should be initialize entry->current first.
|
|
|
-static DWORD GetSubFileInfors(PFILE_LAYOUT_ENTRY Entry, DWORD& dwDirCount, DWORD& dwFileCount, const DWORD dwFilterMask = 0);
|
|
|
+static ULONGLONG GetSubFileInfors(PFILE_LAYOUT_ENTRY Entry, DWORD& dwDirCount, DWORD& dwFileCount, const DWORD dwFilterMask = 0);
|
|
|
+static unsigned long long GetDirectorySize(LPCTSTR dirPath, int nDepth = -1024);
|
|
|
+inline static DWORD GetDirectoryItemCount(LPCTSTR dirPath, int nDepth = -1024);
|
|
|
static void DisplayFileEntities(const PFILE_LAYOUT_ENTRY Entry);
|
|
|
|
|
|
+DWORD GetDirectoryItemCount(LPCTSTR dirPath, int nDepth)
|
|
|
+{
|
|
|
+#if defined(RVC_OS_LINUX)
|
|
|
+ DIR* d;
|
|
|
+ struct dirent* entry;
|
|
|
+ struct stat statbuf;
|
|
|
+ DWORD result = 0;
|
|
|
+
|
|
|
+ if ((d = opendir(dirPath)) == NULL) {
|
|
|
+ Dbg("opendir %s failed: %s", dirPath, strerror(errno));
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ struct dirent* dp = NULL;
|
|
|
+ while ((dp = readdir(d)) != NULL) {
|
|
|
+ if ((!strcmp(dp->d_name, ".")) || (!strcmp(dp->d_name, ".."))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ result++;
|
|
|
+ continue;
|
|
|
+
|
|
|
+ char tempFilePath[MAX_PATH * 2] = { 0 };
|
|
|
+ strcpy(tempFilePath, dirPath);
|
|
|
+ if (strlen(tempFilePath) + strlen(dp->d_name) + 3 >= MAX_PATH * 2) {
|
|
|
+ Dbg("filePath is too long for current.");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ strcat(tempFilePath, "/");
|
|
|
+ strcat(tempFilePath, dp->d_name);
|
|
|
+ struct stat fileStat;
|
|
|
+ if (stat(tempFilePath, &fileStat) < 0) {
|
|
|
+ Dbg("stat dir for %s failed: %d ", tempFilePath, errno);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (S_ISDIR(fileStat.st_mode)) {
|
|
|
+ if (nDepth + 1 >= 0) {
|
|
|
+ Dbg("exceed the deepest dir, do not recursive at all: %s", tempFilePath);
|
|
|
+ } else {
|
|
|
+ result += GetDirectoryItemCount(tempFilePath, nDepth + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closedir(d);
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+#else
|
|
|
+ return 0;
|
|
|
+#endif //RVC_OS_LINUX
|
|
|
+}
|
|
|
+
|
|
|
+unsigned long long GetDirectorySize(LPCTSTR dirPath, int nDepth)
|
|
|
+{
|
|
|
+#if defined(RVC_OS_LINUX)
|
|
|
+ DIR * d;
|
|
|
+ struct dirent* entry;
|
|
|
+ struct stat statbuf;
|
|
|
+ unsigned long long result = 0;
|
|
|
+
|
|
|
+ if ((d = opendir(dirPath)) == NULL) {
|
|
|
+ Dbg("opendir %s failed: %s", dirPath, strerror(errno));
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ lstat(dirPath, &statbuf);
|
|
|
+ result += statbuf.st_size;
|
|
|
+
|
|
|
+ struct dirent* dp = NULL;
|
|
|
+ while ((dp = readdir(d)) != NULL) {
|
|
|
+ if ((!strcmp(dp->d_name, ".")) || (!strcmp(dp->d_name, ".."))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ char tempFilePath[MAX_PATH * 2] = { 0 };
|
|
|
+ strcpy(tempFilePath, dirPath);
|
|
|
+ if (strlen(tempFilePath) + strlen(dp->d_name) + 3 >= MAX_PATH * 2) {
|
|
|
+ Dbg("filePath is too long for current.");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ strcat(tempFilePath, "/");
|
|
|
+ strcat(tempFilePath, dp->d_name);
|
|
|
+ struct stat fileStat;
|
|
|
+ if (stat(tempFilePath, &fileStat) < 0) {
|
|
|
+ Dbg("stat dir for %s failed: %d ", tempFilePath, errno);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (S_ISDIR(fileStat.st_mode)) {
|
|
|
+ if (nDepth + 1 >= 0) {
|
|
|
+ Dbg("exceed the deepest dir, do not recursive at all: %s", tempFilePath);
|
|
|
+ } else {
|
|
|
+ result += GetDirectorySize(tempFilePath, nDepth + 1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result += fileStat.st_size;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closedir(d);
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+#else
|
|
|
+ return 0;
|
|
|
+#endif //RVC_OS_LINUX
|
|
|
+}
|
|
|
+
|
|
|
static UINT GetErrorMessage(CSimpleStringA& retMessage, LPCTSTR lpDefault, DWORD error = GetLastError())
|
|
|
{
|
|
|
#if defined(_MSC_VER)
|
|
|
@@ -587,8 +696,9 @@ static BOOL TraceExtend(PFILE_LAYOUT_ENTRY Entry, int UpLevel)
|
|
|
}
|
|
|
return bRet;
|
|
|
}
|
|
|
+
|
|
|
/*返回该目录下的文件数量(文件+文件夹)*/
|
|
|
-DWORD GetSubFileInfors(PFILE_LAYOUT_ENTRY Entry, DWORD& dwDirCount, DWORD& dwFileCount, const DWORD dwFilterMask)
|
|
|
+ULONGLONG GetSubFileInfors(PFILE_LAYOUT_ENTRY Entry, DWORD& dwDirCount, DWORD& dwFileCount, const DWORD dwFilterMask)
|
|
|
{
|
|
|
dwDirCount = dwFileCount = 0;
|
|
|
if(Entry == NULL) {
|
|
|
@@ -665,11 +775,13 @@ DWORD GetSubFileInfors(PFILE_LAYOUT_ENTRY Entry, DWORD& dwDirCount, DWORD& dwFil
|
|
|
CSimpleStringA csPath(pszParentPah);
|
|
|
struct stat fileStat;
|
|
|
if (stat(csPath, &fileStat) < 0 || !S_ISDIR(fileStat.st_mode)) {
|
|
|
+ Dbg("stat for %s failed or is not dir", csPath.GetData());
|
|
|
delete[] pszParentPah;
|
|
|
return 0;
|
|
|
}
|
|
|
DIR* d = opendir(csPath);
|
|
|
if (!d) {
|
|
|
+ Dbg("opendir %s failed: %s", (LPCTSTR)csPath, strerror(errno));
|
|
|
delete[] pszParentPah;
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -679,9 +791,9 @@ DWORD GetSubFileInfors(PFILE_LAYOUT_ENTRY Entry, DWORD& dwDirCount, DWORD& dwFil
|
|
|
if ((!strcmp(dp->d_name, ".")) || (!strcmp(dp->d_name, ".."))) {
|
|
|
continue;
|
|
|
}
|
|
|
- char tempFilePath[MAX_PATH] = { 0 };
|
|
|
+ char tempFilePath[MAX_PATH*2] = { 0 };
|
|
|
strcpy(tempFilePath, pszParentPah);
|
|
|
- if (strlen(tempFilePath) + strlen(dp->d_name) + 3 >= MAX_PATH) {
|
|
|
+ if (strlen(tempFilePath) + strlen(dp->d_name) + 3 >= MAX_PATH * 2) {
|
|
|
Dbg("filePath is too long for current.");
|
|
|
continue;
|
|
|
}
|
|
|
@@ -690,8 +802,12 @@ DWORD GetSubFileInfors(PFILE_LAYOUT_ENTRY Entry, DWORD& dwDirCount, DWORD& dwFil
|
|
|
stat(tempFilePath, &fileStat);
|
|
|
CSimpleFileComponent folder;
|
|
|
folder.mAttributes = 0;
|
|
|
- if (S_ISDIR(fileStat.st_mode))
|
|
|
+ if (S_ISDIR(fileStat.st_mode)) {
|
|
|
folder.mAttributes |= FILE_ATTRIBUTE_DIRECTORY;
|
|
|
+ folder.mFileSize = GetDirectoryItemCount(tempFilePath); //GetDirectorySize(tempFilePath);
|
|
|
+ } else {
|
|
|
+ folder.mFileSize = fileStat.st_size;
|
|
|
+ }
|
|
|
if (folder.mAttributes == 0)
|
|
|
folder.mAttributes = FILE_ATTRIBUTE_ARCHIVE;
|
|
|
if (!(fileStat.st_mode & S_IWUSR))
|
|
|
@@ -699,14 +815,14 @@ DWORD GetSubFileInfors(PFILE_LAYOUT_ENTRY Entry, DWORD& dwDirCount, DWORD& dwFil
|
|
|
folder.mftAccess = fileStat.st_atime;
|
|
|
folder.mftCreate = fileStat.st_ctime;
|
|
|
folder.mftModified = fileStat.st_mtime;
|
|
|
- folder.mFileSize = fileStat.st_size;
|
|
|
+
|
|
|
const DWORD dwNameLen = strlen(dp->d_name);
|
|
|
Append(Entry->FileNamesBuffer, (PBYTE)dp->d_name, dwNameLen, folder.mNameOffset);
|
|
|
folder.mNameLength = dwNameLen;
|
|
|
Entry->SubFiles.Append(&folder, 0, 1);
|
|
|
|
|
|
- if (folder.mAttributes & FILE_ATTRIBUTE_DIRECTORY) dwDirCount++;
|
|
|
- else dwFileCount++;
|
|
|
+ if (folder.mAttributes & FILE_ATTRIBUTE_DIRECTORY) { dwDirCount++; }
|
|
|
+ else dwFileCount++;
|
|
|
}
|
|
|
closedir(d);
|
|
|
#endif //_MSC_VER
|