Skip to content

Commit 5bfc3f2

Browse files
PatriceJiangdrelaptop
authored andcommitted
[CCFileUtils] win32 getFileSize (cocos2d#19176)
* win32 getFileSize * fix stat
1 parent fc4cbb9 commit 5bfc3f2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

cocos/platform/win32/CCFileUtils-win32.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ THE SOFTWARE.
3636
#include <regex>
3737
#include <sstream>
3838

39+
#include <sys/types.h>
40+
#include <sys/stat.h>
41+
3942
using namespace std;
4043

4144
#define DECLARE_GUARD std::lock_guard<std::recursive_mutex> mutexGuard(_mutex)
@@ -271,6 +274,16 @@ void FileUtilsWin32::listFilesRecursively(const std::string& dirPath, std::vecto
271274
}
272275
}
273276

277+
long FileUtilsWin32::getFileSize(const std::string &filepath) const
278+
{
279+
struct _stat tmp;
280+
if (_stat(filepath.c_str(), &tmp) == 0)
281+
{
282+
return (long)tmp.st_size;
283+
}
284+
return 0;
285+
}
286+
274287
std::vector<std::string> FileUtilsWin32::listFiles(const std::string& dirPath) const
275288
{
276289
std::string fullpath = fullPathForFilename(dirPath);

cocos/platform/win32/CCFileUtils-win32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class CC_DLL FileUtilsWin32 : public FileUtils
112112

113113
virtual FileUtils::Status getContents(const std::string& filename, ResizableBuffer* buffer) const override;
114114

115+
virtual long getFileSize(const std::string &filepath) const override;
116+
115117
/**
116118
* Gets full path for filename, resolution directory and search path.
117119
*

0 commit comments

Comments
 (0)