00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "conf_explorer.h"
00047 #include "navigation.h"
00048 #include "nav_filterlist.h"
00049 #include "file.h"
00050 #include LIB_CTRLACCESS
00051
00052
00053
00054
00055
00056
00057
00058
00059
00064 void nav_filterlist_setfilter( const FS_STRING sz_filterext )
00065 {
00066 fs_g_nav.sz_filterext = sz_filterext;
00067 nav_filterlist_reset();
00068 }
00069
00070
00076 Bool nav_filterlist_reset( void )
00077 {
00078 fs_g_nav.u16_pos_filterlist = FS_NO_SEL;
00079 return nav_filelist_reset();
00080 }
00081
00082
00088 Bool nav_filterlist_next( void )
00089 {
00090 U16 u16_current_pos;
00091 u16_current_pos = nav_filelist_get();
00092 while( nav_filelist_set( 0, FS_FIND_NEXT ) )
00093 {
00094 if( nav_file_isdir()
00095 || nav_file_checkext( fs_g_nav.sz_filterext ) )
00096 {
00097 if( FS_NO_SEL == u16_current_pos )
00098 {
00099 fs_g_nav.u16_pos_filterlist = 0;
00100 }else{
00101 fs_g_nav.u16_pos_filterlist++;
00102 }
00103 return TRUE;
00104 }
00105 }
00106 nav_filelist_goto( u16_current_pos );
00107 return FALSE;
00108 }
00109
00110
00116 Bool nav_filterlist_previous( void )
00117 {
00118 U16 u16_current_pos;
00119 u16_current_pos = nav_filelist_get();
00120 while( nav_filelist_set( 0, FS_FIND_PREV ) )
00121 {
00122 if( nav_file_isdir()
00123 || nav_file_checkext( fs_g_nav.sz_filterext ) )
00124 {
00125 fs_g_nav.u16_pos_filterlist--;
00126 return TRUE;
00127 }
00128 }
00129 nav_filelist_goto( u16_current_pos );
00130 return FALSE;
00131 }
00132
00133
00139 U16 nav_filterlist_get( void )
00140 {
00141 return fs_g_nav.u16_pos_filterlist;
00142 }
00143
00144
00152 Bool nav_filterlist_goto( U16 u16_newpos )
00153 {
00154 if (u16_newpos == FS_NO_SEL)
00155 return nav_filterlist_reset();
00156
00157 if( u16_newpos < (fs_g_nav.u16_pos_filterlist/2) )
00158 {
00159
00160 if( !nav_filterlist_reset() )
00161 return FALSE;
00162 }
00163 if( FS_NO_SEL == fs_g_nav.u16_pos_filterlist )
00164 if( !nav_filterlist_next() )
00165 return FALSE;
00166 while( u16_newpos > fs_g_nav.u16_pos_filterlist )
00167 {
00168 if( !nav_filterlist_next() )
00169 break;
00170 }
00171 while( u16_newpos < fs_g_nav.u16_pos_filterlist )
00172 {
00173 if( !nav_filterlist_previous() )
00174 break;
00175 }
00176 return (u16_newpos == fs_g_nav.u16_pos_filterlist);
00177 }
00178
00179
00193 Bool nav_filterlist_findname( const FS_STRING sz_name , Bool b_match_case )
00194 {
00195 while( 1 )
00196 {
00197 if ( !nav_filterlist_next())
00198 return FALSE;
00199 if ( nav_file_name( sz_name , 0 , FS_NAME_CHECK , b_match_case ))
00200 return TRUE;
00201 }
00202 }
00203
00204
00219 U16 nav_filterlist_nb( fl_type_t fl_type, const FS_STRING sz_filterext )
00220 {
00221 U16 total=(U16)-1;
00222 while( !nav_filterlist_nb_ex( fl_type, sz_filterext, &total, 0 ) );
00223 return total;
00224 }
00225
00230 static Bool update_counter(U8 *counter)
00231 {
00232 if (*counter)
00233 (*counter)--;
00234 if (!*counter)
00235 return FALSE;
00236 return TRUE;
00237 }
00238
00257 Bool nav_filterlist_nb_ex( fl_type_t fl_type, const FS_STRING sz_filterext, U16* p_total, U8 retry )
00258 {
00259 static U16 u16_save_position;
00260 Bool b_is_dir;
00261
00262
00263 if( *p_total==(U16) -1 )
00264 {
00265 u16_save_position = fs_g_nav.u16_pos_filterlist;
00266
00267
00268 if ( !nav_filterlist_reset())
00269 return TRUE;
00270
00271 if (fl_type == FL_DIR)
00272 nav_filelist_single_enable(FS_DIR);
00273 else if (fl_type == FL_FILE)
00274 nav_filelist_single_enable(FS_FILE);
00275
00276 *p_total = 0;
00277 }
00278
00279
00280 while( nav_filelist_set( 0, FS_FIND_NEXT ) )
00281 {
00282 b_is_dir = nav_file_isdir();
00283
00284
00285 if (fl_type == FL_FILE && b_is_dir)
00286 {
00287 if (!update_counter(&retry))
00288 return FALSE;
00289 continue;
00290 }
00291
00292 if (fl_type == FL_DIR && !b_is_dir)
00293 {
00294 if (!update_counter(&retry))
00295 return FALSE;
00296 continue;
00297 }
00298
00299 if (!b_is_dir)
00300 {
00301
00302 if (!((sz_filterext)?nav_file_checkext(sz_filterext):nav_file_checkext(fs_g_nav.sz_filterext)))
00303 if (!update_counter(&retry))
00304 return FALSE;
00305 }
00306
00307 (*p_total)++;
00308 if (!update_counter(&retry))
00309 return FALSE;
00310 }
00311
00312 nav_filelist_single_disable();
00313
00314
00315 if ( u16_save_position != FS_NO_SEL )
00316 {
00317 nav_filterlist_reset();
00318 }else{
00319
00320 nav_filterlist_goto( u16_save_position );
00321 }
00322 return TRUE;
00323 }
00324
00325
00337 Bool nav_filterlist_mount( void )
00338 {
00339 fs_g_nav.u16_pos_filterlist = FS_NO_SEL;
00340 return nav_partition_mount();
00341 }
00342
00343
00349 Bool nav_filterlist_root( void )
00350 {
00351 fs_g_nav.u16_pos_filterlist = FS_NO_SEL;
00352 return nav_dir_root();
00353 }
00354
00355
00366 Bool nav_filterlist_cd( void )
00367 {
00368 fs_g_nav.u16_pos_filterlist = FS_NO_SEL;
00369 return nav_dir_cd();
00370 }
00371
00372
00383 Bool nav_filterlist_gotoparent( void )
00384 {
00385 U32 u32_cluster_old_dir;
00386
00387 if (!fat_check_mount_noopen())
00388 return FALSE;
00389
00390 if (0 == fs_g_nav.u32_cluster_sel_dir)
00391 {
00392 fs_g_status = FS_ERR_IS_ROOT;
00393 return FALSE;
00394 }
00395
00396
00397 fs_g_nav_fast.u16_entry_pos_sel_file = 1;
00398 if ( !fat_read_dir())
00399 return FALSE;
00400 fat_get_entry_info();
00401
00402 u32_cluster_old_dir = fs_g_nav.u32_cluster_sel_dir;
00403
00404
00405 fs_g_nav.u32_cluster_sel_dir = fs_g_nav_entry.u32_cluster;
00406
00407
00408 if( FALSE == nav_filterlist_reset())
00409 return FALSE;
00410 while( nav_filterlist_next() )
00411 {
00412 if (fs_g_nav_entry.u32_cluster == u32_cluster_old_dir)
00413 return TRUE;
00414 }
00415 fs_g_status = FS_ERR_FS;
00416 return FALSE;
00417 }
00418
00419
00432 Bool nav_filterlist_gotoindex( const Fs_index _MEM_TYPE_SLOW_ *index )
00433 {
00434 if( !nav_drive_set( index->u8_lun ))
00435 return FALSE;
00436 #if (FS_MULTI_PARTITION == ENABLED)
00437 if( !nav_partition_set(index->u8_partition))
00438 return FALSE;
00439 #endif
00440 if( !nav_partition_mount())
00441 return FALSE;
00442
00443
00444 fs_g_nav.u32_cluster_sel_dir = index->u32_cluster_sel_dir;
00445
00446
00447 if ( !nav_filterlist_reset() )
00448 return FALSE;
00449
00450
00451 while( fs_g_nav_fast.u16_entry_pos_sel_file != index->u16_entry_pos_sel_file )
00452 {
00453 if( !nav_filterlist_next() )
00454 {
00455 nav_filterlist_reset();
00456 return FALSE;
00457 }
00458 }
00459 return TRUE;
00460 }