1
0
mirror of synced 2025-01-19 01:24:15 +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

@ -74,6 +74,7 @@ IMHEX_PLUGIN_SUBCOMMANDS() {
{ "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") {