mirror of
https://github.com/opencv/opencv.git
synced 2026-11-25 19:07:03 -06:00
Merge pull request #28935 from molhamfetnah:fix/21960-unicode-temp-path
core: fix Unicode temp path handling on Windows (fix #21960) #28935 ## Summary Fixes getCacheDirectoryForDownloads and related temp file functions failing when the user home directory contains Unicode characters like C:\\Users\\テスト\\AppData\\Local\\Temp. ## Root Cause On Windows, OpenCV was using ANSI versions of GetTempPath and GetTempFileName which fail with Unicode paths. ## Fix Replace with wide-character GetTempPathW plus UTF-8 conversion: - modules/core/src/utils/filesystem.cpp - getCacheDirectory for cache paths - modules/core/src/system.cpp - temporary file creation - modules/ts/src/ts_gtest.cpp - test stream capture ## Testing The fix has been verified compiles. Manual testing on Windows with Unicode username required. ## Risk Low: Uses same output format, just different encoding path. Existing ASCII functionality preserved. --- Fixes opencv/opencv#21960
This commit is contained in:
@@ -1118,12 +1118,19 @@ String tempfile( const char* suffix )
|
||||
#else
|
||||
// Use GUID-based naming to avoid race condition with GetTempFileNameA
|
||||
// See issue #19648
|
||||
char temp_dir2[MAX_PATH] = { 0 };
|
||||
wchar_t temp_dir2_w[MAX_PATH] = { 0 };
|
||||
|
||||
if (temp_dir.empty())
|
||||
{
|
||||
::GetTempPathA(sizeof(temp_dir2), temp_dir2);
|
||||
temp_dir = std::string(temp_dir2);
|
||||
::GetTempPathW(sizeof(temp_dir2_w)/sizeof(wchar_t), temp_dir2_w);
|
||||
// Convert from UTF-16 to UTF-8 to support Unicode paths
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, temp_dir2_w, -1, NULL, 0, NULL, NULL);
|
||||
if (len > 0)
|
||||
{
|
||||
std::vector<char> utf8_buf(len);
|
||||
WideCharToMultiByte(CP_UTF8, 0, temp_dir2_w, -1, utf8_buf.data(), len, NULL, NULL);
|
||||
temp_dir = std::string(utf8_buf.data());
|
||||
}
|
||||
}
|
||||
|
||||
GUID g;
|
||||
|
||||
Reference in New Issue
Block a user