Use current encoding for char command line arguments if possible

This is more consistent with the conversion in the other direction, but
here we also fall back to UTF-8 if conversion fails as it seems better
than just losing the argument entirely.

Also make the conversion a bit more efficient by stealing the pointer
from wxCharBuffer instead of using strdup() to copy the string.
This commit is contained in:
Vadim Zeitlin 2023-11-30 00:44:51 +01:00
parent 1d134338a7
commit a4ee2563bc

View file

@ -240,7 +240,9 @@ void wxInitData::InitIfNecessary(int argcIn, wchar_t** argvIn)
for ( int i = 0; i < argc; i++ )
{
argvA[i] = wxStrdup(wxConvUTF8.cWC2MB(argv[i]));
// Try to use the current encoding, but if it fails, it's better to
// fall back to UTF-8 than lose an argument entirely.
argvA[i] = wxConvWhateverWorks.cWC2MB(argvIn[i]).release();
}
#endif // __WINDOWS__/!__WINDOWS__
}