From b5bcee65ee8c0bfba3b83075ec7e82ffc04c4a2e Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Mon, 2 Feb 2026 19:12:05 +0100 Subject: [PATCH 1/3] fix garbled errormessage on windows Thanks for analysing and suggestion @desertwitch See: https://github.com/Parchive/par2cmdline/issues/248#issuecomment-3833085644 Fixes: #248, #253 Signed-off-by: BlackEagle --- src/diskfile.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diskfile.cpp b/src/diskfile.cpp index bf5152e..3781376 100644 --- a/src/diskfile.cpp +++ b/src/diskfile.cpp @@ -1074,15 +1074,15 @@ std::string DiskFile::ErrorMessage(DWORD error) std::string result; LPVOID lpMsgBuf; - if (::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&lpMsgBuf, + (LPWSTR)&lpMsgBuf, 0, NULL)) { - result = (char*)lpMsgBuf; + result = utf8::WideToUtf8((wchar_t*)lpMsgBuf); LocalFree(lpMsgBuf); } else From f3ec94e5f3a816cd7bcb07de27af97c9389c0f1a Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Mon, 2 Feb 2026 19:34:13 +0100 Subject: [PATCH 2/3] par2cmdline, always force UTF-8 on windows Signed-off-by: BlackEagle --- src/par2cmdline.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/par2cmdline.cpp b/src/par2cmdline.cpp index 8f1b2f8..14a59f4 100644 --- a/src/par2cmdline.cpp +++ b/src/par2cmdline.cpp @@ -46,7 +46,9 @@ int main(int argc, char* argv[]) #ifdef _MSC_VER // Memory leak checking _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF | /*_CRTDBG_CHECK_CRT_DF | */_CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif +#ifdef _WIN32 SetConsoleOutputCP(CP_UTF8); utf8::WideToUtf8ArgsAdapter wargsAdapter{ argc, wargv }; From 331bb73a871162b887b78ad90340b79f2e674a5b Mon Sep 17 00:00:00 2001 From: BlackEagle Date: Mon, 2 Feb 2026 19:35:27 +0100 Subject: [PATCH 3/3] improve windows wide format use consistency Where use of non wide format functions was found, replaced them with wide format functions for windows, so it should be consistent for windows now. Signed-off-by: BlackEagle --- src/diskfile.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/diskfile.cpp b/src/diskfile.cpp index 3781376..5f6f702 100644 --- a/src/diskfile.cpp +++ b/src/diskfile.cpp @@ -89,7 +89,7 @@ bool DiskFile::CreateParentDirectory(std::string _pathname) if (!DiskFile::CreateParentDirectory(path)) return false; - if (!CreateDirectory(wpath.c_str(), NULL)) + if (!CreateDirectoryW(wpath.c_str(), NULL)) { DWORD error = ::GetLastError(); @@ -116,7 +116,7 @@ bool DiskFile::Create(std::string _filename, u64 _filesize) // Create the file std::wstring wfilename = utf8::Utf8ToWide(_filename); - hFile = ::CreateFile(wfilename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL); + hFile = ::CreateFileW(wfilename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { DWORD error = ::GetLastError(); @@ -143,7 +143,7 @@ bool DiskFile::Create(std::string _filename, u64 _filesize) ::CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; - ::DeleteFile(wfilename.c_str()); + ::DeleteFileW(wfilename.c_str()); return false; } @@ -158,7 +158,7 @@ bool DiskFile::Create(std::string _filename, u64 _filesize) ::CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; - ::DeleteFile(wfilename.c_str()); + ::DeleteFileW(wfilename.c_str()); return false; } @@ -245,7 +245,7 @@ bool DiskFile::Open(const std::string &_filename, u64 _filesize) filesize = _filesize; std::wstring wfilename = utf8::Utf8ToWide(_filename); - hFile = ::CreateFile(wfilename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + hFile = ::CreateFileW(wfilename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { DWORD error = ::GetLastError(); @@ -377,8 +377,8 @@ std::unique_ptr< std::list > DiskFile::FindFiles(std::string path, std::list *matches = new std::list; std::wstring wwildcard = utf8::Utf8ToWide(path + wildcard); - WIN32_FIND_DATA fd; - HANDLE h = ::FindFirstFile(wwildcard.c_str(), &fd); + WIN32_FIND_DATAW fd; + HANDLE h = ::FindFirstFileW(wwildcard.c_str(), &fd); if (h != INVALID_HANDLE_VALUE) { do @@ -401,7 +401,7 @@ std::unique_ptr< std::list > DiskFile::FindFiles(std::string path, // append without requiring ordering matches->splice(matches->end(), *dirmatches); } - } while (::FindNextFile(h, &fd)); + } while (::FindNextFileW(h, &fd)); ::FindClose(h); } @@ -954,7 +954,7 @@ bool DiskFile::Delete(void) assert(hFile == INVALID_HANDLE_VALUE); std::wstring wfilename = utf8::Utf8ToWide(filename); - if (filename.size() > 0 && 0 == _wunlink(wfilename.c_str())) + if (filename.size() > 0 && ::DeleteFileW(wfilename.c_str())) { exists = false; return true; @@ -1102,7 +1102,7 @@ bool DiskFile::Rename(std::string _filename) std::wstring wfilename = utf8::Utf8ToWide(filename); std::wstring _wfilename = utf8::Utf8ToWide(_filename); - if (::_wrename(wfilename.c_str(), _wfilename.c_str()) == 0) + if (::MoveFileW(wfilename.c_str(), _wfilename.c_str())) { filename.swap(_filename);