fix: Opening files with non-ASCII paths through the command line
Fixes #1380, Fixes #1435 Thanks a lot to @kyle-sylvestre
This commit is contained in:
parent
981ae5067c
commit
ee681b5053
@ -35,8 +35,31 @@ namespace {
|
||||
* @param argv Argument values
|
||||
*/
|
||||
void handleCommandLineInterface(int argc, char **argv) {
|
||||
std::vector<std::string> args;
|
||||
|
||||
#if defined (OS_WINDOWS)
|
||||
hex::unused(argv);
|
||||
|
||||
// On Windows, argv contains UTF-16 encoded strings, so we need to convert them to UTF-8
|
||||
auto convertedCommandLine = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
||||
if (convertedCommandLine == nullptr) {
|
||||
log::error("Failed to convert command line arguments to UTF-8");
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; i += 1) {
|
||||
std::wstring wcharArg = convertedCommandLine[i];
|
||||
std::string utf8Arg = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().to_bytes(wcharArg);
|
||||
|
||||
args.push_back(utf8Arg);
|
||||
}
|
||||
|
||||
::LocalFree(convertedCommandLine);
|
||||
#else
|
||||
// Skip the first argument (the executable path) and convert the rest to a vector of strings
|
||||
std::vector<std::string> args(argv + 1, argv + argc);
|
||||
args = { argv + 1, argv + argc };
|
||||
#endif
|
||||
|
||||
|
||||
// Load all plugins but don't initialize them
|
||||
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Plugins)) {
|
||||
|
Loading…
Reference in New Issue
Block a user