From 085737af1590709a52550dc5581bd34fd49d8ddd Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 18 Jun 2024 22:11:26 +0200 Subject: [PATCH] fix: Opening files on network drives (using UNC paths) crashing ImHex on startup --- .../source/content/command_line_interface.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/builtin/source/content/command_line_interface.cpp b/plugins/builtin/source/content/command_line_interface.cpp index 75dc8ec11..28d32da18 100644 --- a/plugins/builtin/source/content/command_line_interface.cpp +++ b/plugins/builtin/source/content/command_line_interface.cpp @@ -92,7 +92,17 @@ namespace hex::plugin::builtin { doubleDashFound = true; } else { try { - auto path = std::filesystem::weakly_canonical(arg); + std::fs::path path; + + try { + path = std::fs::weakly_canonical(arg); + } catch(std::fs::filesystem_error &) { + path = arg; + } + + if (path.empty()) + continue; + fullPaths.push_back(wolv::util::toUTF8String(path)); } catch (std::exception &e) { log::error("Failed to open file '{}'\n {}", arg, e.what()); @@ -100,7 +110,8 @@ namespace hex::plugin::builtin { } } - hex::subcommands::forwardSubCommand("open", fullPaths); + if (!fullPaths.empty()) + hex::subcommands::forwardSubCommand("open", fullPaths); } void handleCalcCommand(const std::vector &args) {