From 37e211abfbb2dad2dca79c8bcf80ec4a41e25ad3 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Wed, 10 Mar 2021 03:14:55 -0800 Subject: [PATCH 1/3] Don't fail file open/writes silently --- cppwinrt/text_writer.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cppwinrt/text_writer.h b/cppwinrt/text_writer.h index 5045b9395..1e3734aa2 100644 --- a/cppwinrt/text_writer.h +++ b/cppwinrt/text_writer.h @@ -157,9 +157,16 @@ namespace cppwinrt { if (!file_equal(filename)) { - std::ofstream file{ filename, std::ios::out | std::ios::binary }; - file.write(m_first.data(), m_first.size()); - file.write(m_second.data(), m_second.size()); + std::ofstream file; + file.exceptions(std::ofstream::failbit | std::ofstream::badbit); + try { + file.open(filename, std::ios::out | std::ios::binary); + file.write(m_first.data(), m_first.size()); + file.write(m_second.data(), m_second.size()); + } + catch (std::ofstream::failure const& e) { + throw std::filesystem::filesystem_error(e.what(), filename, std::io_errc::stream); + } } m_first.clear(); m_second.clear(); From 7b5eae442442df591b3cc02f1487079a7657f46b Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Wed, 10 Mar 2021 03:21:49 -0800 Subject: [PATCH 2/3] Turn on long path support for cppwinrt --- cppwinrt/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cppwinrt/main.cpp b/cppwinrt/main.cpp index b46e08f58..c0a2721cd 100644 --- a/cppwinrt/main.cpp +++ b/cppwinrt/main.cpp @@ -8,6 +8,7 @@ #include "component_writers.h" #include "file_writers.h" #include "type_writers.h" +#include namespace cppwinrt { @@ -374,5 +375,7 @@ Where is one or more of: int main(int const argc, char** argv) { + // Dynamically enable long path support + ((unsigned char*)(NtCurrentTeb()->ProcessEnvironmentBlock))[3] |= 0x80; return cppwinrt::run(argc, argv); } From 116379cd1b0bfeecbbd60176845db0a961de9c14 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Wed, 10 Mar 2021 10:35:44 -0800 Subject: [PATCH 3/3] move braces to next line --- cppwinrt/text_writer.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cppwinrt/text_writer.h b/cppwinrt/text_writer.h index 1e3734aa2..bde87806e 100644 --- a/cppwinrt/text_writer.h +++ b/cppwinrt/text_writer.h @@ -159,12 +159,14 @@ namespace cppwinrt { std::ofstream file; file.exceptions(std::ofstream::failbit | std::ofstream::badbit); - try { + try + { file.open(filename, std::ios::out | std::ios::binary); file.write(m_first.data(), m_first.size()); file.write(m_second.data(), m_second.size()); } - catch (std::ofstream::failure const& e) { + catch (std::ofstream::failure const& e) + { throw std::filesystem::filesystem_error(e.what(), filename, std::io_errc::stream); } }