//! Go to next file or directory in file list FLAT //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! bool nav_flat_next( void ) { uint16_t u16_save_current_pos; u16_save_current_pos = nav_filelist_get(); if( nav_file_isdir() ) { // The current file is a dir then enter in this if( !nav_dir_cd() ) return false; if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) { // A file is present in this dir then valid the new position fs_g_nav.u8_flat_dir_level++; fs_g_nav.u16_flat_pos_offset += u16_save_current_pos+1; return true; }else{ // No file then return in parent dir if( !nav_dir_gotoparent() ) return false; // Error } } // Find next file in the current dir or the parent dir while( !nav_filelist_set( 0 , FS_FIND_NEXT ) ) { // End of the directory then goes to parent if( 0 == fs_g_nav.u8_flat_dir_level ) return false; // End of list FLAT if( !nav_dir_gotoparent() ) return false; // Error fs_g_nav.u8_flat_dir_level--; } fs_g_nav.u16_flat_pos_offset = (fs_g_nav.u16_flat_pos_offset +u16_save_current_pos +1) -nav_filelist_get(); return true; }
//! This function moves back to the parent directory and selects this directory //! //! @param b_direction direction of navigation (FS_FIND_NEXT or FS_FIND_PREV) //! //! @return The state of the function //! static navauto_mov_explorer_rec_t navauto_mov_explorer_updir(bool b_direction) { // To support directory only mode if (g_navauto_exp_mode == NAVAUTO_MODE_DIRONLY) return NAVAUTO_MOV_EXPLORER_ERROR; // To Support subdirectories mode if (g_navauto_exp_mode == NAVAUTO_MODE_DIRSUB) { // If the selection is on the root level if (g_navauto_u16_dir_level <= g_navauto_u16_dir_level_root) return NAVAUTO_MOV_EXPLORER_ERROR; } if (nav_dir_gotoparent()) { // Set folder change bit bitfield_status.folder_change = 1; g_navauto_u16_dir_level--; return NAVAUTO_MOV_EXPLORER_RECURSIVE; } else // If it fails, means the pointer is on the root return NAVAUTO_MOV_EXPLORER_ERROR; }
//! This function resets the selection pointer, so "no file is selected" in file list FLAT //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! bool nav_flat_reset( void ) { while( 0 != fs_g_nav.u8_flat_dir_level ) { fs_g_nav.u8_flat_dir_level--; nav_dir_gotoparent(); } fs_g_nav.u16_flat_pos_offset = 0; return nav_filelist_reset(); }
//! This function goes to the parent directory //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! //! @verbatim //! After the selected file is the first entry of the new file list FLAT //! @endverbatim //! bool nav_flat_gotoparent( void ) { _MEM_TYPE_SLOW_ Fs_index index; index = nav_getindex(); while( 0 != fs_g_nav.u8_flat_dir_level ) { fs_g_nav.u8_flat_dir_level--; nav_dir_gotoparent(); } if( !nav_dir_gotoparent() ) { nav_gotoindex( &index ); return false; } // Go to at the beginning of FLAT list fs_g_nav.u8_flat_dir_level = 0; fs_g_nav.u16_flat_pos_offset = 0; nav_filelist_reset(); nav_flat_next(); return true; }
//! Go to previous file or directory in file list FLAT //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! bool nav_flat_previous( void ) { uint16_t u16_save_current_pos; u16_save_current_pos = nav_filelist_get(); if( nav_filelist_set( 0 , FS_FIND_PREV ) ) { while( 1 ) { if( !nav_file_isdir() ) { fs_g_nav.u16_flat_pos_offset = ((fs_g_nav.u16_flat_pos_offset +u16_save_current_pos) -nav_filelist_get()) -1; return true; // New valid position } // The selection is a dir then enter in this if( !nav_dir_cd() ) return false; if( !nav_filelist_set( 0 , FS_FIND_NEXT ) ) { // The dir is empty then goes to the parent nav_dir_gotoparent(); // The parent dir is the new selection fs_g_nav.u16_flat_pos_offset = ((fs_g_nav.u16_flat_pos_offset +u16_save_current_pos) -nav_filelist_get()) -1; return true; } fs_g_nav.u8_flat_dir_level++; // Go to the end of dir while( nav_filelist_set( 0 , FS_FIND_NEXT ) ); } } // Beginning of the directory then goes to parent directory if( 0 == fs_g_nav.u8_flat_dir_level ) return false; // beginning of the file list FLAT if( !nav_dir_gotoparent() ) return false; fs_g_nav.u8_flat_dir_level--; fs_g_nav.u16_flat_pos_offset -= (nav_filelist_get()+1); return true; }
//! @brief Synchronize a path with an other path //! //! @return true if success //! bool ushell_cmd_sync( void ) { Fs_index sav_index; uint8_t u8_folder_level = 0; if( g_s_arg[0][0] == 0 ) return false; if( g_s_arg[1][0] == 0 ) return false; // Add '\' at the end of path, else the nav_setcwd select the directory but don't enter into. ushell_path_valid_syntac( g_s_arg[0] ); ushell_path_valid_syntac( g_s_arg[1] ); printf("Synchronize folders:\n\r"); sav_index = nav_getindex(); // Save the position // Select source directory in COPYFILE navigator handle nav_select( FS_NAV_ID_COPYFILE ); printf("Select source directory\n\r"); if( !nav_setcwd( (FS_STRING)g_s_arg[0], true, false ) ) goto ushell_cmd_sync_error; nav_filelist_reset(); // Select destination directory in USHELL navigator handle nav_select( FS_NAV_ID_USHELL_CMD ); printf("Select destination directory\n\r"); if( !nav_setcwd( (FS_STRING)g_s_arg[1], true, true ) ) goto ushell_cmd_sync_error; nav_filelist_reset(); // loop to scan and create ALL folders and files while(1) { while(1) { // Loop to Search files or directories // Reselect Source nav_select( FS_NAV_ID_COPYFILE ); if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) break; // a next file and directory is found // No other dir or file in current dir then go to parent dir on Source and Destination disk if( 0 == u8_folder_level ) { // end of update folder //********* END OF COPY ************** goto ushell_cmd_sync_finish; } printf("Go to parent\n\r"); // Remark, nav_dir_gotoparent() routine go to in parent dir and select the children dir in list u8_folder_level--; if( !nav_dir_gotoparent() ) goto ushell_cmd_sync_error; // Select Destination navigator and go to the same dir of Source nav_select( FS_NAV_ID_USHELL_CMD ); if( !nav_dir_gotoparent() ) goto ushell_cmd_sync_error; } // end of while (1) if( nav_file_isdir()) { printf("Dir found - create dir: "); //** here, a new directory is found and is selected // Get name of current selection (= dir name on Source) if( !nav_file_name( (FS_STRING)g_s_arg[0], USHELL_SIZE_CMD_LINE, FS_NAME_GET, false )) goto ushell_cmd_sync_error; // Enter in dir (on Source) if( !nav_dir_cd()) goto ushell_cmd_sync_error; u8_folder_level++; // Select Destination disk nav_select( FS_NAV_ID_USHELL_CMD ); // Create folder in Destination disk printf((char*)g_s_arg[0]); printf("\n\r"); if( !nav_dir_make( (FS_STRING )g_s_arg[0] )) { if( FS_ERR_FILE_EXIST != fs_g_status ) goto ushell_cmd_sync_error; // here, error the name exist } // Here the navigator have selected the folder on Destination if( !nav_dir_cd()) { if( FS_ERR_NO_DIR == fs_g_status ) { // FYC -> Copy impossible, because a file have the same name of folder } goto ushell_cmd_sync_error; } // here, the folder is created and the navigator is entered in this dir } else { printf("File found - copy file: "); //** here, a new file is found and is selected // Get name of current selection (= file name on Source) if( !nav_file_name( (FS_STRING)g_s_arg[0], USHELL_SIZE_CMD_LINE, FS_NAME_GET, false )) goto ushell_cmd_sync_error; printf((char*)g_s_arg[0]); printf("\n\r"); if( !nav_file_copy()) goto ushell_cmd_sync_error; // Paste file in current dir of Destination disk nav_select( FS_NAV_ID_USHELL_CMD ); while( !nav_file_paste_start( (FS_STRING)g_s_arg[0] ) ) { // Error if( fs_g_status != FS_ERR_FILE_EXIST ) goto ushell_cmd_sync_error; // File exists then deletes this one printf("File exists then deletes this one.\n\r"); if( !nav_file_del( true ) ) goto ushell_cmd_sync_error; // here, retry PASTE } // Copy running { uint8_t status; do{ status = nav_file_paste_state(false); }while( COPY_BUSY == status ); if( COPY_FINISH != status ) goto ushell_cmd_sync_error; } } // if dir OR file } // end of first while(1) ushell_cmd_sync_error: // Restore the position nav_select( FS_NAV_ID_USHELL_CMD ); nav_gotoindex(&sav_index); printf("!!!Copy fail\n\r"); return false; ushell_cmd_sync_finish: // Restore the position nav_select( FS_NAV_ID_USHELL_CMD ); nav_gotoindex(&sav_index); printf("End of copy\n\r"); return true; }
//! @brief This function go back to parent directory //! void ushell_cmd_gotoparent( void ) { nav_dir_gotoparent(); }
//! This function opens a file list at the current position in navigator //! //! @param b_playlist if true then the current selected file is a play list file to open //! else create a file list with files included in a disk part //! @param pos If b_playlist true, then position in the play list to start //! else folder level of the current position //! //! @return false, in case of error or file list empty //! bool navauto_open( bool b_playlist , uint16_t pos ) { Navauto_mov_state state; g_navauto_b_playlist = b_playlist; g_navauto_u16_dir_level_root = 0; g_navauto_u16_nb = 0; if( b_playlist ) { g_navauto_u16_pos = pos; if( !pl_main_open(false) ) return false; g_navauto_u16_nb = pl_nav_getnbfile(); if( 0 == g_navauto_u16_nb ) return false; if( NAVAUTO_RAND_OFF == navauto_getrand() ) { if( pl_nav_setpos( g_navauto_u16_pos )) { if( nav_filelist_validpos() ) return true; } }else{ navauto_rand_init(); } // Error position then restart at the beginning g_navauto_u16_pos = 0; } else { #if( FS_NAV_AUTOMATIC_NBFILE == ENABLE ) Fs_index index; Fs_index index2; Navauto_rand rand_mode; uint16_t u16_current_pos=0; index.u8_lun = 0xFF; // Reset index (by default no valid selected file) g_navauto_u16_dir_level = pos; rand_mode = navauto_getrand(); // Save random mode navauto_setrand( NAVAUTO_RAND_OFF ); // If no valid file then found the first valid file if( !nav_file_checkext( g_navauto_filter )) { // Go to previous position because "navauto_mov_explorer()" execute a next before search valid file if( !nav_filelist_set( 0 , FS_FIND_PREV ) ) nav_filelist_reset(); state = navauto_mov_explorer(FS_FIND_NEXT, NAVAUTO_MOV_OPTS_NONE); if((NAVAUTO_MOV_OK_LOOP != state.status) && (NAVAUTO_MOV_OK != state.status) ) { navauto_setrand(rand_mode); return false; // List empty } } index = nav_getindex(); // Compute the size of file list and search the position of selected file navauto_mov_explorer_reset(); // Go to beginning of loop // Note: the number of file is updated in navauto_mov_explorer() routine when the end of list is detected while( navauto_mov_explorer( FS_FIND_NEXT, NAVAUTO_MOV_OPTS_NONE ).status == NAVAUTO_MOV_OK ) { index2 = nav_getindex(); // Check the current position with the selected file if( (index.u8_lun == index2.u8_lun) && (index.u32_cluster_sel_dir == index2.u32_cluster_sel_dir) && (index.u16_entry_pos_sel_file == index2.u16_entry_pos_sel_file) ) { u16_current_pos = g_navauto_u16_pos; // Save the position number found g_navauto_u16_dir_level_root = g_navauto_u16_dir_level; } } navauto_setrand(rand_mode); // Restore random mode if( 0 == g_navauto_u16_nb ) return false; // loop empty // Go to a file from file list if( NAVAUTO_RAND_OFF == navauto_getrand() ) { if( 0xFF != index.u8_lun ) { // Reselect the file selected at startup nav_gotoindex( &index ); // Go to this one g_navauto_u16_dir_level = g_navauto_u16_dir_level_root; // Update position file g_navauto_u16_pos = u16_current_pos; // Update folder level corresponding at file } // Else, the first file is already selected at the end of "compute file list size" loop return true; }else{ navauto_rand_init(); } #else Fs_index index; Navauto_rand rand_mode; rand_mode = navauto_getrand(); navauto_setrand(NAVAUTO_RAND_OFF); // If no valid file then find the first valid file if( !nav_file_checkext( g_navauto_filter )) { // Go to previous position because "navauto_mov_explorer()" execute a next before search valid file if( !nav_filelist_set( 0 , FS_FIND_PREV ) ) nav_filelist_reset(); state = navauto_mov_explorer(FS_FIND_NEXT, NAVAUTO_MOV_OPTS_NONE); if((NAVAUTO_MOV_OK_LOOP != state.status) && (NAVAUTO_MOV_OK != state.status) ) { navauto_setrand(rand_mode); return false; // List empty } } index = nav_getindex(); navauto_setrand(rand_mode); navauto_mov_explorer_reset(); // Compute directory level g_navauto_u16_dir_level = 0; while(nav_dir_gotoparent()) g_navauto_u16_dir_level++; g_navauto_u16_dir_level_root = g_navauto_u16_dir_level; //g_navauto_u16_dir_level = pos; // Restore index nav_gotoindex(&index); g_navauto_u16_nb = 0xFFFF; if( NAVAUTO_RAND_OFF == navauto_getrand() ) navauto_rand_init(); if( nav_file_checkext( g_navauto_filter )) { // Valid file then update position with the first position but it is not the first ! g_navauto_u16_pos = 1; return true; } #endif } // Find first file or use the random feature state = navauto_mov(FS_FIND_NEXT, NAVAUTO_MOV_OPTS_NONE); if((NAVAUTO_MOV_OK_LOOP != state.status) && (NAVAUTO_MOV_OK != state.status) ) return false; // List empty return true; }
//! This function moves back to the parent directory and selects this directory //! //! @param b_direction direction of navigation (FS_FIND_NEXT or FS_FIND_PREV) //! //! @return The state of the function //! static navauto_mov_explorer_rec_t navauto_mov_explorer_updir(bool b_direction) { bool b_updir_ok = false; // To support directory only mode if (g_navauto_exp_mode == NAVAUTO_MODE_DIRONLY) return NAVAUTO_MOV_EXPLORER_ERROR; // To Support subdirectories mode if (g_navauto_exp_mode == NAVAUTO_MODE_DIRSUB) { // If the selection is on the root level if (g_navauto_u16_dir_level <= g_navauto_u16_dir_level_root) return NAVAUTO_MOV_EXPLORER_ERROR; } #if defined(NAVAUTO_SPEED_OPTIMIZATION) && NAVAUTO_SPEED_OPTIMIZATION == true if (i_navauto_cache >= 0) { if (i_navauto_cache >= NAVAUTO_SPEED_OPTIMIZATION_LEVEL) { if (nav_dir_gotoparent()) { b_updir_ok = true; i_navauto_cache--; } } else { fat_clear_entry_info_and_ptr(); // Look for the "../" directory entry fs_g_nav_fast.u16_entry_pos_sel_file = 1; if (!fat_read_dir()) return NAVAUTO_MOV_EXPLORER_ERROR; fat_get_entry_info(); fs_g_nav.u32_cluster_sel_dir = fs_g_nav_entry.u32_cluster; fs_g_nav.u16_pos_sel_file = navauto_cache[i_navauto_cache].u16_pos_file; fs_g_nav_fast.u16_entry_pos_sel_file = navauto_cache[i_navauto_cache].u16_entry_pos_file; fat_read_dir(); fat_get_entry_info(); i_navauto_cache--; b_updir_ok = true; } } #else if (nav_dir_gotoparent()) b_updir_ok = true; #endif if (b_updir_ok) { // Set folder change bit bitfield_status.folder_change = 1; g_navauto_u16_dir_level--; return NAVAUTO_MOV_EXPLORER_RECURSIVE; } else // If it fails, means the pointer is on the root return NAVAUTO_MOV_EXPLORER_ERROR; }
//! This function adds files in play list //! //! @param sz_filterext add file only corresponding to the extension filter //! @param u8_mode PL_ADD_FILE, PL_ADD_DIR, PL_ADD_SUBDIR //! //! @return false in case of error, see global value "fs_g_status" for more detail //! @return true otherwise //! //! @verbatim //! It is possible to select a file or all files in a directory //! @endverbatim //! bool pl_add( const FS_STRING sz_filterext , uint8_t u8_mode ) { uint8_t nav_id_save; uint8_t u8_folder_level; if( !pl_main_modify() ) return false; nav_id_save = nav_get(); // Check last character of file nav_select( FS_NAV_ID_PLAYLIST ); if( 0!=nav_file_lgt() ) { #if( PL_UNICODE == true) file_string_unicode(); file_seek( 2, FS_SEEK_END); if( '\n' != file_getc()) { file_seek( 2, FS_SEEK_END); file_putc('\n'); } file_string_ascii(); #else file_seek( 1, FS_SEEK_END); if( '\n' != file_getc()) { file_seek( 1, FS_SEEK_END); file_putc('\n'); } #endif } nav_select( nav_id_save ); // Get path of play list file and check with current to create a relative path if( PL_ADD_FILE == u8_mode ) goto pl_add_file; // Add all files valid in current dir u8_folder_level = 0; nav_filelist_reset(); while(1) { while(1) { if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) break; // a next file and directory is found // No other dir or file in current dir then go to parent dir if( 0 == u8_folder_level ) goto pl_add_end; // end of ADD // Remark, nav_dir_gotoparent() routine go to in parent dir and select the children dir in list u8_folder_level--; if( !nav_dir_gotoparent() ) return false; } if( nav_file_isdir()) { if( PL_ADD_SUBDIR == u8_mode ) { // Enter in sub dir if( !nav_dir_cd()) return false; u8_folder_level++; } } else { pl_add_file: if( nav_file_checkext( sz_filterext ) ) { // It is a valid file // Get name of current file #if( (FS_ASCII == true) && (FS_UNICODE == true) && (PL_UNICODE == false) ) nav_string_ascii(); #endif nav_getcwd( (FS_STRING)pl_cache_path, PL_CACHE_PATH_MAX_SIZE, true ); #if( (FS_ASCII == true) && (FS_UNICODE == true) && (PL_UNICODE == false) ) nav_string_unicode(); #endif // Write path in file list nav_select( FS_NAV_ID_PLAYLIST ); #if( PL_UNICODE == true) file_string_unicode(); #endif if( file_puts(pl_cache_path)) file_putc('\n'); #if( PL_UNICODE == true) file_string_ascii(); #endif nav_select( nav_id_save ); pl_g_u16_list_size++; } if( PL_ADD_FILE == u8_mode ) goto pl_add_end; } // if dir OR file } // end of first while(1) pl_add_end: // Go to beginning of file AND no file selected nav_select( FS_NAV_ID_PLAYLIST ); file_seek( 0 , FS_SEEK_SET ); pl_g_u16_list_sel = 0; nav_select( nav_id_save ); return true; }