aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base/SubProcess.cpp13
-rw-r--r--src/base/io/Stream.cpp4
-rw-r--r--src/base/log/StdioLogTarget.cpp4
-rw-r--r--src/base/platform/win/DebugLogTarget.cpp6
-rw-r--r--src/base/platform/win/Exception.cpp6
-rw-r--r--src/base/platform/win/Win32FileStream.cpp37
-rw-r--r--src/platform/gui/win/Window.cpp7
-rw-r--r--src/ui/render/ScrollBar.cpp1
8 files changed, 33 insertions, 45 deletions
diff --git a/src/base/SubProcess.cpp b/src/base/SubProcess.cpp
index 1133b848..9a6ee64f 100644
--- a/src/base/SubProcess.cpp
+++ b/src/base/SubProcess.cpp
@@ -7,11 +7,6 @@
#endif
namespace cru {
-
-#ifdef CRU_PLATFORM_UNIX
-using ThisPlatformSubProcessImpl = platform::unix::PosixSpawnSubProcessImpl;
-#endif
-
PlatformSubProcess::PlatformSubProcess(
SubProcessStartInfo start_info,
std::shared_ptr<IPlatformSubProcessImpl> impl)
@@ -156,8 +151,14 @@ SubProcessExitResult SubProcess::Call(
}
SubProcess::SubProcess(SubProcessStartInfo start_info) {
+
+#ifdef CRU_PLATFORM_UNIX
platform_process_.reset(new PlatformSubProcess(
- std::move(start_info), std::make_shared<ThisPlatformSubProcessImpl>()));
+ std::move(start_info),
+ std::make_shared<platform::unix::PosixSpawnSubProcessImpl>()));
+#else
+ NotImplemented();
+#endif
platform_process_->Start();
}
diff --git a/src/base/io/Stream.cpp b/src/base/io/Stream.cpp
index 9b7ef856..4cb58eca 100644
--- a/src/base/io/Stream.cpp
+++ b/src/base/io/Stream.cpp
@@ -171,11 +171,11 @@ Index Stream::DoGetSize() {
}
Index Stream::DoRead(std::byte* buffer, Index offset, Index size) {
- throw Exception(u"Stream is readable but DoSeek is not implemented.");
+ throw Exception(u"Stream is readable but DoRead is not implemented.");
}
Index Stream::DoWrite(const std::byte* buffer, Index offset, Index size) {
- throw Exception(u"Stream is writable but DoSeek is not implemented.");
+ throw Exception(u"Stream is writable but DoWrite is not implemented.");
}
void Stream::DoFlush() {}
diff --git a/src/base/log/StdioLogTarget.cpp b/src/base/log/StdioLogTarget.cpp
index 45203f2c..a17e91b6 100644
--- a/src/base/log/StdioLogTarget.cpp
+++ b/src/base/log/StdioLogTarget.cpp
@@ -1,5 +1,9 @@
#include "cru/base/log/StdioLogTarget.h"
+#ifdef _WIN32
+#include "cru/base/String.h"
+#endif
+
#include <iostream>
namespace cru::log {
diff --git a/src/base/platform/win/DebugLogTarget.cpp b/src/base/platform/win/DebugLogTarget.cpp
index 89bd3d19..afbab620 100644
--- a/src/base/platform/win/DebugLogTarget.cpp
+++ b/src/base/platform/win/DebugLogTarget.cpp
@@ -1,10 +1,12 @@
#include "cru/base/platform/win/DebugLogTarget.h"
+#include "cru/base/String.h"
+
namespace cru::platform::win {
-void WinDebugLogTarget::Write(::cru::log::LogLevel level, StringView s) {
+void WinDebugLogTarget::Write(::cru::log::LogLevel level, std::string s) {
CRU_UNUSED(level)
- String m = s.ToString();
+ String m = String::FromUtf8(s);
::OutputDebugStringW(reinterpret_cast<const wchar_t*>(m.c_str()));
}
} // namespace cru::platform::win
diff --git a/src/base/platform/win/Exception.cpp b/src/base/platform/win/Exception.cpp
index 5ff6146b..941875f7 100644
--- a/src/base/platform/win/Exception.cpp
+++ b/src/base/platform/win/Exception.cpp
@@ -14,12 +14,12 @@ inline String HResultMakeMessage(HRESULT h_result,
}
HResultError::HResultError(HRESULT h_result)
- : PlatformException(HResultMakeMessage(h_result, std::nullopt)),
+ : Exception(HResultMakeMessage(h_result, std::nullopt)),
h_result_(h_result) {}
HResultError::HResultError(HRESULT h_result,
std::string_view additional_message)
- : PlatformException(HResultMakeMessage(
+ : Exception(HResultMakeMessage(
h_result, String::FromUtf8(additional_message.data(),
additional_message.size()))),
h_result_(h_result) {}
@@ -33,6 +33,6 @@ Win32Error::Win32Error(String message)
: Win32Error(::GetLastError(), message) {}
Win32Error::Win32Error(DWORD error_code, String message)
- : PlatformException(Win32MakeMessage(error_code, message)),
+ : Exception(Win32MakeMessage(error_code, message)),
error_code_(error_code) {}
} // namespace cru::platform::win
diff --git a/src/base/platform/win/Win32FileStream.cpp b/src/base/platform/win/Win32FileStream.cpp
index 54e6ae45..f3809b3e 100644
--- a/src/base/platform/win/Win32FileStream.cpp
+++ b/src/base/platform/win/Win32FileStream.cpp
@@ -14,7 +14,8 @@ namespace cru::platform::win {
using namespace cru::io;
Win32FileStream::Win32FileStream(String path, OpenFileFlag flags)
- : path_(std::move(path)),
+ : Stream(true, true, true),
+ path_(std::move(path)),
flags_(flags),
p_(new details::Win32FileStreamPrivate()) {
DWORD grfMode = STGM_SHARE_DENY_NONE;
@@ -46,15 +47,11 @@ Win32FileStream::Win32FileStream(String path, OpenFileFlag flags)
}
Win32FileStream::~Win32FileStream() {
- Close();
+ DoClose();
delete p_;
}
-bool Win32FileStream::CanSeek() { return true; }
-
-Index Win32FileStream::Seek(Index offset, SeekOrigin origin) {
- CheckClosed();
-
+Index Win32FileStream::DoSeek(Index offset, SeekOrigin origin) {
DWORD dwOrigin = 0;
if (origin == SeekOrigin::Current) {
@@ -74,23 +71,13 @@ Index Win32FileStream::Seek(Index offset, SeekOrigin origin) {
return n_new_offset.QuadPart;
}
-bool Win32FileStream::CanRead() { return true; }
-
-Index Win32FileStream::Read(std::byte* buffer, Index offset, Index size) {
- if (size < 0) {
- throw Exception(u"Size must be greater than 0.");
- }
-
- CheckClosed();
-
+Index Win32FileStream::DoRead(std::byte* buffer, Index offset, Index size) {
ULONG n_read;
ThrowIfFailed(p_->stream_->Read(buffer + offset, size, &n_read));
return n_read;
}
-bool Win32FileStream::CanWrite() { return true; }
-
-Index Win32FileStream::Write(const std::byte* buffer, Index offset,
+Index Win32FileStream::DoWrite(const std::byte* buffer, Index offset,
Index size) {
if (size < 0) {
throw Exception(u"Size must be greater than 0.");
@@ -104,19 +91,13 @@ Index Win32FileStream::Write(const std::byte* buffer, Index offset,
return n_written;
}
-void Win32FileStream::Close() {
- if (closed_) return;
+void Win32FileStream::DoClose() {
+ CRU_STREAM_BEGIN_CLOSE
- if (p_->stream_) {
+ if (p_->stream_) {
p_->stream_->Release();
p_->stream_ = nullptr;
}
- closed_ = true;
}
-
-void Win32FileStream::CheckClosed() {
- if (closed_) throw Exception(u"Stream is closed.");
-}
-
} // namespace cru::platform::win
diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp
index 5bd14323..eeb2cde4 100644
--- a/src/platform/gui/win/Window.cpp
+++ b/src/platform/gui/win/Window.cpp
@@ -245,10 +245,9 @@ void WinNativeWindow::SetCursor(std::shared_ptr<ICursor> cursor) {
auto lg = [](StringView reason) {
CRU_LOG_TAG_WARN(
-
- u"Failed to set cursor because {} when window is visible. (We need to "
- u"update cursor if it is inside the window.) Last error code: {}.",
- reason, ::GetLastError());
+ "Failed to set cursor because {} when window is visible. (We need to "
+ "update cursor if it is inside the window.) Last error code: {}.",
+ reason.ToUtf8(), ::GetLastError());
};
::POINT point;
diff --git a/src/ui/render/ScrollBar.cpp b/src/ui/render/ScrollBar.cpp
index 326f7504..af2851cd 100644
--- a/src/ui/render/ScrollBar.cpp
+++ b/src/ui/render/ScrollBar.cpp
@@ -23,6 +23,7 @@
#include <optional>
#include <stdexcept>
#include <string>
+#include <array>
namespace cru::ui::render {
using namespace std::chrono_literals;