diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2015-01-22 18:29:33 -0800 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2015-01-22 18:29:33 -0800 |
commit | 8283dcfb9df36bb60723d674338ecb2ba9a3f317 (patch) | |
tree | 54faa810b3ec064640051cb174ca5be6c2189913 /src/core/zip | |
parent | 7de393b86db4fe8dcb779e0559dea6508b7d73c1 (diff) |
Implemented CreateZipFileFromFolder() on win32 (fixed #1001)
Diffstat (limited to 'src/core/zip')
-rw-r--r-- | src/core/zip/MCZip.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/core/zip/MCZip.cpp b/src/core/zip/MCZip.cpp index 620aeb06..334ec50b 100644 --- a/src/core/zip/MCZip.cpp +++ b/src/core/zip/MCZip.cpp @@ -57,8 +57,8 @@ static ErrorCode addFile(zipFile file, String * path) if (r < 0) return ErrorFile; -#ifndef _MSC_VER if (S_ISDIR(statinfo.st_mode)) { +#ifndef _MSC_VER DIR * dir = opendir(cPath); if (dir == NULL) { return ErrorFile; @@ -74,13 +74,37 @@ static ErrorCode addFile(zipFile file, String * path) addFile(file, subpath); } closedir(dir); - - return ErrorNone; - } #else - // XXX - should be implemented on Win32. + String * wildcard = path->stringByAppendingPathComponent(MCSTR("*")); + + HANDLE hFind = INVALID_HANDLE_VALUE; + WIN32_FIND_DATA ffd; + + hFind = FindFirstFile(wildcard->fileSystemRepresentation(), &ffd); + if (hFind == INVALID_HANDLE_VALUE) { + return ErrorFile; + } + + do { + if ((strcmp(ffd.cFileName, ".") == 0) || (strcmp(ffd.cFileName, "..") == 0)) { + continue; + } + String * subpath = path->stringByAppendingPathComponent(String::stringWithFileSystemRepresentation(ffd.cFileName)); + addFile(file, subpath); + } + while (FindNextFile(hFind, &ffd) != 0); + + if (GetLastError() != ERROR_NO_MORE_FILES) { + FindClose(hFind); + return ErrorFile; + } + + FindClose(hFind); #endif - + + return ErrorNone; + } + time_t clock; time(&clock); |