From 0396f400a97f71bf743d584acc71a0cdbc155566 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 30 Jun 2023 11:07:10 +0200 Subject: * Added Guid::FromString * Added LoadCompactBinaryObject from file to compactbinaryfile.cpp/h * Added SaveCompactBinary(BinaryWriter& Ar, ...) functions * Added ZEN_PLATFORM_NAME define * Added SystemMetrics functionality to query system properties (see zencore/system.h) --- src/zencore/filesystem.cpp | 69 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 8 deletions(-) (limited to 'src/zencore/filesystem.cpp') 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 +#include #include #include #include @@ -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 DataVec; + + for (const SharedBuffer& Segment : InData.GetSegments()) + { + DataVec.push_back(Segment.AsIoBuffer()); + } + + std::vector 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&& 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)); -- cgit v1.2.3