BadUSB and Archive fixes (#2005)
* BsdUsb: fix empty lines handling * Archive: folders and unknown files rename fix Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									f9730bcafe
								
							
						
					
					
						commit
						73441af9c6
					
				@ -133,7 +133,7 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
 | 
			
		||||
        case ArchiveBrowserEventFileMenuRename:
 | 
			
		||||
            if(favorites) {
 | 
			
		||||
                browser->callback(ArchiveBrowserEventEnterFavMove, browser->context);
 | 
			
		||||
            } else if((archive_is_known_app(selected->type)) && (selected->is_app == false)) {
 | 
			
		||||
            } else if(selected->is_app == false) {
 | 
			
		||||
                archive_show_file_menu(browser, false);
 | 
			
		||||
                scene_manager_set_scene_state(
 | 
			
		||||
                    archive->scene_manager, ArchiveAppSceneBrowser, SCENE_STATE_NEED_REFRESH);
 | 
			
		||||
 | 
			
		||||
@ -57,9 +57,11 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
 | 
			
		||||
            ArchiveFile_t* file = archive_get_current_file(archive->browser);
 | 
			
		||||
 | 
			
		||||
            FuriString* path_dst;
 | 
			
		||||
 | 
			
		||||
            path_dst = furi_string_alloc();
 | 
			
		||||
            path_extract_dirname(path_src, path_dst);
 | 
			
		||||
            furi_string_cat_printf(path_dst, "/%s%s", archive->text_store, known_ext[file->type]);
 | 
			
		||||
            furi_string_cat_printf(
 | 
			
		||||
                path_dst, "/%s%s", archive->text_store, archive->file_extension);
 | 
			
		||||
 | 
			
		||||
            storage_common_rename(fs_api, path_src, furi_string_get_cstr(path_dst));
 | 
			
		||||
            furi_record_close(RECORD_STORAGE);
 | 
			
		||||
 | 
			
		||||
@ -65,7 +65,6 @@ static void render_item_menu(Canvas* canvas, ArchiveBrowserViewModel* model) {
 | 
			
		||||
    if(!archive_is_known_app(selected->type)) {
 | 
			
		||||
        furi_string_set(menu[0], "---");
 | 
			
		||||
        furi_string_set(menu[1], "---");
 | 
			
		||||
        furi_string_set(menu[2], "---");
 | 
			
		||||
    } else {
 | 
			
		||||
        if(model->tab_idx == ArchiveTabFavorites) {
 | 
			
		||||
            furi_string_set(menu[2], "Move");
 | 
			
		||||
 | 
			
		||||
@ -237,12 +237,8 @@ static int32_t
 | 
			
		||||
    const char* line_tmp = furi_string_get_cstr(line);
 | 
			
		||||
    bool state = false;
 | 
			
		||||
 | 
			
		||||
    for(uint32_t i = 0; i < line_len; i++) {
 | 
			
		||||
        if((line_tmp[i] != ' ') && (line_tmp[i] != '\t') && (line_tmp[i] != '\n')) {
 | 
			
		||||
            line_tmp = &line_tmp[i];
 | 
			
		||||
            break; // Skip spaces and tabs
 | 
			
		||||
        }
 | 
			
		||||
        if(i == line_len - 1) return SCRIPT_STATE_NEXT_LINE; // Skip empty lines
 | 
			
		||||
    if(line_len == 0) {
 | 
			
		||||
        return SCRIPT_STATE_NEXT_LINE; // Skip empty lines
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    FURI_LOG_D(WORKER_TAG, "line:%s", line_tmp);
 | 
			
		||||
@ -450,10 +446,12 @@ static int32_t ducky_script_execute_next(BadUsbScript* bad_usb, File* script_fil
 | 
			
		||||
                bad_usb->st.line_cur++;
 | 
			
		||||
                bad_usb->buf_len = bad_usb->buf_len + bad_usb->buf_start - (i + 1);
 | 
			
		||||
                bad_usb->buf_start = i + 1;
 | 
			
		||||
                furi_string_trim(bad_usb->line);
 | 
			
		||||
                delay_val = ducky_parse_line(
 | 
			
		||||
                    bad_usb, bad_usb->line, bad_usb->st.error, sizeof(bad_usb->st.error));
 | 
			
		||||
 | 
			
		||||
                if(delay_val < 0) {
 | 
			
		||||
                if(delay_val == SCRIPT_STATE_NEXT_LINE) { // Empty line
 | 
			
		||||
                    return 0;
 | 
			
		||||
                } else if(delay_val < 0) {
 | 
			
		||||
                    bad_usb->st.error_line = bad_usb->st.line_cur;
 | 
			
		||||
                    FURI_LOG_E(WORKER_TAG, "Unknown command at line %u", bad_usb->st.line_cur);
 | 
			
		||||
                    return SCRIPT_STATE_ERROR;
 | 
			
		||||
 | 
			
		||||
@ -38,7 +38,7 @@ void path_extract_extension(FuriString* path, char* ext, size_t ext_len_max) {
 | 
			
		||||
    size_t dot = furi_string_search_rchar(path, '.');
 | 
			
		||||
    size_t filename_start = furi_string_search_rchar(path, '/');
 | 
			
		||||
 | 
			
		||||
    if((dot > 0) && (filename_start < dot)) {
 | 
			
		||||
    if((dot != FURI_STRING_FAILURE) && (filename_start < dot)) {
 | 
			
		||||
        strlcpy(ext, &(furi_string_get_cstr(path))[dot], ext_len_max);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user