Mercurial > minori
comparison src/core/filesystem.cpp @ 62:4c6dd5999b39
*: update
1. updated animia
2. use widestrings for filesystem on Windows
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 06:16:06 -0400 |
parents | 327568ad9be9 |
children | 3d2decf093bb |
comparison
equal
deleted
inserted
replaced
61:327568ad9be9 | 62:4c6dd5999b39 |
---|---|
16 # include <sys/stat.h> | 16 # include <sys/stat.h> |
17 #endif | 17 #endif |
18 | 18 |
19 #include "core/filesystem.h" | 19 #include "core/filesystem.h" |
20 #include "core/config.h" | 20 #include "core/config.h" |
21 #include "core/strings.h" | |
21 #include <limits.h> | 22 #include <limits.h> |
22 | 23 |
23 namespace Filesystem { | 24 namespace Filesystem { |
24 | 25 |
25 Path::Path() { _path = ""; } | 26 Path::Path() { _path = ""; } |
34 | 35 |
35 while ((start = _path.find_first_not_of(DELIM, end)) != std::string::npos) { | 36 while ((start = _path.find_first_not_of(DELIM, end)) != std::string::npos) { |
36 end = _path.find(DELIM, start); | 37 end = _path.find(DELIM, start); |
37 temp.append(_path.substr(start, end - start)); | 38 temp.append(_path.substr(start, end - start)); |
38 #ifdef WIN32 | 39 #ifdef WIN32 |
39 if (!CreateDirectoryA(temp.c_str(), NULL) && GetLastError() == ERROR_PATH_NOT_FOUND) | 40 if (!CreateDirectoryW(Strings::ToWstring(temp).c_str(), NULL) && GetLastError() == ERROR_PATH_NOT_FOUND) |
40 /* ERROR_PATH_NOT_FOUND should NOT happen here */ | 41 /* ERROR_PATH_NOT_FOUND should NOT happen here */ |
41 return false; | 42 return false; |
42 #else | 43 #else |
43 struct stat st; | 44 struct stat st; |
44 if (stat(temp.c_str(), &st) == -1) | 45 if (stat(temp.c_str(), &st) == -1) |
49 return true; | 50 return true; |
50 } | 51 } |
51 | 52 |
52 bool Path::Exists() const { | 53 bool Path::Exists() const { |
53 #if WIN32 | 54 #if WIN32 |
54 return GetFileAttributes(_path.c_str()) != INVALID_FILE_ATTRIBUTES; | 55 std::wstring buf = Strings::ToWstring(_path); |
56 return GetFileAttributesW(buf.c_str()) != INVALID_FILE_ATTRIBUTES; | |
55 #else | 57 #else |
56 struct stat st; | 58 struct stat st; |
57 return stat(_path.c_str(), &st) == 0; | 59 return stat(_path.c_str(), &st) == 0; |
58 #endif | 60 #endif |
59 } | 61 } |
85 } | 87 } |
86 | 88 |
87 Path GetDotPath(void) { | 89 Path GetDotPath(void) { |
88 std::string ret = ""; | 90 std::string ret = ""; |
89 #ifdef WIN32 | 91 #ifdef WIN32 |
90 char buf[PATH_MAX + 1]; | 92 std::wstring buf(MAX_PATH, '\0'); |
91 if (SHGetFolderPathAndSubDir(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_DIR, buf) == S_OK) { | 93 if (SHGetFolderPathAndSubDirW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, CONFIG_WDIR, &buf.front()) == S_OK) { |
92 ret += buf; | 94 buf.resize(buf.find('\0')); |
95 ret += Strings::ToUtf8String(buf); | |
93 } | 96 } |
94 #elif defined(MACOSX) | 97 #elif defined(MACOSX) |
95 ret += osx::GetApplicationSupportDirectory(); | 98 ret += osx::GetApplicationSupportDirectory(); |
96 ret += DELIM CONFIG_DIR; | 99 ret += DELIM CONFIG_DIR; |
97 #else // just assume POSIX | 100 #else // just assume POSIX |