diff --git a/cpp/command/contribute.cpp b/cpp/command/contribute.cpp index 7a403776fa..ee9a551ebd 100644 --- a/cpp/command/contribute.cpp +++ b/cpp/command/contribute.cpp @@ -22,6 +22,15 @@ #include "../command/commandline.h" #include "../main.h" +#if __MINGW32__ +// `std::wstring_convert` needs explicit including in case of MINGW +#include +#endif + +#ifdef OS_IS_WINDOWS +#include +#endif + #ifndef BUILD_DISTRIBUTED int MainCmds::contribute(const std::vector& args) { @@ -802,10 +811,17 @@ int MainCmds::contribute(const vector& args) { std::unique_ptr outputEachMove = nullptr; std::function flushOutputEachMove = nullptr; if(gameLoopThreadIdx == 0 && watchOngoingGameInFile) { - // TODO someday - doesn't handle non-ascii paths. #ifdef OS_IS_WINDOWS + std::wstring_convert> converter; + std::wstring watchOngoingGameInFileWideName; + try { + watchOngoingGameInFileWideName = converter.from_bytes(watchOngoingGameInFileName); + } + catch(const std::range_error&) { + throw StringError("watchOngoingGameFileName is not valid UTF-8: " + watchOngoingGameInFileName); + } FILE* file = NULL; - fopen_s(&file, watchOngoingGameInFileName.c_str(), "a"); + file = _wfopen(watchOngoingGameInFileWideName.c_str(), L"a"); if(file == NULL) throw StringError("Could not open file: " + watchOngoingGameInFileName); outputEachMove = std::make_unique(file);