config.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #pragma once
  2. #include <flipper_format/flipper_format.h>
  3. #include <furi.h>
  4. #include "../../types/plugin_state.h"
  5. #include "../../types/token_info.h"
  6. #include "constants.h"
  7. typedef uint8_t TokenLoadingResult;
  8. typedef uint8_t TotpConfigFileOpenResult;
  9. typedef uint8_t TotpConfigFileUpdateResult;
  10. /**
  11. * @brief Token loading results
  12. */
  13. enum TokenLoadingResults {
  14. /**
  15. * @brief All the tokens loaded successfully
  16. */
  17. TokenLoadingResultSuccess,
  18. /**
  19. * @brief All the tokens loaded, but there are some warnings
  20. */
  21. TokenLoadingResultWarning,
  22. /**
  23. * @brief Tokens not loaded because of error(s)
  24. */
  25. TokenLoadingResultError
  26. };
  27. /**
  28. * @brief Config file opening result
  29. */
  30. enum TotpConfigFileOpenResults {
  31. /**
  32. * @brief Config file opened successfully
  33. */
  34. TotpConfigFileOpenSuccess = 0,
  35. /**
  36. * @brief An error has occurred during opening config file
  37. */
  38. TotpConfigFileOpenError = 1
  39. };
  40. /**
  41. * @brief Config file updating result
  42. */
  43. enum TotpConfigFileUpdateResults {
  44. /**
  45. * @brief Config file updated successfully
  46. */
  47. TotpConfigFileUpdateSuccess,
  48. /**
  49. * @brief An error has occurred during updating config file
  50. */
  51. TotpConfigFileUpdateError
  52. };
  53. /**
  54. * @brief Tries to take a config file backup
  55. * @return backup path if backup successfully taken; \c NULL otherwise
  56. */
  57. char* totp_config_file_backup();
  58. /**
  59. * @brief Saves all the settings and tokens to an application config file
  60. * @param plugin_state application state
  61. * @return Config file update result
  62. */
  63. TotpConfigFileUpdateResult totp_full_save_config_file(const PluginState* const plugin_state);
  64. /**
  65. * @brief Loads basic information from an application config file into application state without loading all the tokens
  66. * @param plugin_state application state
  67. * @return Config file open result
  68. */
  69. TotpConfigFileOpenResult totp_config_file_load_base(PluginState* const plugin_state);
  70. /**
  71. * @brief Loads tokens from an application config file into application state
  72. * @param plugin_state application state
  73. * @return Results of the loading
  74. */
  75. TokenLoadingResult totp_config_file_load_tokens(PluginState* const plugin_state);
  76. /**
  77. * @brief Add new token to the end of the application config file
  78. * @param token_info token information to be saved
  79. * @return Config file update result
  80. */
  81. TotpConfigFileUpdateResult totp_config_file_save_new_token(const TokenInfo* token_info);
  82. /**
  83. * @brief Updates timezone offset in an application config file
  84. * @param new_timezone_offset new timezone offset to be set
  85. * @return Config file update result
  86. */
  87. TotpConfigFileUpdateResult totp_config_file_update_timezone_offset(float new_timezone_offset);
  88. /**
  89. * @brief Updates notification method in an application config file
  90. * @param new_notification_method new notification method to be set
  91. * @return Config file update result
  92. */
  93. TotpConfigFileUpdateResult
  94. totp_config_file_update_notification_method(NotificationMethod new_notification_method);
  95. /**
  96. * @brief Updates automation method in an application config file
  97. * @param new_automation_method new automation method to be set
  98. * @return Config file update result
  99. */
  100. TotpConfigFileUpdateResult
  101. totp_config_file_update_automation_method(AutomationMethod new_automation_method);
  102. /**
  103. * @brief Updates application user settings
  104. * @param plugin_state application state
  105. * @return Config file update result
  106. */
  107. TotpConfigFileUpdateResult totp_config_file_update_user_settings(const PluginState* plugin_state);
  108. /**
  109. * @brief Updates crypto signatures information
  110. * @param plugin_state application state
  111. * @return Config file update result
  112. */
  113. TotpConfigFileUpdateResult
  114. totp_config_file_update_crypto_signatures(const PluginState* plugin_state);
  115. /**
  116. * @brief Reset all the settings to default
  117. */
  118. void totp_config_file_reset();