Skip to content

Commit e2ad6a1

Browse files
authored
Merge pull request #8 from Willy-JL/some-fixes
Some fixes
2 parents d366342 + a00bc10 commit e2ad6a1

4 files changed

+28
-34
lines changed

actions/action_subghz.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
222222
}
223223
} else { // if not RAW protocol
224224
FURI_LOG_I(TAG, "Protocol != RAW");
225-
bool repeat_exists = flipper_format_key_exist(fff_data_file, "Repeat");
226-
if(!repeat_exists) {
227-
flipper_format_write_uint32(fff_data_file, "Repeat", &repeat, 1);
228-
}
225+
flipper_format_insert_or_update_uint32(fff_data_file, "Repeat", &repeat, 1);
229226
transmitter =
230227
subghz_transmitter_alloc_init(environment, furi_string_get_cstr(temp_str));
231228
if(transmitter == NULL) {
@@ -240,17 +237,16 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
240237
is_init_protocol = false;
241238
}
242239
}
243-
if(!repeat_exists) {
244-
flipper_format_delete_key(fff_data_file, "Repeat");
245-
}
246240
}
247241

248242
if(is_init_protocol) {
249243
check_file = true;
250244
} else {
251245
subghz_devices_sleep(device);
252246
subghz_devices_end(device);
253-
subghz_transmitter_free(transmitter);
247+
if(transmitter != NULL) {
248+
subghz_transmitter_free(transmitter);
249+
}
254250
}
255251
} while(false);
256252

scenes/scene_action_create_group.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ bool scene_action_create_group_on_event(void* context, SceneManagerEvent event)
4545
if(!strcmp(app->temp_cstr, "")) {
4646
return false;
4747
}
48-
Item* item = ItemArray_get(app->items_view->items, app->selected_item);
48+
4949
FuriString* current_path = furi_string_alloc();
50-
path_extract_dirname(furi_string_get_cstr(item->path), current_path);
50+
if(app->selected_item != EMPTY_ACTION_INDEX) {
51+
Item* item = ItemArray_get(app->items_view->items, app->selected_item);
52+
path_extract_dirname(furi_string_get_cstr(item->path), current_path);
53+
} else {
54+
furi_string_set(current_path, app->items_view->path);
55+
}
5156

5257
FuriString* new_group_path = furi_string_alloc();
5358
furi_string_printf(

scenes/scene_action_rename.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool scene_action_rename_on_event(void* context, SceneManagerEvent event) {
6666
FuriString* new_path = furi_string_alloc_printf(
6767
"%s/%s%s", furi_string_get_cstr(dir_name), app->temp_cstr, item->ext);
6868

69-
// FURI_LOG_I(TAG, "Rename: %s to %s", old_path, furi_string_get_cstr(new_path));
69+
FURI_LOG_I(TAG, "Rename: %s to %s", old_path, furi_string_get_cstr(new_path));
7070
FS_Error fs_result =
7171
storage_common_rename(app->storage, old_path, furi_string_get_cstr(new_path));
7272
if(fs_result == FSE_OK) {

scenes/scene_action_settings.c

+16-23
Original file line numberDiff line numberDiff line change
@@ -93,37 +93,19 @@ static bool scene_action_settings_import_file_browser_callback(
9393

9494
// Ask user for file to import from elsewhere on the SD card
9595
FuriString* scene_action_get_file_to_import_alloc(App* app) {
96-
FuriString* current_path = furi_string_alloc();
97-
if(app->selected_item != EMPTY_ACTION_INDEX) {
98-
Item* item = ItemArray_get(app->items_view->items, app->selected_item);
99-
path_extract_dirname(furi_string_get_cstr(item->path), current_path);
100-
} else {
101-
furi_string_set(current_path, app->items_view->path);
102-
}
103-
10496
// Setup our file browser options
10597
DialogsFileBrowserOptions fb_options;
10698
dialog_file_browser_set_basic_options(&fb_options, "", NULL);
107-
fb_options.base_path = furi_string_get_cstr(current_path);
99+
fb_options.base_path = STORAGE_EXT_PATH_PREFIX;
108100
fb_options.skip_assets = true;
109101
furi_string_set_str(app->temp_str, fb_options.base_path);
110102
fb_options.item_loader_callback = scene_action_settings_import_file_browser_callback;
111103
fb_options.item_loader_context = app;
112104

113105
FuriString* full_path = NULL;
114106
if(dialog_file_browser_show(app->dialog, app->temp_str, app->temp_str, &fb_options)) {
115-
// FURI_LOG_I(TAG, "Selected file is %s", furi_string_get_cstr(app->temp_str));
116-
FuriString* file_name = furi_string_alloc();
117-
path_extract_filename(app->temp_str, file_name, false);
118-
// FURI_LOG_I(TAG, "Importing file %s", furi_string_get_cstr(file_name));
119-
full_path = furi_string_alloc_printf(
120-
"%s/%s", furi_string_get_cstr(current_path), furi_string_get_cstr(file_name));
121-
// FURI_LOG_I(TAG, "New path is %s", furi_string_get_cstr(full_path));
122-
furi_string_free(file_name);
123-
} else {
124-
// FURI_LOG_I(TAG, "User cancelled");
107+
full_path = furi_string_alloc_set(app->temp_str);
125108
}
126-
furi_string_free(current_path);
127109
return full_path;
128110
}
129111

@@ -241,8 +223,8 @@ bool scene_action_settings_on_event(void* context, SceneManagerEvent event) {
241223
consumed = true;
242224
// get the filename to import
243225
FuriString* import_file = scene_action_get_file_to_import_alloc(app);
244-
FURI_LOG_I(TAG, "Importing %s", furi_string_get_cstr(import_file));
245226
if(import_file) {
227+
FURI_LOG_I(TAG, "Importing %s", furi_string_get_cstr(import_file));
246228
// if it's a .ir file, switch to a scene that lets user pick the command from the file
247229
// only if there's more than one command in the file. then copy that relevant chunk
248230
// to the local directory
@@ -274,12 +256,23 @@ bool scene_action_settings_on_event(void* context, SceneManagerEvent event) {
274256
furi_string_get_cstr(file_name));
275257
// FURI_LOG_I(TAG, "New path is %s", furi_string_get_cstr(full_path));
276258

259+
FURI_LOG_I(
260+
TAG,
261+
"Copy: %s to %s",
262+
furi_string_get_cstr(import_file),
263+
furi_string_get_cstr(full_path));
277264
FS_Error fs_result = storage_common_copy(
278265
app->storage,
279266
furi_string_get_cstr(import_file),
280267
furi_string_get_cstr(full_path));
281-
if(fs_result == FSE_OK) {
282-
} else {
268+
if(fs_result != FSE_OK) {
269+
FURI_LOG_E(
270+
TAG, "Copy file failed! %s", filesystem_api_error_get_desc(fs_result));
271+
FuriString* error_msg = furi_string_alloc_printf(
272+
"Copy failed!\nError: %s", filesystem_api_error_get_desc(fs_result));
273+
dialog_message_show_storage_error(
274+
app->dialog, furi_string_get_cstr(error_msg));
275+
furi_string_free(error_msg);
283276
}
284277
furi_string_free(file_name);
285278
furi_string_free(full_path);

0 commit comments

Comments
 (0)