aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zen/internalfile.cpp52
-rw-r--r--zen/internalfile.h8
-rw-r--r--zenserver/cache/cachestore.cpp8
-rw-r--r--zenstore/caslog.cpp15
4 files changed, 50 insertions, 33 deletions
diff --git a/zen/internalfile.cpp b/zen/internalfile.cpp
index 44c60511e..b88ec51dc 100644
--- a/zen/internalfile.cpp
+++ b/zen/internalfile.cpp
@@ -2,8 +2,12 @@
#include "internalfile.h"
+#include <zencore/filesystem.h>
+#include <zencore/fmtutils.h>
#include <zencore/windows.h>
+#include <spdlog/spdlog.h>
+
#include <gsl/gsl-lite.hpp>
#define ZEN_USE_SLIST ZEN_PLATFORM_WINDOWS
@@ -120,21 +124,23 @@ FileBufferManager::ReturnBuffer(zen::IoBuffer Buffer)
//////////////////////////////////////////////////////////////////////////
+using namespace fmt::literals;
+
InternalFile::InternalFile()
{
}
InternalFile::~InternalFile()
{
- if (m_memory)
- _aligned_free(m_memory);
+ if (m_Memory)
+ _aligned_free(m_Memory);
}
size_t
InternalFile::GetFileSize()
{
ULONGLONG sz;
- m_file.GetSize(sz);
+ m_File.GetSize(sz);
return size_t(sz);
}
@@ -144,11 +150,11 @@ InternalFile::OpenWrite(std::filesystem::path FileName, bool IsCreate)
{
const DWORD dwCreationDisposition = IsCreate ? CREATE_ALWAYS : OPEN_EXISTING;
- HRESULT hRes = m_file.Create(FileName.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, dwCreationDisposition);
+ HRESULT hRes = m_File.Create(FileName.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, dwCreationDisposition);
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to open file");
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to open file for writing: '{}'"_format(FileName));
}
}
@@ -157,30 +163,30 @@ InternalFile::OpenRead(std::filesystem::path FileName)
{
const DWORD dwCreationDisposition = OPEN_EXISTING;
- HRESULT hRes = m_file.Create(FileName.c_str(), GENERIC_READ, FILE_SHARE_READ, dwCreationDisposition);
+ HRESULT hRes = m_File.Create(FileName.c_str(), GENERIC_READ, FILE_SHARE_READ, dwCreationDisposition);
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to open file");
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to open file for reading: '{}'"_format(FileName));
}
}
const void*
InternalFile::MemoryMapFile()
{
- auto fileSize = GetFileSize();
+ auto FileSize = GetFileSize();
- if (fileSize > 100 * 1024 * 1024)
+ if (FileSize > 100 * 1024 * 1024)
{
- m_mmap.MapFile(m_file);
+ m_Mmap.MapFile(m_File);
- return m_mmap.GetData();
+ return m_Mmap.GetData();
}
- m_memory = _aligned_malloc(fileSize, 64);
- Read(m_memory, fileSize, 0);
+ m_Memory = _aligned_malloc(FileSize, 64);
+ Read(m_Memory, FileSize, 0);
- return m_memory;
+ return m_Memory;
}
void
@@ -191,32 +197,34 @@ InternalFile::Read(void* Data, uint64_t Size, uint64_t Offset)
ovl.Offset = DWORD(Offset & 0xffff'ffffu);
ovl.OffsetHigh = DWORD(Offset >> 32);
- HRESULT hRes = m_file.Read(Data, gsl::narrow<DWORD>(Size), &ovl);
+ HRESULT hRes = m_File.Read(Data, gsl::narrow<DWORD>(Size), &ovl);
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to read from file" /* TODO: add context */);
+ throw std::system_error(GetLastError(),
+ std::system_category(),
+ "Failed to read from file '{}'"_format(zen::PathFromHandle(m_File)));
}
}
void
InternalFile::Write(const void* Data, uint64_t Size, uint64_t Offset)
{
- OVERLAPPED ovl{};
+ OVERLAPPED Ovl{};
- ovl.Offset = DWORD(Offset & 0xffff'ffffu);
- ovl.OffsetHigh = DWORD(Offset >> 32);
+ Ovl.Offset = DWORD(Offset & 0xffff'ffffu);
+ Ovl.OffsetHigh = DWORD(Offset >> 32);
- HRESULT hRes = m_file.Write(Data, gsl::narrow<DWORD>(Size), &ovl);
+ HRESULT hRes = m_File.Write(Data, gsl::narrow<DWORD>(Size), &Ovl);
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file" /* TODO: add context */);
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file '{}'"_format(zen::PathFromHandle(m_File)));
}
}
void
InternalFile::Flush()
{
- m_file.Flush();
+ m_File.Flush();
}
diff --git a/zen/internalfile.h b/zen/internalfile.h
index 2d1f9b00f..c6071418e 100644
--- a/zen/internalfile.h
+++ b/zen/internalfile.h
@@ -46,13 +46,13 @@ public:
void Write(const void* Data, uint64_t Size, uint64_t Offset);
void Flush();
- void* Handle() { return m_file; }
+ void* Handle() { return m_File; }
const void* MemoryMapFile();
size_t GetFileSize();
private:
- CAtlFile m_file;
- CAtlFileMappingBase m_mmap;
- void* m_memory = nullptr;
+ CAtlFile m_File;
+ CAtlFileMappingBase m_Mmap;
+ void* m_Memory = nullptr;
};
diff --git a/zenserver/cache/cachestore.cpp b/zenserver/cache/cachestore.cpp
index fc218de6b..5b0358994 100644
--- a/zenserver/cache/cachestore.cpp
+++ b/zenserver/cache/cachestore.cpp
@@ -7,6 +7,7 @@
#include <fmt/core.h>
#include <spdlog/spdlog.h>
#include <zencore/filesystem.h>
+#include <zencore/fmtutils.h>
#include <zencore/iobuffer.h>
#include <zencore/string.h>
#include <zencore/thread.h>
@@ -18,6 +19,7 @@
#include <atlfile.h>
using namespace zen;
+using namespace fmt::literals;
namespace UE {
@@ -720,7 +722,9 @@ ZenFile::Read(void* Data, uint64_t Size, uint64_t Offset)
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to read from file" /* TODO: add context */);
+ throw std::system_error(GetLastError(),
+ std::system_category(),
+ "Failed to read from file '{}'"_format(zen::PathFromHandle(m_File)));
}
}
@@ -736,7 +740,7 @@ ZenFile::Write(const void* Data, uint64_t Size, uint64_t Offset)
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file" /* TODO: add context */);
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file '{}'"_format(zen::PathFromHandle(m_File)));
}
}
diff --git a/zenstore/caslog.cpp b/zenstore/caslog.cpp
index 0f918bfd8..6d9e22f88 100644
--- a/zenstore/caslog.cpp
+++ b/zenstore/caslog.cpp
@@ -5,6 +5,8 @@
#include "CompactCas.h"
#include <zencore/except.h>
+#include <zencore/filesystem.h>
+#include <zencore/fmtutils.h>
#include <zencore/memory.h>
#include <zencore/string.h>
#include <zencore/thread.h>
@@ -12,6 +14,7 @@
#include <xxhash.h>
+#include <spdlog/spdlog.h>
#include <gsl/gsl-lite.hpp>
#include <functional>
@@ -24,6 +27,8 @@ struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax erro
namespace zen {
+using namespace fmt::literals;
+
uint32_t
CasLogFile::FileHeader::ComputeChecksum()
{
@@ -49,7 +54,7 @@ CasLogFile::Open(std::filesystem::path FileName, size_t RecordSize, bool IsCreat
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to open log file" /* TODO: add path */);
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to open log file '{}'"_format(FileName));
}
uint64_t AppendOffset = 0;
@@ -135,7 +140,7 @@ CasLogFile::Append(const void* DataPointer, uint64_t DataSize)
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to write to log file" /* TODO: add context */);
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to write to log file '{}'"_format(zen::PathFromHandle(m_File)));
}
}
@@ -156,7 +161,7 @@ CasBlobFile::Open(std::filesystem::path FileName, bool isCreate)
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to open bucket sobs file");
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to open bucket sobs file '{}'"_format(FileName));
}
}
@@ -172,7 +177,7 @@ CasBlobFile::Read(void* Data, uint64_t Size, uint64_t Offset)
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to read from file" /* TODO: add context */);
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to read from file '{}'"_format(zen::PathFromHandle(m_File)));
}
}
@@ -198,7 +203,7 @@ CasBlobFile::Write(const void* Data, uint64_t Size, uint64_t Offset)
if (FAILED(hRes))
{
- throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file" /* TODO: add context */);
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file '{}'"_format(zen::PathFromHandle(m_File)));
}
}