aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-08-28 21:03:50 +0200
committerStefan Boberg <[email protected]>2021-08-28 21:03:50 +0200
commit5acd66ed9488664b2f1aaa238a3b982b06f4d115 (patch)
tree43c928ddda0ef7480a29612906cb005ba3fa1fbc /zencore/filesystem.cpp
parenttrivial: Simple comment edit (diff)
downloadzen-5acd66ed9488664b2f1aaa238a3b982b06f4d115.tar.xz
zen-5acd66ed9488664b2f1aaa238a3b982b06f4d115.zip
Added WriteFile() overload which accepts a single IoBuffer
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 908810773..591630b75 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -400,19 +400,26 @@ CopyFile(std::filesystem::path FromPath, std::filesystem::path ToPath, const Cop
return Success;
}
-bool
+void
WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t BufferCount)
{
using namespace fmt::literals;
CAtlFile Outfile;
HRESULT hRes = Outfile.Create(Path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS);
+ if (hRes == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND))
+ {
+ zen::CreateDirectories(Path.parent_path());
+
+ hRes = Outfile.Create(Path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS);
+ }
+
if (FAILED(hRes))
{
zen::ThrowSystemException(hRes, "File open failed for '{}'"_format(Path).c_str());
}
- // TODO: this could be block-enlightened
+ // TODO: this should be block-enlightened
for (size_t i = 0; i < BufferCount; ++i)
{
@@ -421,7 +428,7 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer
while (WriteSize)
{
- uint64_t ChunkSize = zen::Min<uint64_t>(WriteSize, uint64_t(2) * 1024 * 1024 * 1024);
+ const uint64_t ChunkSize = zen::Min<uint64_t>(WriteSize, uint64_t(2) * 1024 * 1024 * 1024);
hRes = Outfile.Write(DataPtr, gsl::narrow_cast<uint32_t>(WriteSize));
@@ -434,10 +441,17 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer
DataPtr = reinterpret_cast<const uint8_t*>(DataPtr) + ChunkSize;
}
}
+}
- return true;
+void
+WriteFile(std::filesystem::path Path, IoBuffer Data)
+{
+ const IoBuffer* const DataPtr = &Data;
+
+ WriteFile(Path, &DataPtr, 1);
}
+
FileContents
ReadFile(std::filesystem::path Path)
{