1
0
mirror of synced 2025-01-31 03:53:44 +01:00

feat: Added --reset-settings command

This commit is contained in:
WerWolv 2024-06-26 19:38:25 +02:00
parent a84db9821c
commit 1dfce6a5c2
3 changed files with 43 additions and 16 deletions

View File

@ -21,6 +21,7 @@ namespace hex::plugin::builtin {
void handlePatternLanguageCommand(const std::vector<std::string> &args); void handlePatternLanguageCommand(const std::vector<std::string> &args);
void handleHexdumpCommand(const std::vector<std::string> &args); void handleHexdumpCommand(const std::vector<std::string> &args);
void handleDemangleCommand(const std::vector<std::string> &args); void handleDemangleCommand(const std::vector<std::string> &args);
void handleSettingsResetCommand(const std::vector<std::string> &args);
void registerCommandForwarders(); void registerCommandForwarders();

View File

@ -1,6 +1,7 @@
#include "content/command_line_interface.hpp" #include <content/command_line_interface.hpp>
#include <content/providers/file_provider.hpp> #include <content/providers/file_provider.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/imhex_api.hpp> #include <hex/api/imhex_api.hpp>
#include <hex/api/event_manager.hpp> #include <hex/api/event_manager.hpp>
#include <hex/api/plugin_manager.hpp> #include <hex/api/plugin_manager.hpp>
@ -351,6 +352,30 @@ namespace hex::plugin::builtin {
std::exit(EXIT_SUCCESS); std::exit(EXIT_SUCCESS);
} }
void handleSettingsResetCommand(const std::vector<std::string> &) {
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() { void registerCommandForwarders() {
hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){ hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){

View File

@ -58,22 +58,23 @@ namespace hex::plugin::builtin {
} }
IMHEX_PLUGIN_SUBCOMMANDS() { IMHEX_PLUGIN_SUBCOMMANDS() {
{ "help", "h", "Print help about this command", hex::plugin::builtin::handleHelpCommand }, { "help", "h", "Print help about this command", hex::plugin::builtin::handleHelpCommand },
{ "version", "", "Print ImHex version", hex::plugin::builtin::handleVersionCommand }, { "version", "", "Print ImHex version", hex::plugin::builtin::handleVersionCommand },
{ "plugins", "", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand }, { "plugins", "", "Lists all plugins that have been installed", hex::plugin::builtin::handlePluginsCommand },
{ "language", "", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand }, { "language", "", "Changes the language ImHex uses", hex::plugin::builtin::handleLanguageCommand },
{ "verbose", "v", "Enables verbose debug logging", hex::plugin::builtin::handleVerboseCommand }, { "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 }, { "calc", "", "Evaluate a mathematical expression", hex::plugin::builtin::handleCalcCommand },
{ "hash", "", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand }, { "hash", "", "Calculate the hash of a file", hex::plugin::builtin::handleHashCommand },
{ "encode", "", "Encode a string", hex::plugin::builtin::handleEncodeCommand }, { "encode", "", "Encode a string", hex::plugin::builtin::handleEncodeCommand },
{ "decode", "", "Decode a string", hex::plugin::builtin::handleDecodeCommand }, { "decode", "", "Decode a string", hex::plugin::builtin::handleDecodeCommand },
{ "magic", "", "Identify file types", hex::plugin::builtin::handleMagicCommand }, { "magic", "", "Identify file types", hex::plugin::builtin::handleMagicCommand },
{ "pl", "", "Interact with the pattern language", hex::plugin::builtin::handlePatternLanguageCommand }, { "pl", "", "Interact with the pattern language", hex::plugin::builtin::handlePatternLanguageCommand },
{ "hexdump", "", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand }, { "hexdump", "", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand },
{ "demangle", "", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand }, { "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") { IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {