5 #include <sys/stat.h>
\r
9 #include "Raym/Log.h"
\r
10 #include "Raym/Raym.h"
\r
16 DEFINE_STATIC_MUTEX(mutex_);
\r
17 static FileManager *defaultManager_ = NULL;
\r
19 FileManager::FileManager()
\r
21 DebugLog2("FileManager::FileManager()");
\r
24 FileManager::~FileManager()
\r
26 DebugLog2("FileManager::~FileManager()");
\r
29 FileManager *FileManager::defaultManager()
\r
31 DebugLog2("FileManager::defaultManager()");
\r
34 if (defaultManager_ == NULL)
\r
36 defaultManager_ = new FileManager();
\r
37 ((Object *)defaultManager_)->init();
\r
38 ((Object *)defaultManager_)->autorelease(true);
\r
42 return defaultManager_;
\r
45 bool FileManager::fileExistsAtPath(String *path, bool *isDirectory)
\r
47 DebugLog2("FileManager::fileExistsAtPath(path,isDirectory)");
\r
49 bool result = false;
\r
53 struct __stat64 buffer;
\r
54 if (_stat64(path->cString(), &buffer) == 0)
\r
57 if (isDirectory != NULL)
\r
59 *isDirectory = ((buffer.st_mode & _S_IFDIR) == _S_IFDIR);
\r
68 bool FileManager::fileExistsAtPath(const char *path, bool *isDirectory)
\r
70 DebugLog2("FileManager::fileExistsAtPath(path,isDirectory)");
\r
72 bool result = false;
\r
73 if ((path != NULL) && (isDirectory != NULL))
\r
75 result = fileExistsAtPath(String::stringWithUTF8String(path), isDirectory);
\r
80 bool FileManager::removeItemAtPath(String *path, Error **error)
\r
82 DebugLog2("FileManager::removeItemAtPath()");
\r
84 bool result = false;
\r
88 if (fileExistsAtPath(path, &isDir))
\r
92 result = (_rmdir(path->cString()) == 0);
\r
96 result = (remove(path->cString()) == 0);
\r
103 const char *FileManager::className()
\r
105 return "FileManager";
\r
108 int FileManager::freeSpaceForPath(String *path)
\r
111 TCHAR tpath[MAX_PATH + 1];
\r
114 size_t returnValue;
\r
115 e = mbstowcs_s(&returnValue, tpath, sizeof(tpath), path->cString(), _TRUNCATE);
\r
118 ULARGE_INTEGER freeBytesAvailable;
\r
119 ULARGE_INTEGER totalNumberOfBytes;
\r
120 if (GetDiskFreeSpaceEx(tpath, &freeBytesAvailable, &totalNumberOfBytes, NULL))
\r
122 result = (int)(freeBytesAvailable.QuadPart / 1024 / 1024 / 1024);
\r