#include "init/tasks.hpp" #include #include #include "views/view_hexeditor.hpp" #include "views/view_pattern_editor.hpp" #include "views/view_pattern_data.hpp" #include "views/view_hashes.hpp" #include "views/view_information.hpp" #include "views/view_help.hpp" #include "views/view_tools.hpp" #include "views/view_strings.hpp" #include "views/view_data_inspector.hpp" #include "views/view_disassembler.hpp" #include "views/view_bookmarks.hpp" #include "views/view_patches.hpp" #include "views/view_command_palette.hpp" #include "views/view_settings.hpp" #include "views/view_data_processor.hpp" #include "views/view_yara.hpp" #include "views/view_constants.hpp" #include "helpers/plugin_manager.hpp" #include #include namespace hex::init { using namespace std::literals::string_literals; static bool checkForUpdates() { hex::Net net; auto releases = net.getJson(GitHubApiURL + "/releases/latest"s).get(); if (releases.code != 200) return false; if (!releases.body.contains("tag_name") || !releases.body["tag_name"].is_string()) return false; auto currVersion = "v" + std::string(IMHEX_VERSION).substr(0, 5); auto latestVersion = releases.body["tag_name"].get(); if (latestVersion != currVersion) getInitArguments().push_back({ "update-available", latestVersion.data() }); return true; } static bool downloadInformation() { hex::Net net; auto tip = net.getString(ImHexApiURL + "/tip"s).get(); if (tip.code != 200) return false; getInitArguments().push_back({ "tip-of-the-day", tip.body }); return true; } bool createDirectories() { bool result = true; std::array paths = { ImHexPath::Patterns, ImHexPath::PatternsInclude, ImHexPath::Magic, ImHexPath::Plugins, ImHexPath::Resources, ImHexPath::Config, ImHexPath::Constants, ImHexPath::Yara, ImHexPath::Python }; for (auto path : paths) { for (auto &folder : hex::getPath(path)) { try { std::filesystem::create_directories(folder); } catch (...) { result = false; } } } if (!result) getInitArguments().push_back({ "folder-creation-error", { } }); return result; } bool loadDefaultViews() { ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); ContentRegistry::Views::add(); return true; } bool deleteSharedData() { SharedData::deferredCalls.clear(); delete SharedData::currentProvider; SharedData::currentProvider = nullptr; SharedData::settingsEntries.clear(); SharedData::settingsJson.clear(); SharedData::commandPaletteCommands.clear(); SharedData::patternLanguageFunctions.clear(); for (auto &view : SharedData::views) delete view; SharedData::views.clear(); SharedData::toolsEntries.clear(); SharedData::dataInspectorEntries.clear(); SharedData::bookmarkEntries.clear(); for (auto &pattern : SharedData::patternData) delete pattern; SharedData::patternData.clear(); SharedData::languageNames.clear(); SharedData::languageDefinitions.clear(); SharedData::loadedLanguageStrings.clear(); SharedData::welcomeScreenEntries.clear(); SharedData::footerItems.clear(); SharedData::dataProcessorNodes.clear(); SharedData::recentFilePaths.clear(); SharedData::clearVariables(); return true; } bool loadPlugins() { for (const auto &dir : hex::getPath(ImHexPath::Plugins)) { PluginManager::load(dir); } if (PluginManager::getPlugins().empty()) { getInitArguments().push_back({ "no-plugins", { } }); return false; } for (const auto &plugin : PluginManager::getPlugins()) { plugin.initializePlugin(); } return true; } bool unloadPlugins() { PluginManager::unload(); return true; } bool loadSettings() { try { ContentRegistry::Settings::load(); } catch (...) { return false; } return true; } bool storeSettings() { try { ContentRegistry::Settings::store(); } catch (...) { return false; } return true; } std::vector getInitTasks() { return { { "Checking for updates...", checkForUpdates }, { "Downloading information...", downloadInformation }, { "Creating directories...", createDirectories }, { "Loading default views...", loadDefaultViews }, { "Loading plugins...", loadPlugins }, { "Loading settings...", loadSettings }, }; } std::vector getExitTasks() { return { { "Saving settings...", storeSettings }, { "Cleaning up shared data...", deleteSharedData }, { "Unloading plugins...", unloadPlugins }, }; } std::vector& getInitArguments() { static std::vector initArguments; return initArguments; } }