7
7
#define QUAC_SETTINGS_FILE_VERSION 1
8
8
9
9
void quac_set_default_settings (App * app ) {
10
- app -> settings .rfid_duration = 2500 ;
11
10
app -> settings .layout = QUAC_APP_LANDSCAPE ;
12
11
app -> settings .show_icons = true;
13
12
app -> settings .show_headers = true;
13
+ app -> settings .rfid_duration = 2500 ;
14
+ app -> settings .nfc_duration = 1000 ;
14
15
app -> settings .subghz_use_ext_antenna = false;
15
16
app -> settings .show_hidden = false;
16
17
}
@@ -21,11 +22,13 @@ void quac_load_settings(App* app) {
21
22
temp_str = furi_string_alloc ();
22
23
uint32_t temp_data32 = 0 ;
23
24
25
+ // Initialize settings to the defaults
26
+ quac_set_default_settings (app );
27
+
24
28
FURI_LOG_I (TAG , "SETTINGS: Reading: %s" , QUAC_SETTINGS_PATH );
25
- bool successful = false;
26
29
do {
27
30
if (!flipper_format_file_open_existing (fff_settings , QUAC_SETTINGS_PATH )) {
28
- FURI_LOG_I (TAG , "SETTINGS: File not found, loading defaults" );
31
+ FURI_LOG_I (TAG , "SETTINGS: File not found, using defaults" );
29
32
break ;
30
33
}
31
34
@@ -43,55 +46,54 @@ void quac_load_settings(App* app) {
43
46
44
47
// Now read actual values we care about
45
48
if (!flipper_format_read_string (fff_settings , "Layout" , temp_str )) {
46
- FURI_LOG_E (TAG , "SETTINGS: Missing Layout" );
47
- break ;
48
- }
49
- if (!strcmp (furi_string_get_cstr (temp_str ), "Landscape" )) {
50
- app -> settings .layout = QUAC_APP_LANDSCAPE ;
51
- } else if (!strcmp (furi_string_get_cstr (temp_str ), "Portrait" )) {
52
- app -> settings .layout = QUAC_APP_PORTRAIT ;
49
+ FURI_LOG_W (TAG , "SETTINGS: Missing Layout" );
53
50
} else {
54
- FURI_LOG_E (TAG , "SETTINGS: Invalid Layout" );
55
- break ;
51
+ if (!strcmp (furi_string_get_cstr (temp_str ), "Landscape" )) {
52
+ app -> settings .layout = QUAC_APP_LANDSCAPE ;
53
+ } else if (!strcmp (furi_string_get_cstr (temp_str ), "Portrait" )) {
54
+ app -> settings .layout = QUAC_APP_PORTRAIT ;
55
+ } else {
56
+ FURI_LOG_E (TAG , "SETTINGS: Invalid Layout" );
57
+ }
56
58
}
57
59
58
60
if (!flipper_format_read_uint32 (fff_settings , "Show Icons" , & temp_data32 , 1 )) {
59
- FURI_LOG_E (TAG , "SETTINGS: Missing 'Show Icons'" );
60
- break ;
61
+ FURI_LOG_W (TAG , "SETTINGS: Missing 'Show Icons'" );
62
+ } else {
63
+ app -> settings .show_icons = (temp_data32 == 0 ) ? false : true;
61
64
}
62
- app -> settings .show_icons = (temp_data32 == 0 ) ? false : true;
63
65
64
66
if (!flipper_format_read_uint32 (fff_settings , "Show Headers" , & temp_data32 , 1 )) {
65
- FURI_LOG_E (TAG , "SETTINGS: Missing 'Show Headers'" );
66
- break ;
67
+ FURI_LOG_W (TAG , "SETTINGS: Missing 'Show Headers'" );
68
+ } else {
69
+ app -> settings .show_headers = (temp_data32 == 1 ) ? true : false;
67
70
}
68
- app -> settings .show_headers = (temp_data32 == 1 ) ? true : false;
69
71
70
72
if (!flipper_format_read_uint32 (fff_settings , "RFID Duration" , & temp_data32 , 1 )) {
71
- FURI_LOG_E (TAG , "SETTINGS: Missing 'RFID Duration'" );
72
- break ;
73
+ FURI_LOG_W (TAG , "SETTINGS: Missing 'RFID Duration'" );
74
+ } else {
75
+ app -> settings .rfid_duration = temp_data32 ;
76
+ }
77
+
78
+ if (!flipper_format_read_uint32 (fff_settings , "NFC Duration" , & temp_data32 , 1 )) {
79
+ FURI_LOG_W (TAG , "SETTINGS: Missing 'NFC Duration'" );
80
+ } else {
81
+ app -> settings .nfc_duration = temp_data32 ;
73
82
}
74
- app -> settings .rfid_duration = temp_data32 ;
75
83
76
84
if (!flipper_format_read_uint32 (fff_settings , "SubGHz Ext Antenna" , & temp_data32 , 1 )) {
77
- FURI_LOG_E (TAG , "SETTINGS: Missing 'SubGHz Ext Antenna'" );
78
- break ;
85
+ FURI_LOG_W (TAG , "SETTINGS: Missing 'SubGHz Ext Antenna'" );
86
+ } else {
87
+ app -> settings .subghz_use_ext_antenna = (temp_data32 == 1 ) ? true : false;
79
88
}
80
- app -> settings .subghz_use_ext_antenna = (temp_data32 == 1 ) ? true : false;
81
89
82
90
if (!flipper_format_read_uint32 (fff_settings , "Show Hidden" , & temp_data32 , 1 )) {
83
- FURI_LOG_E (TAG , "SETTINGS: Missing 'Show Hidden'" );
84
- break ;
91
+ FURI_LOG_W (TAG , "SETTINGS: Missing 'Show Hidden'" );
92
+ } else {
93
+ app -> settings .show_hidden = (temp_data32 == 1 ) ? true : false;
85
94
}
86
- app -> settings .show_hidden = (temp_data32 == 1 ) ? true : false;
87
-
88
- successful = true;
89
95
} while (false);
90
96
91
- if (!successful ) {
92
- quac_set_default_settings (app );
93
- }
94
-
95
97
furi_string_free (temp_str );
96
98
flipper_format_free (fff_settings );
97
99
}
@@ -137,6 +139,11 @@ void quac_save_settings(App* app) {
137
139
FURI_LOG_E (TAG , "SETTINGS: Failed to write 'RFID Duration'" );
138
140
break ;
139
141
}
142
+ if (!flipper_format_write_uint32 (
143
+ fff_settings , "NFC Duration" , & app -> settings .nfc_duration , 1 )) {
144
+ FURI_LOG_E (TAG , "SETTINGS: Failed to write 'NFC Duration'" );
145
+ break ;
146
+ }
140
147
temp_data32 = app -> settings .subghz_use_ext_antenna ? 1 : 0 ;
141
148
if (!flipper_format_write_uint32 (fff_settings , "SubGHz Ext Antenna" , & temp_data32 , 1 )) {
142
149
FURI_LOG_E (TAG , "SETTINGS: Failed to write 'SubGHz Ext Antenna'" );
0 commit comments