#include #include #include "window.hpp" #include "crash_handlers.hpp" #include "messaging.hpp" #include "init/splash_window.hpp" #include "init/tasks.hpp" #include #include #include #include #include #include "hex/subcommands/subcommands.hpp" #include #include using namespace hex; int main(int argc, char **argv) { Window::initNative(); hex::crash::setupCrashHandlers(); std::vector args(argv + 1, argv + argc); if (argc > 1) { for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Plugins)) { PluginManager::load(dir); } hex::messaging::setupMessaging(); hex::subcommands::processArguments(args); PluginManager::unload(); } log::info("Welcome to ImHex {}!", ImHexApi::System::getImHexVersion()); log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()); // Check if ImHex is installed in portable mode { if (const auto executablePath = wolv::io::fs::getExecutablePath(); executablePath.has_value()) { const auto flagFile = executablePath->parent_path() / "PORTABLE"; if (wolv::io::fs::exists(flagFile) && wolv::io::fs::isRegularFile(flagFile)) ImHexApi::System::impl::setPortableVersion(true); } } bool shouldRestart = false; // Register an event to handle restarting of ImHex EventManager::subscribe([&]{ shouldRestart = true; }); do { shouldRestart = false; // Initialization { init::WindowSplash splashWindow; // Add initialization tasks to run TaskManager::init(); for (const auto &[name, task, async] : init::getInitTasks()) splashWindow.addStartupTask(name, task, async); // Draw the splash window while tasks are running if (!splashWindow.loop()) ImHexApi::System::getInitArguments().insert({ "tasks-failed", {} }); } log::info("Running on {} {} ({})", ImHexApi::System::getOSName(), ImHexApi::System::getOSVersion(), ImHexApi::System::getArchitecture()); log::info("Using '{}' GPU", ImHexApi::System::getGPUVendor()); // Clean up everything after the main window is closed ON_SCOPE_EXIT { for (const auto &[name, task, async] : init::getExitTasks()) task(); TaskManager::exit(); }; // Main window { Window window; // Open file that has been requested to be opened through other, OS-specific means if (auto path = hex::getInitialFilePath(); path.has_value()) { EventManager::post(path.value()); } // Render the main window EventManager::post(); window.loop(); } } while (shouldRestart); return EXIT_SUCCESS; }