2021-02-10 18:17:09 +01:00
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/logger.hpp>
|
|
|
|
|
2020-11-10 15:26:38 +01:00
|
|
|
#include "window.hpp"
|
2023-06-01 18:35:41 +02:00
|
|
|
#include "crash_handlers.hpp"
|
2020-11-10 15:26:38 +01:00
|
|
|
|
2021-04-20 21:46:48 +02:00
|
|
|
#include "init/splash_window.hpp"
|
|
|
|
#include "init/tasks.hpp"
|
|
|
|
|
2023-05-14 21:50:58 +02:00
|
|
|
#include <hex/api/task.hpp>
|
2022-08-08 21:23:52 +02:00
|
|
|
#include <hex/api/project_file_manager.hpp>
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
#include <wolv/io/fs.hpp>
|
|
|
|
#include <wolv/utils/guards.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;
|
2023-06-01 18:35:41 +02:00
|
|
|
hex::crash::setupCrashHandlers();
|
2022-02-01 18:09:40 +01:00
|
|
|
ImHexApi::System::impl::setProgramArguments(argc, argv, envp);
|
2021-01-13 17:28:27 +01:00
|
|
|
|
2023-01-16 19:39:00 +01:00
|
|
|
// Check if ImHex is installed in portable mode
|
|
|
|
{
|
2023-03-12 18:27:29 +01:00
|
|
|
if (const auto executablePath = wolv::io::fs::getExecutablePath(); executablePath.has_value()) {
|
2023-01-16 19:39:00 +01:00
|
|
|
const auto flagFile = executablePath->parent_path() / "PORTABLE";
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
if (wolv::io::fs::exists(flagFile) && wolv::io::fs::isRegularFile(flagFile))
|
2023-01-16 19:39:00 +01:00
|
|
|
ImHexApi::System::impl::setPortableVersion(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
bool shouldRestart = false;
|
2022-08-16 11:48:37 +02:00
|
|
|
do {
|
2023-04-13 16:10:55 +02:00
|
|
|
// Register an event to handle restarting of ImHex
|
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();
|
|
|
|
|
2023-06-20 11:55:56 +02:00
|
|
|
log::info("Welcome to ImHex {}!", IMHEX_VERSION);
|
2023-05-25 09:25:22 +02:00
|
|
|
#if defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH_SHORT)
|
2023-06-20 11:55:56 +02:00
|
|
|
log::info("Compiled using commit {}@{}", GIT_BRANCH, GIT_COMMIT_HASH_SHORT);
|
2023-05-25 09:25:22 +02:00
|
|
|
#endif
|
2022-08-16 11:48:37 +02:00
|
|
|
|
|
|
|
init::WindowSplash splashWindow;
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Add initialization tasks to run
|
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
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Draw the splash window while tasks are running
|
2022-08-16 11:48:37 +02:00
|
|
|
if (!splashWindow.loop())
|
|
|
|
ImHexApi::System::getInitArguments().insert({ "tasks-failed", {} });
|
|
|
|
}
|
|
|
|
|
2023-06-20 11:55:56 +02:00
|
|
|
log::info("Running on {} {} ({})", ImHexApi::System::getOSName(), ImHexApi::System::getOSVersion(), ImHexApi::System::getArchitecture());
|
|
|
|
log::info("Using '{}' GPU", ImHexApi::System::getGPUVendor());
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Clean up everything after the main window is closed
|
2023-06-20 11:55:56 +02:00
|
|
|
auto exitHandler = [](auto){
|
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
|
|
|
};
|
|
|
|
|
2023-06-20 11:55:56 +02:00
|
|
|
ON_SCOPE_EXIT { exitHandler(0); };
|
|
|
|
|
2022-08-16 11:48:37 +02:00
|
|
|
// Main window
|
|
|
|
{
|
2023-02-06 07:11:21 +01:00
|
|
|
Window window;
|
2022-08-16 11:48:37 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-05-15 18:07:49 +02:00
|
|
|
// Open file that has been requested to be opened through other, OS-specific means
|
|
|
|
if (auto path = hex::getInitialFilePath(); path.has_value()) {
|
|
|
|
EventManager::post<RequestOpenFile>(path.value());
|
|
|
|
}
|
|
|
|
|
2023-02-17 12:03:53 +01:00
|
|
|
// Render the main window
|
2023-06-01 18:35:41 +02:00
|
|
|
|
|
|
|
EventManager::post<EventImHexStartupFinished>();
|
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
|
|
|
}
|