From ac9d99bb6d1753aa0c2e2047e10aaf731e59f5a6 Mon Sep 17 00:00:00 2001 From: Saad Khurshid Qurashi <147279806+Isaadqurashi@users.noreply.github.com> Date: Wed, 18 Dec 2024 02:59:19 +0500 Subject: [PATCH 1/2] Update main.cpp Exception handling was added to catch any runtime errors. Safe handling of the Linux distribution information was implemented to avoid potential crashes when the value is unavailable... Improved logging for the Linux distribution to handle empty versions and missing distro data. --- main/gui/source/main.cpp | 63 +++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/main/gui/source/main.cpp b/main/gui/source/main.cpp index 2f932fb3e8ab9..5d6f41fc99711 100644 --- a/main/gui/source/main.cpp +++ b/main/gui/source/main.cpp @@ -16,6 +16,7 @@ namespace hex::init { void runCommandLine(int argc, char **argv); } + /** * @brief Main entry point of ImHex * @param argc Argument count @@ -23,32 +24,40 @@ namespace hex::init { * @return Exit code */ int main(int argc, char **argv) { - using namespace hex; - - // Set the main thread's name to "Main" - TaskManager::setCurrentThreadName("Main"); - - // Setup crash handlers right away to catch crashes as early as possible - crash::setupCrashHandlers(); - - // Run platform-specific initialization code - Window::initNative(); - - // Handle command line arguments if any have been passed - if (argc > 1) { - init::runCommandLine(argc, argv); + try { + using namespace hex; + + // Set the main thread's name to "Main" + TaskManager::setCurrentThreadName("Main"); + + // Setup crash handlers right away to catch crashes as early as possible + crash::setupCrashHandlers(); + + // Run platform-specific initialization code + Window::initNative(); + + // Handle command line arguments if any have been passed + if (argc > 1) { + init::runCommandLine(argc, argv); + } + + // Log some system information to aid debugging when users share their logs + log::info("Welcome to ImHex {}!", ImHexApi::System::getImHexVersion()); + log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()); + log::info("Running on {} {} ({})", ImHexApi::System::getOSName(), ImHexApi::System::getOSVersion(), ImHexApi::System::getArchitecture()); + + #if defined(OS_LINUX) + if (auto distro = ImHexApi::System::getLinuxDistro(); distro.has_value()) { + log::info("Linux distribution: {}. Version: {}", distro->name, distro->version.empty() ? "None" : distro->version); + } else { + log::warning("Linux distribution information is not available."); + } + #endif + + // Run ImHex + return init::runImHex(); + } catch (const std::exception &e) { + std::cerr << "Unhandled exception: " << e.what() << std::endl; + return EXIT_FAILURE; } - - // Log some system information to aid debugging when users share their logs - log::info("Welcome to ImHex {}!", ImHexApi::System::getImHexVersion()); - log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()); - log::info("Running on {} {} ({})", ImHexApi::System::getOSName(), ImHexApi::System::getOSVersion(), ImHexApi::System::getArchitecture()); - #if defined(OS_LINUX) - auto distro = ImHexApi::System::getLinuxDistro().value(); - log::info("Linux distribution: {}. Version: {}", distro.name, distro.version == "" ? "None" : distro.version); - #endif - - - // Run ImHex - return init::runImHex(); } From 3f49e4b4469a86d85c8f967d3b9a777300859388 Mon Sep 17 00:00:00 2001 From: Saad Khurshid Qurashi <147279806+Isaadqurashi@users.noreply.github.com> Date: Wed, 18 Dec 2024 03:03:01 +0500 Subject: [PATCH 2/2] Update main.cpp --- main/gui/source/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/main/gui/source/main.cpp b/main/gui/source/main.cpp index 5d6f41fc99711..7c2fe5f1cf4bb 100644 --- a/main/gui/source/main.cpp +++ b/main/gui/source/main.cpp @@ -16,7 +16,6 @@ namespace hex::init { void runCommandLine(int argc, char **argv); } - /** * @brief Main entry point of ImHex * @param argc Argument count