[Base] Fix Windows CreateFolder so it creates the entire path properly.

This commit is contained in:
gibbed 2019-07-18 17:47:25 -05:00
parent 324d28adba
commit 9a8d77137c
1 changed files with 5 additions and 7 deletions

View File

@ -45,13 +45,11 @@ bool PathExists(const std::wstring& path) {
}
bool CreateFolder(const std::wstring& path) {
wchar_t folder[kMaxPath] = {0};
auto end = std::wcschr(path.c_str(), xe::kWPathSeparator);
while (end) {
wcsncpy(folder, path.c_str(), end - path.c_str() + 1);
CreateDirectory(folder, NULL);
end = wcschr(++end, xe::kWPathSeparator);
}
size_t pos = 0;
do {
pos = path.find_first_of(xe::kWPathSeparator, pos + 1);
CreateDirectoryW(path.substr(0, pos).c_str(), nullptr);
} while (pos != std::string::npos);
return PathExists(path);
}