aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-25 17:42:19 +0800
committercrupest <crupest@outlook.com>2022-01-25 17:42:19 +0800
commit839292efaaf8d997b2cbca7abae8c6e575f6c01a (patch)
tree0f0354fca793e75b90f9d02e86351b2a86601f34 /src/common
parent2ed65999ef6f3e1156427dd3efe04353ae657882 (diff)
downloadcru-839292efaaf8d997b2cbca7abae8c6e575f6c01a.tar.gz
cru-839292efaaf8d997b2cbca7abae8c6e575f6c01a.tar.bz2
cru-839292efaaf8d997b2cbca7abae8c6e575f6c01a.zip
...
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/platform/win/Exception.cpp7
-rw-r--r--src/common/platform/win/Win32FileStream.cpp (renamed from src/common/io/Win32FileStream.cpp)20
3 files changed, 19 insertions, 10 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 0316d9e6..481205a0 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -34,7 +34,7 @@ endif()
if (WIN32)
target_sources(cru_base PRIVATE
- io/Win32FileStream.cpp
+ platform/win/Win32FileStream.cpp
platform/win/Exception.cpp
)
endif()
diff --git a/src/common/platform/win/Exception.cpp b/src/common/platform/win/Exception.cpp
index 34ae8955..def12123 100644
--- a/src/common/platform/win/Exception.cpp
+++ b/src/common/platform/win/Exception.cpp
@@ -32,8 +32,15 @@ inline String Win32MakeMessage(DWORD error_code, String message) {
Win32Error::Win32Error(std::string_view message)
: Win32Error(::GetLastError(), message) {}
+Win32Error::Win32Error(String message)
+ : Win32Error(::GetLastError(), message) {}
+
Win32Error::Win32Error(DWORD error_code, std::string_view message)
: PlatformException(Win32MakeMessage(
error_code, String::FromUtf8(message.data(), message.size()))),
error_code_(error_code) {}
+
+Win32Error::Win32Error(DWORD error_code, String message)
+ : PlatformException(Win32MakeMessage(error_code, message)),
+ error_code_(error_code) {}
} // namespace cru::platform::win
diff --git a/src/common/io/Win32FileStream.cpp b/src/common/platform/win/Win32FileStream.cpp
index e7ee0e6a..5997c570 100644
--- a/src/common/io/Win32FileStream.cpp
+++ b/src/common/platform/win/Win32FileStream.cpp
@@ -1,11 +1,13 @@
-#include "cru/common/io/Win32FileStream.hpp"
+#include "cru/common/platform/win/Win32FileStream.hpp"
-#include "cru/common/Exception.hpp"
#include "cru/common/io/OpenFileFlag.hpp"
+#include "cru/common/platform/win/Exception.hpp"
#include <Windows.h>
-namespace cru::io {
+namespace cru::platform::win {
+using namespace cru::io;
+
namespace details {
struct Win32FileStreamPrivate {
HANDLE handle;
@@ -40,7 +42,7 @@ Win32FileStream::Win32FileStream(String path, OpenFileFlag flags)
dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, nullptr);
if (p_->handle == INVALID_HANDLE_VALUE) {
- throw Exception(u"Failed to call CreateFileW.");
+ throw Win32Error(u"Failed to call CreateFileW.");
}
}
@@ -59,7 +61,7 @@ Index Win32FileStream::Tell() {
LARGE_INTEGER file_pointer;
if (::SetFilePointerEx(p_->handle, offset, &file_pointer, FILE_CURRENT) ==
0) {
- throw Exception(u"Failed to call SetFilePointerEx.");
+ throw Win32Error(u"Failed to call SetFilePointerEx.");
}
return file_pointer.QuadPart;
@@ -81,7 +83,7 @@ void Win32FileStream::Seek(Index offset, SeekOrigin origin) {
LARGE_INTEGER n_offset;
n_offset.QuadPart = offset;
if (::SetFilePointerEx(p_->handle, n_offset, nullptr, dwMoveMethod) == 0) {
- throw Exception(u"Failed to call SetFilePointerEx.");
+ throw Win32Error(u"Failed to call SetFilePointerEx.");
}
}
@@ -92,7 +94,7 @@ Index Win32FileStream::Read(std::byte* buffer, Index offset, Index size) {
DWORD dwRead;
if (::ReadFile(p_->handle, buffer + offset, size, &dwRead, nullptr) == 0) {
- throw Exception(u"Failed to call ReadFile.");
+ throw Win32Error(u"Failed to call ReadFile.");
}
return dwRead;
}
@@ -106,7 +108,7 @@ Index Win32FileStream::Write(const std::byte* buffer, Index offset,
DWORD dwWritten;
if (::WriteFile(p_->handle, buffer + offset, size, &dwWritten, nullptr) ==
0) {
- throw Exception(u"Failed to call WriteFile.");
+ throw Win32Error(u"Failed to call WriteFile.");
}
return dwWritten;
@@ -124,4 +126,4 @@ void Win32FileStream::CheckClosed() {
if (closed_) throw Exception(u"Stream is closed.");
}
-} // namespace cru::io
+} // namespace cru::platform::win