2021-02-10 18:17:09 +01:00
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
#include <hex/helpers/logger.hpp>
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
#include "window.hpp"
|
|
|
|
|
2021-04-20 21:46:48 +02:00
|
|
|
#include "init/splash_window.hpp"
|
|
|
|
#include "init/tasks.hpp"
|
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
#include <hex/api/project_file_manager.hpp>
|
|
|
|
|
2021-12-22 13:16:51 +01:00
|
|
|
int main(int argc, char **argv, char **envp) {
|
2021-01-13 17:28:27 +01:00
|
|
|
using namespace hex;
|
2022-02-01 18:09:40 +01:00
|
|
|
ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
|
2021-01-13 17:28:27 +01:00
|
|
|
|
2022-02-15 22:36:36 +01:00
|
|
|
#if defined(OS_WINDOWS)
|
2022-02-15 23:07:48 +01:00
|
|
|
ImHexApi::System::impl::setBorderlessWindowMode(true);
|
2022-02-15 22:36:36 +01:00
|
|
|
#endif
|
|
|
|
|
2022-08-16 11:48:37 +02:00
|
|
|
bool shouldRestart = false;
|
|
|
|
|
|
|
|
do {
|
2022-10-06 21:26:24 +02:00
|
|
|
EventManager::subscribe<RequestRestartImHex>([&]{ shouldRestart = true; });
|
2022-08-16 11:48:37 +02:00
|
|
|
shouldRestart = false;
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
{
|
|
|
|
Window::initNative();
|
|
|
|
|
2022-10-21 14:55:01 +02:00
|
|
|
hex::log::info("Welcome to ImHex {}!", IMHEX_VERSION);
|
2022-08-16 11:48:37 +02:00
|
|
|
|
|
|
|
init::WindowSplash splashWindow;
|
|
|
|
|
2022-10-04 23:37:48 +02:00
|
|
|
TaskManager::init();
|
2022-09-19 16:54:19 +02:00
|
|
|
for (const auto &[name, task, async] : init::getInitTasks())
|
|
|
|
splashWindow.addStartupTask(name, task, async);
|
2022-08-16 11:48:37 +02:00
|
|
|
|
|
|
|
if (!splashWindow.loop())
|
|
|
|
ImHexApi::System::getInitArguments().insert({ "tasks-failed", {} });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
ON_SCOPE_EXIT {
|
2022-09-19 16:54:19 +02:00
|
|
|
for (const auto &[name, task, async] : init::getExitTasks())
|
2022-08-16 11:48:37 +02:00
|
|
|
task();
|
2022-10-04 23:37:48 +02:00
|
|
|
TaskManager::exit();
|
2022-08-16 11:48:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Main window
|
|
|
|
{
|
|
|
|
Window window;
|
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
; // No arguments provided
|
2022-09-15 09:48:02 +02:00
|
|
|
else if (argc >= 2) {
|
2022-10-07 10:14:24 +02:00
|
|
|
for (auto i = 1; i < argc; i++) {
|
|
|
|
if (auto argument = ImHexApi::System::getProgramArgument(i); argument.has_value())
|
|
|
|
EventManager::post<RequestOpenFile>(argument.value());
|
|
|
|
}
|
2022-08-16 11:48:37 +02:00
|
|
|
}
|
|
|
|
|
2022-10-20 09:48:06 +02:00
|
|
|
window.loop();
|
2021-04-20 21:46:48 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:48:37 +02:00
|
|
|
} while (shouldRestart);
|
2021-01-12 16:50:15 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2020-11-10 15:26:38 +01:00
|
|
|
}
|