reset.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. void totp_cli_command_reset_docopt_commands() {
  9. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_RESET
  10. " Reset application to default settings\r\n");
  11. }
  12. void totp_cli_command_reset_docopt_usage() {
  13. TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_RESET "\r\n");
  14. }
  15. void totp_cli_command_reset_handle(
  16. PluginState* plugin_state,
  17. Cli* cli,
  18. FuriMessageQueue* event_queue) {
  19. TOTP_CLI_LOCK_UI(plugin_state);
  20. TOTP_CLI_PRINTF_WARNING(
  21. "As a result of reset all the settings and tokens will be permanently lost.\r\n");
  22. TOTP_CLI_PRINTF_WARNING("Do you really want to reset application?\r\n");
  23. TOTP_CLI_PRINTF_WARNING("Type \"" TOTP_CLI_RESET_CONFIRMATION_KEYWORD
  24. "\" and hit <ENTER> to confirm:\r\n");
  25. FuriString* temp_str = furi_string_alloc();
  26. bool is_confirmed = totp_cli_read_line(cli, temp_str, false) &&
  27. furi_string_cmpi_str(temp_str, TOTP_CLI_RESET_CONFIRMATION_KEYWORD) == 0;
  28. furi_string_free(temp_str);
  29. if(is_confirmed) {
  30. totp_config_file_reset(plugin_state);
  31. TOTP_CLI_PRINTF_SUCCESS("Application has been successfully reset to default.\r\n");
  32. TOTP_CLI_PRINTF_SUCCESS("Now application will be closed to apply all the changes.\r\n");
  33. totp_cli_force_close_app(event_queue);
  34. } else {
  35. TOTP_CLI_PRINTF_INFO("Action was not confirmed by user\r\n");
  36. TOTP_CLI_UNLOCK_UI(plugin_state);
  37. }
  38. }