-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle UTF8 file names on Windows #26
Comments
_wsopen_s is expecting a What should the |
I believe, std::wstring c_str() returns a pointer to wchar_t buffer that is terminated by zero. I have tested this change on VIsual Studio 2017, 2019 only, but it should work on other C++ compilers too. |
I was actually asking about modifications to the code in the I think I was confused because the way you set it up with the If you meant this to be a Windows-only solution then I'll move the conversion within the Windows-only block. |
Yes, these changes are needed on Windows only (while I also tried to make portable character conversion code). |
I'm not sure if this works since I don't compile on Windows. Please let me know if there are issues! Based on code from #26
OK - I've made changes in 8ee8582. Thanks Olli! |
Visual Studio 2019 error don't need the conversion |
Can you please post the error you're getting? wstring's |
I can't catch it here int result = open(fileName_.c_str(), flags, mode);
if (result < 0)
{
throw E57_EXCEPTION2(E57_ERROR_OPEN_FAILED,
"result=" + toString(result)
+ " fileName=" + fileName
+ " flags=" + toString(flags)
+ " mode=" + toString(mode));
}
return result; The normal work but // Handle UTF-8 file names - Windows requires conversion to UTF-16
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring widePath = converter.from_bytes( fileName );
int handle;
int err = _wsopen_s(&handle, widePath.c_str(), flags, _SH_DENYNO, mode);
if (handle < 0)
{
throw E57_EXCEPTION2(E57_ERROR_OPEN_FAILED,
"err=" + toString(err)
+ " fileName=" + fileName
+ " flags=" + toString(flags)
+ " mode=" + toString(mode));
}
return handle; Don't work You can test filenames ’测试点云.e57‘ (Edited by @asmaloney to format code - use ```cpp around code to make it more readable.) |
I don't run Windows, so I can't test it. Maybe @ollira or another Windows user can try it and come up with an explanation/solution. |
Hi, In my environments the suggested filename (测试点云.e57) works just fine. Perhaps the fileName parameter from jiawenquan's application is not a UTF8-encoded string. |
Hi,
To support UTF8-encoded file names on Windows, some code changes are needed in CheckedFile.cpp. This patch appears to work on Visual Studio 2017, and probably should also work on 2015.
The text was updated successfully, but these errors were encountered: