18 #if defined(__ISWINDOWS__)
25 # if !defined(__powerpc__)
30 #if defined(__ISWINDOWS__)
32 bool IsBrowsePath(
const std::wstring& path) {
33 return (path == L
"." || path == L
"..");
35 unsigned long long CalculateDirSize(
const std::wstring& path, std::vector<std::wstring>* errVect) {
36 unsigned long long size = 0;
37 WIN32_FIND_DATAW data;
39 sh = FindFirstFileW((path + L
"\\*").c_str(), &data);
41 if (sh == INVALID_HANDLE_VALUE) {
43 if (errVect != NULL) errVect->push_back(path);
49 if (!IsBrowsePath(data.cFileName)) {
51 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
56 size += data.nFileSizeHigh * (
unsigned long long)(MAXDWORD) + data.nFileSizeLow;
59 }
while (FindNextFileW(sh, &data));
65 #elif defined(__ANDROID__) || defined(__powerpc__)
75 static thread_local
unsigned long long ftw_summer;
76 int ftw_function(
const char* fpath,
const struct stat* sb,
int tflag,
struct FTW* ftwbuf) {
77 ftw_summer += sb->st_size;
82 int flags = 0 | FTW_DEPTH | FTW_PHYS;
84 double temp = ftw_summer;
91 std::ifstream in(filename, std::ios::in | std::ios::binary);
93 std::vector<char> contents;
94 in.seekg(0, std::ios::end);
95 contents.resize((
unsigned int)in.tellg());
96 in.seekg(0, std::ios::beg);
97 in.read(&contents[0], contents.size());
105 std::replace(file_path.begin(), file_path.end(),
'\\',
'/');
107 #if defined(__ISWINDOWS__)
108 const char sep =
'\\';
110 const char sep =
'/';
113 std::vector<std::string> pathsplit =
strsplit(file_path,
'/');
114 std::string path = pathsplit[0];
115 for (std::size_t i = 0, sz = pathsplit.size(); i < sz; i++) {
117 #if defined(__ISWINDOWS__)
118 int errcode = CreateDirectoryA((LPCSTR)path.c_str(), NULL);
120 switch (GetLastError()) {
121 case ERROR_ALREADY_EXISTS:
123 case ERROR_PATH_NOT_FOUND:
130 # if defined(__powerpc__)
132 mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
136 if (i < (sz - 1)) path +=
format(
"%c%s", sep, pathsplit[i + 1].c_str());
141 #if defined(__ISLINUX__)
142 return std::string(
"/");
143 #elif defined(__ISAPPLE__)
144 return std::string(
"/");
145 #elif defined(__ISWINDOWS__)
146 return std::string(
"\\");
154 #if defined(__ISLINUX__)
156 home = getenv(
"HOME");
157 return std::string(home);
158 #elif defined(__ISAPPLE__)
160 home = getenv(
"HOME");
162 struct passwd* pwd = getpwuid(getuid());
170 return std::string(home);
171 #elif defined(__ISWINDOWS__)
172 # if defined(_MSC_VER)
173 # pragma warning(push)
174 # pragma warning(disable : 4996)
176 char* pUSERPROFILE = getenv(
"USERPROFILE");
177 if (pUSERPROFILE != NULL) {
178 return std::string(pUSERPROFILE);
180 char* pHOMEDRIVE = getenv(
"HOMEDRIVE");
181 char* pHOMEPATH = getenv(
"HOMEPATH");
182 if (pHOMEDRIVE != NULL && pHOMEPATH != NULL) {
183 return std::string(pHOMEDRIVE) + std::string(pHOMEPATH);
185 return std::string(
"");
188 # if defined(_MSC_VER)
189 # pragma warning(pop)
197 std::string path_cpy;
199 path_cpy = path.substr(0, path.size() - 1);
204 #if defined(__ISWINDOWS__)
208 if (_stat(path_cpy.c_str(), &buf) == 0) {
213 #elif defined(__ISLINUX__) || defined(__ISAPPLE__)
215 if (lstat(path_cpy.c_str(), &st) == 0) {
216 if (S_ISDIR(st.st_mode))
return true;
217 if (S_ISREG(st.st_mode))
return true;
227 std::string
join_path(
const std::string& one,
const std::string& two) {
230 if (!
endswith(one, separator) && !one.empty()) {
231 result = one + separator;
240 std::ifstream in(filename, std::ios::in | std::ios::binary);
242 std::string contents;
243 in.seekg(0, std::ios::end);
244 contents.resize((
unsigned int)in.tellg());
245 in.seekg(0, std::ios::beg);
246 in.read(&contents[0], contents.size());