Skip to content

Commit af4fd6c

Browse files
committed
fix(capture): convert std::filesystem::path::u8string() cleanly under C++20
1 parent b6922e1 commit af4fd6c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎src/screen_capture_common.cpp‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
namespace nativeapi::detail {
2424
namespace {
2525
constexpr int kMaxDimension = 32768;
26+
std::string PathToUtf8(const std::filesystem::path& path) {
27+
auto utf8 = path.u8string();
28+
return std::string(reinterpret_cast<const char*>(utf8.data()), utf8.size());
29+
}
2630
bool FrameValid(const CaptureFrame& frame) {
2731
return frame.width > 0 && frame.height > 0 && frame.width <= kMaxDimension &&
2832
frame.height <= kMaxDimension &&
@@ -69,7 +73,7 @@ bool ValidRecordingPath(const std::string& path) {
6973
try {
7074
auto p = std::filesystem::u8path(path);
7175
if (!p.is_absolute()) return false;
72-
auto extension = p.extension().u8string();
76+
auto extension = PathToUtf8(p.extension());
7377
std::transform(extension.begin(), extension.end(), extension.begin(),
7478
[](unsigned char c) { return char(std::tolower(c)); });
7579
return extension == ".mp4";
@@ -142,8 +146,8 @@ bool CaptureOutputFile::Create(const std::string& destination, std::string& erro
142146
auto directory = path.parent_path() /
143147
(".nativeapi-recording-" + std::to_string(random()) + "-" + std::to_string(random()));
144148
if (std::filesystem::create_directory(directory, ec)) {
145-
directory_ = directory.u8string();
146-
temporary_ = (directory / "video.mp4").u8string();
149+
directory_ = PathToUtf8(directory);
150+
temporary_ = PathToUtf8(directory / "video.mp4");
147151
destination_ = destination;
148152
return true;
149153
}

0 commit comments

Comments
 (0)