Add File Naming setting for more detailed naming (#3002)

* added filename mode setting
* added furi_flag checks for when filename_mode is set
* changed naming for ibutton, lfrfid and subghz
* requested changes from PR
* Lib: gather all naming bits and pieces under name generator module. Properly bump api version. FuriHal: fix RTC flag enum.
* PR requested changes
* bug fix for arg type
* added functionality for other application scenes
* Lib: cleanup name generator API, simplify usage. Sync API symbols.
* Lib: proper size type in name_generator. Cleanup.
* FuriHal: cleanup rtc api usage across firmware

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Max
2023-09-01 14:57:49 +09:00
committed by GitHub
co-authored by あく
parent e5fdb2e069
commit 52b5966262
27 changed files with 207 additions and 98 deletions
+2 -1
View File
@@ -195,7 +195,8 @@ bool ibutton_load_key(iButton* ibutton) {
bool ibutton_select_and_load_key(iButton* ibutton) {
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, IBUTTON_APP_EXTENSION, &I_ibutt_10px);
dialog_file_browser_set_basic_options(
&browser_options, IBUTTON_APP_FILENAME_EXTENSION, &I_ibutt_10px);
browser_options.base_path = IBUTTON_APP_FOLDER;
if(furi_string_empty(ibutton->file_path)) {
+2 -1
View File
@@ -29,7 +29,8 @@
#include "scenes/ibutton_scene.h"
#define IBUTTON_APP_FOLDER ANY_PATH("ibutton")
#define IBUTTON_APP_EXTENSION ".ibtn"
#define IBUTTON_APP_FILENAME_PREFIX "iBtn"
#define IBUTTON_APP_FILENAME_EXTENSION ".ibtn"
#define IBUTTON_KEY_NAME_SIZE 22
@@ -1,6 +1,6 @@
#include "../ibutton_i.h"
#include <toolbox/random_name.h>
#include <toolbox/name_generator.h>
#include <toolbox/path.h>
#include <dolphin/dolphin.h>
@@ -17,7 +17,8 @@ void ibutton_scene_save_name_on_enter(void* context) {
const bool is_new_file = furi_string_empty(ibutton->file_path);
if(is_new_file) {
set_random_name(ibutton->key_name, IBUTTON_KEY_NAME_SIZE);
name_generator_make_auto(
ibutton->key_name, IBUTTON_KEY_NAME_SIZE, IBUTTON_APP_FILENAME_PREFIX);
}
text_input_set_header_text(text_input, "Name the key");
@@ -29,8 +30,8 @@ void ibutton_scene_save_name_on_enter(void* context) {
IBUTTON_KEY_NAME_SIZE,
is_new_file);
ValidatorIsFile* validator_is_file =
validator_is_file_alloc_init(IBUTTON_APP_FOLDER, IBUTTON_APP_EXTENSION, ibutton->key_name);
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
IBUTTON_APP_FOLDER, IBUTTON_APP_FILENAME_EXTENSION, ibutton->key_name);
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewTextInput);
@@ -48,7 +49,7 @@ bool ibutton_scene_save_name_on_event(void* context, SceneManagerEvent event) {
"%s/%s%s",
IBUTTON_APP_FOLDER,
ibutton->key_name,
IBUTTON_APP_EXTENSION);
IBUTTON_APP_FILENAME_EXTENSION);
if(ibutton_save_key(ibutton)) {
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSaveSuccess);
@@ -1,7 +1,6 @@
#include "../infrared_i.h"
#include "common/infrared_scene_universal_common.h"
#include <furi_hal_rtc.h>
void infrared_scene_universal_ac_on_enter(void* context) {
infrared_scene_universal_common_on_enter(context);
+7 -3
View File
@@ -215,13 +215,16 @@ bool lfrfid_save_key(LfRfid* app) {
lfrfid_make_app_folder(app);
if(furi_string_end_with(app->file_path, LFRFID_APP_EXTENSION)) {
if(furi_string_end_with(app->file_path, LFRFID_APP_FILENAME_EXTENSION)) {
size_t filename_start = furi_string_search_rchar(app->file_path, '/');
furi_string_left(app->file_path, filename_start);
}
furi_string_cat_printf(
app->file_path, "/%s%s", furi_string_get_cstr(app->file_name), LFRFID_APP_EXTENSION);
app->file_path,
"/%s%s",
furi_string_get_cstr(app->file_name),
LFRFID_APP_FILENAME_EXTENSION);
result = lfrfid_save_key_data(app, app->file_path);
return result;
@@ -231,7 +234,8 @@ bool lfrfid_load_key_from_file_select(LfRfid* app) {
furi_assert(app);
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, LFRFID_APP_EXTENSION, &I_125_10px);
dialog_file_browser_set_basic_options(
&browser_options, LFRFID_APP_FILENAME_EXTENSION, &I_125_10px);
browser_options.base_path = LFRFID_APP_FOLDER;
// Input events and views are managed by file_browser
+3 -2
View File
@@ -40,8 +40,9 @@
#define LFRFID_APP_FOLDER ANY_PATH("lfrfid")
#define LFRFID_SD_FOLDER EXT_PATH("lfrfid")
#define LFRFID_APP_EXTENSION ".rfid"
#define LFRFID_APP_SHADOW_EXTENSION ".shd"
#define LFRFID_APP_FILENAME_PREFIX "RFID"
#define LFRFID_APP_FILENAME_EXTENSION ".rfid"
#define LFRFID_APP_SHADOW_FILENAME_EXTENSION ".shd"
#define LFRFID_APP_RAW_ASK_EXTENSION ".ask.raw"
#define LFRFID_APP_RAW_PSK_EXTENSION ".psk.raw"
@@ -1,6 +1,6 @@
#include <lib/toolbox/random_name.h>
#include "../lfrfid_i.h"
#include <dolphin/dolphin.h>
#include <toolbox/name_generator.h>
void lfrfid_scene_save_name_on_enter(void* context) {
LfRfid* app = context;
@@ -11,7 +11,10 @@ void lfrfid_scene_save_name_on_enter(void* context) {
bool key_name_is_empty = furi_string_empty(app->file_name);
if(key_name_is_empty) {
furi_string_set(app->file_path, LFRFID_APP_FOLDER);
set_random_name(app->text_store, LFRFID_TEXT_STORE_SIZE);
name_generator_make_auto(
app->text_store, LFRFID_TEXT_STORE_SIZE, LFRFID_APP_FILENAME_PREFIX);
furi_string_set(folder_path, LFRFID_APP_FOLDER);
} else {
lfrfid_text_store_set(app, "%s", furi_string_get_cstr(app->file_name));
@@ -31,7 +34,7 @@ void lfrfid_scene_save_name_on_enter(void* context) {
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
furi_string_get_cstr(folder_path),
LFRFID_APP_EXTENSION,
LFRFID_APP_FILENAME_EXTENSION,
furi_string_get_cstr(app->file_name));
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
+5 -1
View File
@@ -223,7 +223,11 @@ void nfc_blink_stop(Nfc* nfc) {
bool nfc_save_file(Nfc* nfc) {
furi_string_printf(
nfc->dev->load_path, "%s/%s%s", NFC_APP_FOLDER, nfc->dev->dev_name, NFC_APP_EXTENSION);
nfc->dev->load_path,
"%s/%s%s",
NFC_APP_FOLDER,
nfc->dev->dev_name,
NFC_APP_FILENAME_EXTENSION);
bool file_saved = nfc_device_save(nfc->dev, furi_string_get_cstr(nfc->dev->load_path));
return file_saved;
}
@@ -1,5 +1,5 @@
#include "../nfc_i.h"
#include <lib/toolbox/random_name.h>
#include <lib/toolbox/name_generator.h>
#include <gui/modules/validators.h>
#include <toolbox/path.h>
#include <dolphin/dolphin.h>
@@ -17,7 +17,7 @@ void nfc_scene_save_name_on_enter(void* context) {
TextInput* text_input = nfc->text_input;
bool dev_name_empty = false;
if(!strcmp(nfc->dev->dev_name, "")) {
set_random_name(nfc->text_store, sizeof(nfc->text_store));
name_generator_make_auto(nfc->text_store, NFC_DEV_NAME_MAX_LEN, NFC_APP_FILENAME_PREFIX);
dev_name_empty = true;
} else {
nfc_text_store_set(nfc, nfc->dev->dev_name);
@@ -34,14 +34,14 @@ void nfc_scene_save_name_on_enter(void* context) {
FuriString* folder_path;
folder_path = furi_string_alloc();
if(furi_string_end_with(nfc->dev->load_path, NFC_APP_EXTENSION)) {
if(furi_string_end_with(nfc->dev->load_path, NFC_APP_FILENAME_EXTENSION)) {
path_extract_dirname(furi_string_get_cstr(nfc->dev->load_path), folder_path);
} else {
furi_string_set(folder_path, NFC_APP_FOLDER);
}
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
furi_string_get_cstr(folder_path), NFC_APP_EXTENSION, nfc->dev->dev_name);
furi_string_get_cstr(folder_path), NFC_APP_FILENAME_EXTENSION, nfc->dev->dev_name);
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput);
@@ -239,7 +239,11 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
FuriString* temp_str = furi_string_alloc();
furi_string_printf(
temp_str, "%s/%s%s", SUBGHZ_RAW_FOLDER, RAW_FILE_NAME, SUBGHZ_APP_EXTENSION);
temp_str,
"%s/%s%s",
SUBGHZ_RAW_FOLDER,
RAW_FILE_NAME,
SUBGHZ_APP_FILENAME_EXTENSION);
subghz_protocol_raw_gen_fff_data(
subghz_txrx_get_fff_data(subghz->txrx),
furi_string_get_cstr(temp_str),
@@ -1,10 +1,10 @@
#include "../subghz_i.h"
#include "subghz/types.h"
#include <lib/toolbox/random_name.h>
#include "../helpers/subghz_custom_event.h"
#include <lib/subghz/protocols/raw.h>
#include <gui/modules/validators.h>
#include <dolphin/dolphin.h>
#include <toolbox/name_generator.h>
#define MAX_TEXT_INPUT_LEN 22
@@ -40,7 +40,9 @@ void subghz_scene_save_name_on_enter(void* context) {
if(!subghz_path_is_file(subghz->file_path)) {
char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0};
set_random_name(file_name_buf, SUBGHZ_MAX_LEN_NAME);
name_generator_make_auto(file_name_buf, SUBGHZ_MAX_LEN_NAME, SUBGHZ_APP_FILENAME_PREFIX);
furi_string_set(file_name, file_name_buf);
furi_string_set(subghz->file_path, SUBGHZ_APP_FOLDER);
//highlighting the entire filename by default
@@ -71,7 +73,7 @@ void subghz_scene_save_name_on_enter(void* context) {
dev_name_empty);
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
furi_string_get_cstr(subghz->file_path), SUBGHZ_APP_EXTENSION, "");
furi_string_get_cstr(subghz->file_path), SUBGHZ_APP_FILENAME_EXTENSION, "");
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
furi_string_free(file_name);
@@ -94,7 +96,10 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) {
if(event.event == SubGhzCustomEventSceneSaveName) {
if(strcmp(subghz->file_name_tmp, "") != 0) {
furi_string_cat_printf(
subghz->file_path, "/%s%s", subghz->file_name_tmp, SUBGHZ_APP_EXTENSION);
subghz->file_path,
"/%s%s",
subghz->file_name_tmp,
SUBGHZ_APP_FILENAME_EXTENSION);
if(subghz_path_is_file(subghz->file_path_tmp)) {
if(!subghz_rename_file(subghz)) {
return false;
+5 -4
View File
@@ -238,7 +238,7 @@ bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len) {
storage,
furi_string_get_cstr(file_path),
furi_string_get_cstr(file_name),
SUBGHZ_APP_EXTENSION,
SUBGHZ_APP_FILENAME_EXTENSION,
file_name,
max_len);
@@ -247,7 +247,7 @@ bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len) {
"%s/%s%s",
furi_string_get_cstr(file_path),
furi_string_get_cstr(file_name),
SUBGHZ_APP_EXTENSION);
SUBGHZ_APP_FILENAME_EXTENSION);
furi_string_set(subghz->file_path, temp_str);
res = true;
}
@@ -320,7 +320,8 @@ bool subghz_load_protocol_from_file(SubGhz* subghz) {
FuriString* file_path = furi_string_alloc();
DialogsFileBrowserOptions browser_options;
dialog_file_browser_set_basic_options(&browser_options, SUBGHZ_APP_EXTENSION, &I_sub1_10px);
dialog_file_browser_set_basic_options(
&browser_options, SUBGHZ_APP_FILENAME_EXTENSION, &I_sub1_10px);
browser_options.base_path = SUBGHZ_APP_FOLDER;
// Input events and views are managed by file_select
@@ -394,7 +395,7 @@ void subghz_file_name_clear(SubGhz* subghz) {
}
bool subghz_path_is_file(FuriString* path) {
return furi_string_end_with(path, SUBGHZ_APP_EXTENSION);
return furi_string_end_with(path, SUBGHZ_APP_FILENAME_EXTENSION);
}
void subghz_lock(SubGhz* subghz) {
-1
View File
@@ -4,7 +4,6 @@
#include <furi.h>
#include <furi_hal.h>
#include <furi_hal_rtc.h>
#include <stdint.h>
#include <u8g2_glue.h>
-1
View File
@@ -2,7 +2,6 @@
#include <furi.h>
#include <furi_hal.h>
#include <furi_hal_rtc.h>
#include "gui.h"
#include "gui_i.h"
@@ -153,6 +153,21 @@ static void sleep_method_changed(VariableItem* item) {
}
}
const char* const filename_scheme[] = {
"Default",
"Detailed",
};
static void filename_scheme_changed(VariableItem* item) {
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, filename_scheme[index]);
if(index) {
furi_hal_rtc_set_flag(FuriHalRtcFlagDetailedFilename);
} else {
furi_hal_rtc_reset_flag(FuriHalRtcFlagDetailedFilename);
}
}
static uint32_t system_settings_exit(void* context) {
UNUSED(context);
return VIEW_NONE;
@@ -236,6 +251,12 @@ SystemSettings* system_settings_alloc() {
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, sleep_method[value_index]);
item = variable_item_list_add(
app->var_item_list, "File Naming", COUNT_OF(filename_scheme), filename_scheme_changed, app);
value_index = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDetailedFilename) ? 1 : 0;
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, filename_scheme[value_index]);
view_set_previous_callback(
variable_item_list_get_view(app->var_item_list), system_settings_exit);
view_dispatcher_add_view(