reset.c 1.5 KB

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