diff options
Diffstat (limited to 'src/zencore/filesystem.cpp')
| -rw-r--r-- | src/zencore/filesystem.cpp | 69 |
1 files changed, 61 insertions, 8 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp index cde4c52ab..059d1b5f0 100644 --- a/src/zencore/filesystem.cpp +++ b/src/zencore/filesystem.cpp @@ -2,6 +2,7 @@ #include <zencore/filesystem.h> +#include <zencore/compositebuffer.h> #include <zencore/except.h> #include <zencore/fmtutils.h> #include <zencore/iobuffer.h> @@ -100,6 +101,8 @@ WipeDirectory(const wchar_t* DirPath) WIN32_FIND_DATAW FindData; HANDLE hFind = FindFirstFileW(Pattern.c_str(), &FindData); + bool Success = true; + if (hFind != nullptr) { do @@ -135,27 +138,43 @@ WipeDirectory(const wchar_t* DirPath) { if (FindData.dwFileAttributes & FILE_ATTRIBUTE_RECALL_ON_OPEN) { - DeleteReparsePoint(Path.c_str(), FindData.dwReserved0); + if (!DeleteReparsePoint(Path.c_str(), FindData.dwReserved0)) + { + Success = false; + } } if (FindData.dwFileAttributes & FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS) { - DeleteReparsePoint(Path.c_str(), FindData.dwReserved0); + if (!DeleteReparsePoint(Path.c_str(), FindData.dwReserved0)) + { + Success = false; + } } - bool Success = DeleteDirectories(Path.c_str()); + bool Succeeded = DeleteDirectories(Path.c_str()); - if (!Success) + if (!Succeeded) { if (FindData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { - DeleteReparsePoint(Path.c_str(), FindData.dwReserved0); + if (!DeleteReparsePoint(Path.c_str(), FindData.dwReserved0)) + { + Success = false; + } } } } else { - DeleteFileW(Path.c_str()); + BOOL Succeeded = DeleteFileW(Path.c_str()); + + if (!Succeeded) + { + // We should emit a warning here, but this is quite low level so care + // needs to be taken. + Success = false; + } } } } while (FindNextFileW(hFind, &FindData) == TRUE); @@ -633,6 +652,26 @@ WriteFile(std::filesystem::path Path, IoBuffer Data) WriteFile(Path, &DataPtr, 1); } +void +WriteFile(std::filesystem::path Path, CompositeBuffer InData) +{ + std::vector<IoBuffer> DataVec; + + for (const SharedBuffer& Segment : InData.GetSegments()) + { + DataVec.push_back(Segment.AsIoBuffer()); + } + + std::vector<const IoBuffer*> DataPtrs; + + for (IoBuffer& Data : DataVec) + { + DataPtrs.push_back(&Data); + } + + WriteFile(Path, DataPtrs.data(), DataPtrs.size()); +} + IoBuffer FileContents::Flatten() { @@ -676,7 +715,13 @@ ReadFile(std::filesystem::path Path) void* Handle; #if ZEN_PLATFORM_WINDOWS - windows::Handle FromFile(CreateFileW(Path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr)); + windows::Handle FromFile(CreateFileW(Path.c_str(), + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + nullptr, + OPEN_EXISTING, + 0, + nullptr)); if (FromFile == INVALID_HANDLE_VALUE) { FromFile.Detach(); @@ -717,7 +762,13 @@ bool ScanFile(std::filesystem::path Path, const uint64_t ChunkSize, std::function<void(const void* Data, size_t Size)>&& ProcessFunc) { #if ZEN_PLATFORM_WINDOWS - windows::Handle FromFile(CreateFileW(Path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr)); + windows::Handle FromFile(CreateFileW(Path.c_str(), + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + nullptr, + OPEN_EXISTING, + 0, + nullptr)); if (FromFile == INVALID_HANDLE_VALUE) { FromFile.Detach(); @@ -1047,6 +1098,8 @@ std::filesystem::path GetRunningExecutablePath() { #if ZEN_PLATFORM_WINDOWS + // TODO: make this long path aware + TCHAR ExePath[MAX_PATH]; DWORD PathLength = GetModuleFileName(NULL, ExePath, ZEN_ARRAY_COUNT(ExePath)); |