reset.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "reset.h"
  2. #include <stdlib.h>
  3. #include <furi/core/string.h>
  4. #include "../../cli_helpers.h"
  5. #include "../../../ui/scene_director.h"
  6. #include "../../../services/config/config.h"
  7. #define TOTP_CLI_RESET_CONFIRMATION_KEYWORD "YES"
  8. #ifdef TOTP_CLI_RICH_HELP_ENABLED
  9. void totp_cli_command_reset_docopt_commands() {
  10. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_RESET
  11. " Reset application to default settings\r\n");
  12. }
  13. void totp_cli_command_reset_docopt_usage() {
  14. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_RESET "\r\n");
  15. }
  16. #endif
  17. void totp_cli_command_reset_handle(PluginState* plugin_state, Cli* cli) {
  18. TOTP_CLI_LOCK_UI(plugin_state);
  19. TOTP_CLI_PRINTF_WARNING(
  20. "As a result of reset all the settings and tokens will be permanently lost.\r\n");
  21. TOTP_CLI_PRINTF_WARNING("Do you really want to reset application?\r\n");
  22. TOTP_CLI_PRINTF_WARNING("Type \"" TOTP_CLI_RESET_CONFIRMATION_KEYWORD
  23. "\" and hit <ENTER> to confirm:\r\n");
  24. FuriString* temp_str = furi_string_alloc();
  25. bool is_confirmed = totp_cli_read_line(cli, temp_str, false) &&
  26. furi_string_cmpi_str(temp_str, TOTP_CLI_RESET_CONFIRMATION_KEYWORD) == 0;
  27. furi_string_free(temp_str);
  28. if(is_confirmed) {
  29. totp_config_file_reset(plugin_state);
  30. TOTP_CLI_PRINTF_SUCCESS("Application has been successfully reset to default.\r\n");
  31. TOTP_CLI_PRINTF_SUCCESS("Now application will be closed to apply all the changes.\r\n");
  32. totp_cli_force_close_app(plugin_state->event_queue);
  33. } else {
  34. TOTP_CLI_PRINTF_INFO("Action was not confirmed by user\r\n");
  35. TOTP_CLI_UNLOCK_UI(plugin_state);
  36. }
  37. }