diff options
| author | Stefan Boberg <[email protected]> | 2021-08-28 21:10:07 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-08-28 21:10:07 +0200 |
| commit | 82d373e7fa382db18bf123f7ca69e343567c5196 (patch) | |
| tree | 34fcedc392c6b9dab7ff77d84f75877988672db8 /zencore | |
| parent | Added basic file logging (diff) | |
| parent | Merge branch 'main' of https://github.com/EpicGames/zen (diff) | |
| download | zen-82d373e7fa382db18bf123f7ca69e343567c5196.tar.xz zen-82d373e7fa382db18bf123f7ca69e343567c5196.zip | |
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zencore')
| -rw-r--r-- | zencore/filesystem.cpp | 22 | ||||
| -rw-r--r-- | zencore/httpserver.cpp | 9 | ||||
| -rw-r--r-- | zencore/include/zencore/filesystem.h | 3 | ||||
| -rw-r--r-- | zencore/include/zencore/httpserver.h | 1 | ||||
| -rw-r--r-- | zencore/include/zencore/scopeguard.h | 2 |
5 files changed, 31 insertions, 6 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) { diff --git a/zencore/httpserver.cpp b/zencore/httpserver.cpp index b52886c0a..eaa8bdfcd 100644 --- a/zencore/httpserver.cpp +++ b/zencore/httpserver.cpp @@ -271,6 +271,15 @@ HttpServerRequest::~HttpServerRequest() } void +HttpServerRequest::WriteResponse(HttpResponse HttpResponseCode, CbPackage Data) +{ + // TODO: implement efficient version of this which can send package attachment + // payloads directly from disk + ZEN_UNUSED(HttpResponseCode, Data); + ZEN_NOT_IMPLEMENTED(); +} + +void HttpServerRequest::WriteResponse(HttpResponse HttpResponseCode, CbObject Data) { #if 0 diff --git a/zencore/include/zencore/filesystem.h b/zencore/include/zencore/filesystem.h index d8140932b..a2d368d6f 100644 --- a/zencore/include/zencore/filesystem.h +++ b/zencore/include/zencore/filesystem.h @@ -43,7 +43,8 @@ struct FileContents ZENCORE_API FileContents ReadFile(std::filesystem::path Path); ZENCORE_API bool ScanFile(std::filesystem::path Path, uint64_t ChunkSize, std::function<void(const void* Data, size_t Size)>&& ProcessFunc); -ZENCORE_API bool WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t BufferCount); +ZENCORE_API void WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t BufferCount); +ZENCORE_API void WriteFile(std::filesystem::path Path, IoBuffer Data); struct CopyFileOptions { diff --git a/zencore/include/zencore/httpserver.h b/zencore/include/zencore/httpserver.h index 86c121366..009fd9f2c 100644 --- a/zencore/include/zencore/httpserver.h +++ b/zencore/include/zencore/httpserver.h @@ -240,6 +240,7 @@ public: virtual void WriteResponse(HttpResponse HttpResponseCode, HttpContentType ContentType, std::u8string_view ResponseString) = 0; void WriteResponse(HttpResponse HttpResponseCode, CbObject Data); + void WriteResponse(HttpResponse HttpResponseCode, CbPackage Package); void WriteResponse(HttpResponse HttpResponseCode, HttpContentType ContentType, std::string_view ResponseString); protected: diff --git a/zencore/include/zencore/scopeguard.h b/zencore/include/zencore/scopeguard.h index ba8cd3094..00836f181 100644 --- a/zencore/include/zencore/scopeguard.h +++ b/zencore/include/zencore/scopeguard.h @@ -6,7 +6,7 @@ namespace zen { template<typename T> -class ScopeGuardImpl +class [[nodiscard]] ScopeGuardImpl { public: inline ScopeGuardImpl(T&& func) : m_guardFunc(func) {} |