Skip to content

Commit

Permalink
Merge pull request #8 from Willy-JL/some-fixes
Browse files Browse the repository at this point in the history
Some fixes
  • Loading branch information
rdefeo authored Jun 1, 2024
2 parents d366342 + a00bc10 commit e2ad6a1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
12 changes: 4 additions & 8 deletions actions/action_subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
}
} else { // if not RAW protocol
FURI_LOG_I(TAG, "Protocol != RAW");
bool repeat_exists = flipper_format_key_exist(fff_data_file, "Repeat");
if(!repeat_exists) {
flipper_format_write_uint32(fff_data_file, "Repeat", &repeat, 1);
}
flipper_format_insert_or_update_uint32(fff_data_file, "Repeat", &repeat, 1);
transmitter =
subghz_transmitter_alloc_init(environment, furi_string_get_cstr(temp_str));
if(transmitter == NULL) {
Expand All @@ -240,17 +237,16 @@ void action_subghz_tx(void* context, const FuriString* action_path, FuriString*
is_init_protocol = false;
}
}
if(!repeat_exists) {
flipper_format_delete_key(fff_data_file, "Repeat");
}
}

if(is_init_protocol) {
check_file = true;
} else {
subghz_devices_sleep(device);
subghz_devices_end(device);
subghz_transmitter_free(transmitter);
if(transmitter != NULL) {
subghz_transmitter_free(transmitter);
}
}
} while(false);

Expand Down
9 changes: 7 additions & 2 deletions scenes/scene_action_create_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ bool scene_action_create_group_on_event(void* context, SceneManagerEvent event)
if(!strcmp(app->temp_cstr, "")) {
return false;
}
Item* item = ItemArray_get(app->items_view->items, app->selected_item);

FuriString* current_path = furi_string_alloc();
path_extract_dirname(furi_string_get_cstr(item->path), current_path);
if(app->selected_item != EMPTY_ACTION_INDEX) {
Item* item = ItemArray_get(app->items_view->items, app->selected_item);
path_extract_dirname(furi_string_get_cstr(item->path), current_path);
} else {
furi_string_set(current_path, app->items_view->path);
}

FuriString* new_group_path = furi_string_alloc();
furi_string_printf(
Expand Down
2 changes: 1 addition & 1 deletion scenes/scene_action_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool scene_action_rename_on_event(void* context, SceneManagerEvent event) {
FuriString* new_path = furi_string_alloc_printf(
"%s/%s%s", furi_string_get_cstr(dir_name), app->temp_cstr, item->ext);

// FURI_LOG_I(TAG, "Rename: %s to %s", old_path, furi_string_get_cstr(new_path));
FURI_LOG_I(TAG, "Rename: %s to %s", old_path, furi_string_get_cstr(new_path));
FS_Error fs_result =
storage_common_rename(app->storage, old_path, furi_string_get_cstr(new_path));
if(fs_result == FSE_OK) {
Expand Down
39 changes: 16 additions & 23 deletions scenes/scene_action_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,19 @@ static bool scene_action_settings_import_file_browser_callback(

// Ask user for file to import from elsewhere on the SD card
FuriString* scene_action_get_file_to_import_alloc(App* app) {
FuriString* current_path = furi_string_alloc();
if(app->selected_item != EMPTY_ACTION_INDEX) {
Item* item = ItemArray_get(app->items_view->items, app->selected_item);
path_extract_dirname(furi_string_get_cstr(item->path), current_path);
} else {
furi_string_set(current_path, app->items_view->path);
}

// Setup our file browser options
DialogsFileBrowserOptions fb_options;
dialog_file_browser_set_basic_options(&fb_options, "", NULL);
fb_options.base_path = furi_string_get_cstr(current_path);
fb_options.base_path = STORAGE_EXT_PATH_PREFIX;
fb_options.skip_assets = true;
furi_string_set_str(app->temp_str, fb_options.base_path);
fb_options.item_loader_callback = scene_action_settings_import_file_browser_callback;
fb_options.item_loader_context = app;

FuriString* full_path = NULL;
if(dialog_file_browser_show(app->dialog, app->temp_str, app->temp_str, &fb_options)) {
// FURI_LOG_I(TAG, "Selected file is %s", furi_string_get_cstr(app->temp_str));
FuriString* file_name = furi_string_alloc();
path_extract_filename(app->temp_str, file_name, false);
// FURI_LOG_I(TAG, "Importing file %s", furi_string_get_cstr(file_name));
full_path = furi_string_alloc_printf(
"%s/%s", furi_string_get_cstr(current_path), furi_string_get_cstr(file_name));
// FURI_LOG_I(TAG, "New path is %s", furi_string_get_cstr(full_path));
furi_string_free(file_name);
} else {
// FURI_LOG_I(TAG, "User cancelled");
full_path = furi_string_alloc_set(app->temp_str);
}
furi_string_free(current_path);
return full_path;
}

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

FURI_LOG_I(
TAG,
"Copy: %s to %s",
furi_string_get_cstr(import_file),
furi_string_get_cstr(full_path));
FS_Error fs_result = storage_common_copy(
app->storage,
furi_string_get_cstr(import_file),
furi_string_get_cstr(full_path));
if(fs_result == FSE_OK) {
} else {
if(fs_result != FSE_OK) {
FURI_LOG_E(
TAG, "Copy file failed! %s", filesystem_api_error_get_desc(fs_result));
FuriString* error_msg = furi_string_alloc_printf(
"Copy failed!\nError: %s", filesystem_api_error_get_desc(fs_result));
dialog_message_show_storage_error(
app->dialog, furi_string_get_cstr(error_msg));
furi_string_free(error_msg);
}
furi_string_free(file_name);
furi_string_free(full_path);
Expand Down

0 comments on commit e2ad6a1

Please sign in to comment.