Skip to content

Commit

Permalink
Common: Fix Recursive CreateDirectoryPath() on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastRar authored and F0bes committed Sep 12, 2024
1 parent 4e19794 commit 0cf4b76
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion common/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1732,8 +1732,26 @@ bool FileSystem::CreateDirectoryPath(const char* Path, bool Recursive, Error* er
std::wstring tempPath;
tempPath.reserve(pathLength);

// for absolute paths, we need to skip over the path root
size_t rootLength = 0;
if (Path::IsAbsolute(Path))
{
const wchar_t* root_start = wpath.c_str();
wchar_t* root_end;
const HRESULT hr = PathCchSkipRoot(const_cast<wchar_t*>(root_start), &root_end);
if (FAILED(hr))
{
Error::SetHResult(error, "PathCchSkipRoot() failed: ", hr);
return false;
}
rootLength = static_cast<size_t>(root_end - root_start);

// copy path root
tempPath.append(wpath, 0, rootLength);
}

// create directories along the path
for (size_t i = 0; i < pathLength; i++)
for (size_t i = rootLength; i < pathLength; i++)
{
if (wpath[i] == L'\\' || wpath[i] == L'/')
{
Expand Down

0 comments on commit 0cf4b76

Please sign in to comment.