From 1dfce6a5c2af0c1e313930b36474c844339bb50c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 26 Jun 2024 19:38:25 +0200 Subject: [PATCH] feat: Added `--reset-settings` command --- .../content/command_line_interface.hpp | 1 + .../source/content/command_line_interface.cpp | 29 +++++++++++++++++-- plugins/builtin/source/plugin_builtin.cpp | 29 ++++++++++--------- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/plugins/builtin/include/content/command_line_interface.hpp b/plugins/builtin/include/content/command_line_interface.hpp index 74f9b3ac2..c29c063fd 100644 --- a/plugins/builtin/include/content/command_line_interface.hpp +++ b/plugins/builtin/include/content/command_line_interface.hpp @@ -21,6 +21,7 @@ namespace hex::plugin::builtin { void handlePatternLanguageCommand(const std::vector &args); void handleHexdumpCommand(const std::vector &args); void handleDemangleCommand(const std::vector &args); + void handleSettingsResetCommand(const std::vector &args); void registerCommandForwarders(); diff --git a/plugins/builtin/source/content/command_line_interface.cpp b/plugins/builtin/source/content/command_line_interface.cpp index 76f209c20..7752f1759 100644 --- a/plugins/builtin/source/content/command_line_interface.cpp +++ b/plugins/builtin/source/content/command_line_interface.cpp @@ -1,6 +1,7 @@ -#include "content/command_line_interface.hpp" - +#include #include + +#include #include #include #include @@ -351,6 +352,30 @@ namespace hex::plugin::builtin { std::exit(EXIT_SUCCESS); } + void handleSettingsResetCommand(const std::vector &) { + constexpr static auto ConfirmationString = "YES I AM ABSOLUTELY SURE"; + + log::println("You're about to reset all settings back to their default. Are you sure you want to continue?"); + log::println("Type \"{}\" to continue.", ConfirmationString); + + std::string input(128, '\x00'); + + log::print("> "); + std::fgets(input.data(), input.size() - 1, stdin); + input = wolv::util::trim(input); + + if (input == ConfirmationString) { + log::println("Resetting all settings!"); + ContentRegistry::Settings::impl::clear(); + ContentRegistry::Settings::impl::store(); + + std::exit(EXIT_SUCCESS); + } else { + log::println("Wrong confirmation string. Settings will not be reset."); + std::exit(EXIT_FAILURE); + } + } + void registerCommandForwarders() { hex::subcommands::registerSubCommand("open", [](const std::vector &args){ diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index f04ce9843..97e658abb 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -58,22 +58,23 @@ namespace hex::plugin::builtin { } IMHEX_PLUGIN_SUBCOMMANDS() { - { "help", "h", "Print help about this command", hex::plugin::builtin::handleHelpCommand }, - { "version", "", "Print ImHex version", hex::plugin::builtin::handleVersionCommand }, - { "plugins", "", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand }, - { "language", "", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand }, - { "verbose", "v", "Enables verbose debug logging", hex::plugin::builtin::handleVerboseCommand }, + { "help", "h", "Print help about this command", hex::plugin::builtin::handleHelpCommand }, + { "version", "", "Print ImHex version", hex::plugin::builtin::handleVersionCommand }, + { "plugins", "", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand }, + { "language", "", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand }, + { "verbose", "v", "Enables verbose debug logging", hex::plugin::builtin::handleVerboseCommand }, - { "open", "o", "Open files passed as argument. [default]", hex::plugin::builtin::handleOpenCommand }, + { "open", "o", "Open files passed as argument. [default]", hex::plugin::builtin::handleOpenCommand }, - { "calc", "", "Evaluate a mathematical expression", hex::plugin::builtin::handleCalcCommand }, - { "hash", "", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand }, - { "encode", "", "Encode a string", hex::plugin::builtin::handleEncodeCommand }, - { "decode", "", "Decode a string", hex::plugin::builtin::handleDecodeCommand }, - { "magic", "", "Identify file types", hex::plugin::builtin::handleMagicCommand }, - { "pl", "", "Interact with the pattern language", hex::plugin::builtin::handlePatternLanguageCommand }, - { "hexdump", "", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand }, - { "demangle", "", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand }, + { "calc", "", "Evaluate a mathematical expression", hex::plugin::builtin::handleCalcCommand }, + { "hash", "", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand }, + { "encode", "", "Encode a string", hex::plugin::builtin::handleEncodeCommand }, + { "decode", "", "Decode a string", hex::plugin::builtin::handleDecodeCommand }, + { "magic", "", "Identify file types", hex::plugin::builtin::handleMagicCommand }, + { "pl", "", "Interact with the pattern language", hex::plugin::builtin::handlePatternLanguageCommand }, + { "hexdump", "", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand }, + { "demangle", "", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand }, + { "reset-settings", "", "Demangle a mangled symbol", hex::plugin::builtin::handleSettingsResetCommand }, }; IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {