From 343df64cf1796217a914c84a91e548631a268d48 Mon Sep 17 00:00:00 2001 From: WuYJ <1427760@qq.com> Date: Sat, 1 Mar 2025 19:37:35 +0800 Subject: [PATCH 1/2] fix compilation errors in the MSVC c++ environment and ensure the fountain mode codec works correctly. --- CMakeLists.txt | 8 ++++++++ src/exe/cimbar/cimbar.cpp | 7 +++++-- src/lib/encoder/Encoder.h | 2 +- src/lib/fountain/fountain_decoder_sink.h | 2 +- src/third_party_lib/fmt/format.h | 4 ++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20103865..096f3683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,10 @@ cmake_minimum_required(VERSION 3.10) project ( libcimbar ) enable_testing() +if (MSVC) + add_compile_options(/FI "iso646.h") +endif() + if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${libcimbar_SOURCE_DIR}/dist" CACHE PATH "..." FORCE) endif() @@ -50,6 +54,10 @@ if(NOT DEFINED CPPFILESYSTEM) set(CPPFILESYSTEM "stdc++fs") endif() +if(MSVC) + set(CPPFILESYSTEM "") +endif() + set (PROJECTS src/lib/bit_file src/lib/chromatic_adaptation diff --git a/src/exe/cimbar/cimbar.cpp b/src/exe/cimbar/cimbar.cpp index 35c00988..5fb6b8c7 100644 --- a/src/exe/cimbar/cimbar.cpp +++ b/src/exe/cimbar/cimbar.cpp @@ -40,8 +40,11 @@ namespace { { if (_done) return; - +#ifdef _WIN32 + if (::feof(stdin)) +#else if (::feof(::stdin)) +#endif { mark_done(); return; @@ -204,7 +207,7 @@ int main(int argc, char** argv) exit(0); } - string outpath = std::experimental::filesystem::current_path(); + string outpath = std::experimental::filesystem::current_path().string(); if (result.count("out")) outpath = result["out"].as(); std::cerr << "Output files will appear in " << outpath << std::endl; diff --git a/src/lib/encoder/Encoder.h b/src/lib/encoder/Encoder.h index fad1e685..76be09e5 100644 --- a/src/lib/encoder/Encoder.h +++ b/src/lib/encoder/Encoder.h @@ -42,7 +42,7 @@ inline unsigned Encoder::encode(const std::string& filename, std::string output_ inline unsigned Encoder::encode_fountain(const std::string& filename, const std::function& on_frame, int compression_level, double redundancy, int canvas_size) { - std::ifstream infile(filename); + std::ifstream infile(filename, std::ios::binary); fountain_encoder_stream::ptr fes = create_fountain_encoder(infile, compression_level); if (!fes) return 0; diff --git a/src/lib/fountain/fountain_decoder_sink.h b/src/lib/fountain/fountain_decoder_sink.h index 118a65fd..cee6f7d5 100644 --- a/src/lib/fountain/fountain_decoder_sink.h +++ b/src/lib/fountain/fountain_decoder_sink.h @@ -36,7 +36,7 @@ class fountain_decoder_sink bool store(const FountainMetadata& md, const std::vector& data) { std::string file_path = fmt::format("{}/{}", _dataDir, get_filename(md)); - OUTSTREAM f(file_path); + OUTSTREAM f(file_path, std::ios::binary); f.write((char*)data.data(), data.size()); if (_logWrites) printf("%s\n", file_path.c_str()); diff --git a/src/third_party_lib/fmt/format.h b/src/third_party_lib/fmt/format.h index e5bd8b11..89fa2fae 100644 --- a/src/third_party_lib/fmt/format.h +++ b/src/third_party_lib/fmt/format.h @@ -1453,7 +1453,11 @@ template class to_utf8 { ++p; if (p == s.end() || (c & 0xfc00) != 0xd800 || (*p & 0xfc00) != 0xdc00) { if (policy == to_utf8_error_policy::abort) return false; +#ifdef _WIN32 + buf.append(string_view("\xef\xbf\xbd")); +#else buf.append(string_view("�")); +#endif --p; } else { c = (c << 10) + static_cast(*p) - 0x35fdc00; From 1a1cd2a59432ac34c5bf42bd618f40f6f5ad17e2 Mon Sep 17 00:00:00 2001 From: WuYJ <1427760@qq.com> Date: Mon, 3 Mar 2025 19:55:54 +0800 Subject: [PATCH 2/2] Undo incorrect changes made to the upstream fmt --- src/third_party_lib/fmt/format.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/third_party_lib/fmt/format.h b/src/third_party_lib/fmt/format.h index 89fa2fae..e5bd8b11 100644 --- a/src/third_party_lib/fmt/format.h +++ b/src/third_party_lib/fmt/format.h @@ -1453,11 +1453,7 @@ template class to_utf8 { ++p; if (p == s.end() || (c & 0xfc00) != 0xd800 || (*p & 0xfc00) != 0xdc00) { if (policy == to_utf8_error_policy::abort) return false; -#ifdef _WIN32 - buf.append(string_view("\xef\xbf\xbd")); -#else buf.append(string_view("�")); -#endif --p; } else { c = (c << 10) + static_cast(*p) - 0x35fdc00;