00001
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
00047
00048
00049
00050
00051 #include "conf_explorer.h"
00052 #include "nav_automatic.h"
00053 #include "file.h"
00054 #include LIB_CTRLACCESS
00055 #include LIB_MEM
00056
00057
00058
00059
00060 Bool g_navauto_b_playlist;
00061 _MEM_TYPE_SLOW_ Navauto_mode g_navauto_exp_mode = NAVAUTO_MODE_DISKS;
00062 _MEM_TYPE_SLOW_ Navauto_rand g_navauto_rand = NAVAUTO_RAND_OFF;
00063 _MEM_TYPE_SLOW_ U16 g_navauto_u16_nb = 0;
00064 _MEM_TYPE_SLOW_ U16 g_navauto_u16_pos;
00065 _MEM_TYPE_SLOW_ U16 g_navauto_u16_dir_level;
00066 _MEM_TYPE_SLOW_ U16 g_navauto_u16_dir_level_root;
00067 _MEM_TYPE_SLOW_ FS_STRING g_navauto_filter;
00068 _MEM_TYPE_SLOW_ U16 g_navauto_u16_rand_pos;
00069 _MEM_TYPE_SLOW_ U8 g_navauto_rand_tab[NAVAUTO_MAX_RANGE_RAND];
00070
00073 #ifndef FS_NAV_AUTOMATIC_NBFILE
00074 # define FS_NAV_AUTOMATIC_NBFILE DISABLE
00075 #endif
00076
00077
00078
00079 typedef enum
00080 {
00081 NAVAUTO_MOV_EXPLORER_OK,
00082 NAVAUTO_MOV_EXPLORER_ERROR,
00083 NAVAUTO_MOV_EXPLORER_RECURSIVE
00084 } navauto_mov_explorer_rec_t;
00085
00086 static U8 navauto_mov_explorer_rec(Bool b_direction, navauto_mov_options_t options);
00087 static navauto_mov_explorer_rec_t navauto_mov_explorer_select_limit_dir_cur_folder(Bool b_direction);
00088 static navauto_mov_explorer_rec_t navauto_mov_explorer_select_limit_file_cur_folder(Bool b_direction);
00089 static navauto_mov_explorer_rec_t navauto_mov_explorer_updir(Bool b_direction);
00090 static navauto_mov_explorer_rec_t navauto_mov_explorer_limit(Bool b_direction);
00091
00092
00093 typedef navauto_mov_explorer_rec_t (*navauto_mov_explorer_process_fct_t) (Bool);
00094
00102 static const navauto_mov_explorer_process_fct_t new_dir_process_fct[] = {
00103 #ifdef NAV_AUTO_FILE_IN_FIRST
00104 navauto_mov_explorer_select_limit_file_cur_folder,
00105 navauto_mov_explorer_select_limit_dir_cur_folder
00106 #else
00107 navauto_mov_explorer_select_limit_dir_cur_folder,
00108 navauto_mov_explorer_select_limit_file_cur_folder
00109 #endif
00110 };
00117 static const navauto_mov_explorer_process_fct_t is_dir_process_fct[2] = {
00118 #ifdef NAV_AUTO_FILE_IN_FIRST
00119 navauto_mov_explorer_select_limit_file_cur_folder,
00120 navauto_mov_explorer_updir
00121 #else
00122 navauto_mov_explorer_updir,
00123 navauto_mov_explorer_select_limit_file_cur_folder
00124 #endif
00125 };
00132 static const navauto_mov_explorer_process_fct_t is_file_process_fct[2] = {
00133 #ifdef NAV_AUTO_FILE_IN_FIRST
00134 navauto_mov_explorer_updir,
00135 navauto_mov_explorer_select_limit_dir_cur_folder
00136 #else
00137 navauto_mov_explorer_select_limit_dir_cur_folder,
00138 navauto_mov_explorer_updir
00139 #endif
00140 };
00146 static const navauto_mov_explorer_process_fct_t limit_process_fct[2] = {
00147 navauto_mov_explorer_limit,
00148 navauto_mov_explorer_limit
00149 };
00150
00151 static Navauto_mov_bitfield_status bitfield_status;
00152
00153 void navauto_rand_init ( void );
00154 void navauto_mov_explorer_reset ( void );
00155 Navauto_mov_state navauto_mov_explorer ( Bool b_direction, navauto_mov_options_t options );
00156 Navauto_mov_state navauto_mov_playlist ( Bool b_direction );
00157
00158
00167 Navauto_mode navauto_getmode( void )
00168 {
00169 return g_navauto_exp_mode;
00170 }
00171
00172
00185 Bool navauto_setmode( Navauto_mode exp_mode )
00186 {
00187 if( g_navauto_exp_mode == exp_mode )
00188 return TRUE;
00189 g_navauto_exp_mode = exp_mode;
00190 if( g_navauto_b_playlist )
00191 return TRUE;
00192 return navauto_open( FALSE , 0 );
00193 }
00194
00195
00200 Navauto_rand navauto_getrand( void )
00201 {
00202 return g_navauto_rand;
00203 }
00204
00205
00210 void navauto_setrand( Navauto_rand rand )
00211 {
00212 g_navauto_rand = rand;
00213 navauto_rand_init();
00214
00215 if( g_navauto_u16_pos <= (NAVAUTO_MAX_RANGE_RAND*8) )
00216 {
00217
00218 U8 u8_pos_rand = g_navauto_u16_pos-1;
00219 g_navauto_rand_tab[u8_pos_rand/8] |= 1<<(u8_pos_rand%8);
00220 }
00221 }
00222
00223
00226 void navauto_rand_init( void )
00227 {
00228
00229 memset( g_navauto_rand_tab , 0 , NAVAUTO_MAX_RANGE_RAND );
00230 g_navauto_u16_rand_pos = 0;
00231 }
00232
00233
00236 U16 navauto_rand_choose( void )
00237 {
00238 U16 u16_i;
00239 U16 u16_nb_file_rand;
00240 U16 u16_pos_file_rand;
00241
00242 navauto_rand_choose_restart:
00243 if( g_navauto_u16_nb == g_navauto_u16_rand_pos )
00244 return 0;
00245
00246
00247 if( (g_navauto_u16_nb-g_navauto_u16_rand_pos) < (NAVAUTO_MAX_RANGE_RAND*8) )
00248 u16_nb_file_rand = g_navauto_u16_nb-g_navauto_u16_rand_pos;
00249 else
00250 u16_nb_file_rand = NAVAUTO_MAX_RANGE_RAND*8;
00251
00252
00253 u16_i = 0;
00254 while( 1 )
00255 {
00256 if( u16_nb_file_rand == u16_i )
00257 {
00258
00259 memset( g_navauto_rand_tab , 0 , NAVAUTO_MAX_RANGE_RAND );
00260 g_navauto_u16_rand_pos += u16_nb_file_rand;
00261 goto navauto_rand_choose_restart;
00262 }
00263 if( 0 == (g_navauto_rand_tab[u16_i/8] & (1<<(u16_i%8))) )
00264 break;
00265 u16_i++;
00266 }
00267
00268
00269 NAVAUTO_GET_RAND(u16_i);
00270 if( u16_i == 0 ) u16_i = 1;
00271
00272
00273 u16_pos_file_rand = g_navauto_u16_pos-g_navauto_u16_rand_pos-1;
00274
00275
00276 while( 0 != u16_i )
00277 {
00278 u16_pos_file_rand++;
00279 if( u16_pos_file_rand >= u16_nb_file_rand )
00280 u16_pos_file_rand = 0;
00281 if( 0 == (g_navauto_rand_tab[u16_pos_file_rand/8] & (1<<(u16_pos_file_rand%8))) )
00282 u16_i--;
00283 }
00284
00285 g_navauto_rand_tab[u16_pos_file_rand/8] |= 1<<(u16_pos_file_rand%8);
00286 return (g_navauto_u16_rand_pos+u16_pos_file_rand+1);
00287 }
00288
00289
00298 void navauto_init( const FS_STRING sz_filterext )
00299 {
00300 g_navauto_filter = sz_filterext;
00301 g_navauto_u16_dir_level_root = 0;
00302 g_navauto_u16_nb = 0;
00303 }
00304
00305
00315 Bool navauto_open( Bool b_playlist , U16 pos )
00316 {
00317 Navauto_mov_state state;
00318
00319 g_navauto_b_playlist = b_playlist;
00320 g_navauto_u16_dir_level_root = 0;
00321 g_navauto_u16_nb = 0;
00322
00323 if( b_playlist )
00324 {
00325 g_navauto_u16_pos = pos;
00326 if( !pl_main_open(FALSE) )
00327 return FALSE;
00328 g_navauto_u16_nb = pl_nav_getnbfile();
00329 if( 0 == g_navauto_u16_nb )
00330 return FALSE;
00331 if( NAVAUTO_RAND_OFF == navauto_getrand() )
00332 {
00333 if( pl_nav_setpos( g_navauto_u16_pos ))
00334 {
00335 if( nav_filelist_validpos() )
00336 return TRUE;
00337 }
00338 }else{
00339 navauto_rand_init();
00340 }
00341
00342 g_navauto_u16_pos = 0;
00343 }
00344 else
00345 {
00346 #if( FS_NAV_AUTOMATIC_NBFILE == ENABLE )
00347 Fs_index index;
00348 Fs_index index2;
00349 Navauto_rand rand_mode;
00350 U16 u16_current_pos=0;
00351
00352 index.u8_lun = 0xFF;
00353 g_navauto_u16_dir_level = pos;
00354
00355 rand_mode = navauto_getrand();
00356 navauto_setrand( NAVAUTO_RAND_OFF );
00357
00358
00359 if( !nav_file_checkext( g_navauto_filter ))
00360 {
00361
00362 if( !nav_filelist_set( 0 , FS_FIND_PREV ) )
00363 nav_filelist_reset();
00364 state = navauto_mov_explorer(FS_FIND_NEXT, NAVAUTO_MOV_OPTS_NONE);
00365 if((NAVAUTO_MOV_OK_LOOP != state.status)
00366 && (NAVAUTO_MOV_OK != state.status) )
00367 {
00368 navauto_setrand(rand_mode);
00369 return FALSE;
00370 }
00371 }
00372 index = nav_getindex();
00373
00374
00375 navauto_mov_explorer_reset();
00376
00377
00378 while( navauto_mov_explorer( FS_FIND_NEXT, NAVAUTO_MOV_OPTS_NONE ).status == NAVAUTO_MOV_OK )
00379 {
00380 index2 = nav_getindex();
00381
00382 if( (index.u8_lun == index2.u8_lun)
00383 && (index.u32_cluster_sel_dir == index2.u32_cluster_sel_dir)
00384 && (index.u16_entry_pos_sel_file == index2.u16_entry_pos_sel_file) )
00385 {
00386 u16_current_pos = g_navauto_u16_pos;
00387 g_navauto_u16_dir_level_root = g_navauto_u16_dir_level;
00388 }
00389 }
00390
00391 navauto_setrand(rand_mode);
00392 if( 0 == g_navauto_u16_nb )
00393 return FALSE;
00394
00395
00396 if( NAVAUTO_RAND_OFF == navauto_getrand() )
00397 {
00398 if( 0xFF != index.u8_lun )
00399 {
00400
00401 nav_gotoindex( &index );
00402 g_navauto_u16_dir_level = g_navauto_u16_dir_level_root;
00403 g_navauto_u16_pos = u16_current_pos;
00404 }
00405
00406 return TRUE;
00407 }else{
00408 navauto_rand_init();
00409 }
00410 #else
00411 Fs_index index;
00412 Navauto_rand rand_mode;
00413
00414 rand_mode = navauto_getrand();
00415 navauto_setrand(NAVAUTO_RAND_OFF);
00416
00417
00418 if( !nav_file_checkext( g_navauto_filter ))
00419 {
00420
00421 if( !nav_filelist_set( 0 , FS_FIND_PREV ) )
00422 nav_filelist_reset();
00423 state = navauto_mov_explorer(FS_FIND_NEXT, NAVAUTO_MOV_OPTS_NONE);
00424 if((NAVAUTO_MOV_OK_LOOP != state.status)
00425 && (NAVAUTO_MOV_OK != state.status) )
00426 {
00427 navauto_setrand(rand_mode);
00428 return FALSE;
00429 }
00430 }
00431 index = nav_getindex();
00432
00433 navauto_setrand(rand_mode);
00434
00435 navauto_mov_explorer_reset();
00436
00437 g_navauto_u16_dir_level = 0;
00438 while(nav_dir_gotoparent())
00439 g_navauto_u16_dir_level++;
00440 g_navauto_u16_dir_level_root = g_navauto_u16_dir_level;
00441
00442
00443 nav_gotoindex(&index);
00444
00445 g_navauto_u16_nb = 0xFFFF;
00446
00447 if( NAVAUTO_RAND_OFF == navauto_getrand() )
00448 navauto_rand_init();
00449
00450 if( nav_file_checkext( g_navauto_filter ))
00451 {
00452
00453 g_navauto_u16_pos = 1;
00454 return TRUE;
00455 }
00456 #endif
00457 }
00458
00459 state = navauto_mov(FS_FIND_NEXT, NAVAUTO_MOV_OPTS_NONE);
00460 if((NAVAUTO_MOV_OK_LOOP != state.status)
00461 && (NAVAUTO_MOV_OK != state.status) )
00462 return FALSE;
00463 return TRUE;
00464 }
00465
00466
00473 void navauto_mov_explorer_reset( void )
00474 {
00475 g_navauto_u16_nb = 0;
00476
00477 switch( g_navauto_exp_mode )
00478 {
00479 case NAVAUTO_MODE_DISKS :
00480 g_navauto_u16_dir_level = 0;
00481 g_navauto_u16_dir_level_root = 0;
00482 nav_drive_set(0);
00483 nav_dir_root();
00484 break;
00485
00486 case NAVAUTO_MODE_DISK :
00487 g_navauto_u16_dir_level = 0;
00488 g_navauto_u16_dir_level_root = 0;
00489 nav_dir_root();
00490 break;
00491
00492 default:
00493 g_navauto_u16_dir_level = 0;
00494 g_navauto_u16_dir_level_root = 0;
00495 nav_dir_root();
00496
00497 break;
00498 }
00499
00500
00501 g_navauto_u16_pos = (U16) -1;
00502 }
00503
00504
00516 U16 navauto_close( void )
00517 {
00518 if( g_navauto_b_playlist )
00519 {
00520 pl_main_close();
00521 return g_navauto_u16_pos;
00522 }
00523 return g_navauto_u16_dir_level;
00524 }
00525
00526
00529 U16 navauto_getnb( void )
00530 {
00531 return g_navauto_u16_nb;
00532 }
00533
00536 U16 navauto_getpos( void )
00537 {
00538 return g_navauto_u16_pos;
00539 }
00540
00541
00548 Bool navauto_setpos( U16 u16_pos )
00549 {
00550 Bool b_direction;
00551 Navauto_rand rand_mode;
00552 Navauto_mov_state state;
00553
00554 rand_mode = navauto_getrand();
00555 state.status = NAVAUTO_MOV_OK;
00556
00557 while( (u16_pos != g_navauto_u16_pos ) )
00558 {
00559 b_direction = ( u16_pos > g_navauto_u16_pos )? FS_FIND_NEXT : FS_FIND_PREV;
00560 state = navauto_mov( b_direction, NAVAUTO_MOV_OPTS_NONE );
00561 }
00562
00563 navauto_setrand(rand_mode);
00564
00565 return (NAVAUTO_MOV_OK == state.status);
00566 }
00567
00568
00580 Navauto_mov_state navauto_mov( Bool b_direction, navauto_mov_options_t options )
00581 {
00582 if( g_navauto_b_playlist )
00583 return navauto_mov_playlist( b_direction );
00584 else
00585 return navauto_mov_explorer( b_direction, options );
00586 }
00587
00588
00589
00590
00598 static navauto_mov_explorer_rec_t navauto_mov_explorer_limit(Bool b_direction)
00599 {
00600
00601 nav_filelist_reset();
00602
00603 while(navauto_mov_explorer_updir(b_direction) != NAVAUTO_MOV_EXPLORER_ERROR);
00604
00605 g_navauto_u16_dir_level = g_navauto_u16_dir_level_root;
00606
00607 return NAVAUTO_MOV_EXPLORER_RECURSIVE;
00608 }
00616 static navauto_mov_explorer_rec_t navauto_mov_explorer_select_limit_file_cur_folder(Bool b_direction)
00617 {
00618 if ((b_direction == FS_FIND_NEXT)?nav_filelist_first(FS_FILE):nav_filelist_last(FS_FILE))
00619 {
00620
00621
00622 while(!nav_file_checkext(g_navauto_filter))
00623 {
00624 if (!nav_filelist_set(0, b_direction))
00625 return NAVAUTO_MOV_EXPLORER_ERROR;
00626 }
00627 return NAVAUTO_MOV_EXPLORER_OK;
00628 }
00629 else
00630 return NAVAUTO_MOV_EXPLORER_ERROR;
00631 }
00632
00640 static navauto_mov_explorer_rec_t navauto_mov_explorer_select_limit_dir_cur_folder(Bool b_direction)
00641 {
00642 if (!((b_direction == FS_FIND_NEXT)?nav_filelist_first(FS_DIR):nav_filelist_last(FS_DIR)))
00643 return NAVAUTO_MOV_EXPLORER_ERROR;
00644
00645
00646 g_navauto_u16_dir_level++;
00647
00648 nav_dir_cd();
00649
00650
00651 bitfield_status.folder_change = 1;
00652
00653 return NAVAUTO_MOV_EXPLORER_RECURSIVE;
00654 }
00655
00662 static navauto_mov_explorer_rec_t navauto_mov_explorer_updir(Bool b_direction)
00663 {
00664
00665 if (g_navauto_exp_mode == NAVAUTO_MODE_DIRONLY)
00666 return NAVAUTO_MOV_EXPLORER_ERROR;
00667
00668
00669 if (g_navauto_exp_mode == NAVAUTO_MODE_DIRSUB)
00670 {
00671
00672 if (g_navauto_u16_dir_level <= g_navauto_u16_dir_level_root)
00673 return NAVAUTO_MOV_EXPLORER_ERROR;
00674 }
00675
00676 if (nav_dir_gotoparent())
00677 {
00678
00679 bitfield_status.folder_change = 1;
00680
00681 g_navauto_u16_dir_level--;
00682 return NAVAUTO_MOV_EXPLORER_RECURSIVE;
00683 }
00684 else
00685 return NAVAUTO_MOV_EXPLORER_ERROR;
00686 }
00687
00688 static __inline__ U8 navauto_mov_ok_loop(Bool b_direction, navauto_mov_options_t options)
00689 {
00690 Bool b_ok_loop = FALSE;
00691
00692
00693 if (g_navauto_exp_mode == NAVAUTO_MODE_DISKS)
00694 {
00695
00696 do
00697 {
00698 if (b_direction == FS_FIND_NEXT)
00699 {
00700
00701 if (!nav_drive_set(nav_drive_get() + 1))
00702 {
00703 nav_drive_set(0);
00704 b_ok_loop = TRUE;
00705 }
00706 }
00707 else
00708 {
00709
00710 if (!nav_drive_set(nav_drive_get() - 1))
00711 {
00712 nav_drive_set(nav_drive_nb() - 1);
00713 b_ok_loop = TRUE;
00714 }
00715 }
00716 }while(!nav_partition_mount());
00717
00718
00719 if (b_ok_loop)
00720 {
00721 navauto_mov_explorer_rec(b_direction, options);
00722 return NAVAUTO_MOV_OK_LOOP;
00723 }
00724
00725
00726 return navauto_mov_explorer_rec(b_direction, options);
00727 }
00728
00729 return NAVAUTO_MOV_OK_LOOP;
00730 }
00731
00732 static __inline__ U8 navauto_mov_explorer_new_dir(Bool b_direction, navauto_mov_options_t options)
00733 {
00734 int i;
00735
00736 i = (b_direction == FS_FIND_NEXT)?0:(sizeof(new_dir_process_fct)/sizeof(navauto_mov_explorer_process_fct_t)-1);
00737 while(i >= 0 && i < sizeof(new_dir_process_fct)/sizeof(navauto_mov_explorer_process_fct_t))
00738 {
00739 switch(new_dir_process_fct[i](b_direction))
00740 {
00741 case NAVAUTO_MOV_EXPLORER_RECURSIVE:
00742 return navauto_mov_explorer_rec(b_direction, options);
00743 case NAVAUTO_MOV_EXPLORER_OK:
00744 return NAVAUTO_MOV_OK;
00745 default:
00746 break;
00747 }
00748
00749 i += (b_direction == FS_FIND_NEXT)?(1):(-1);
00750 }
00751
00752
00753
00754 if (navauto_mov_explorer_updir(b_direction) == NAVAUTO_MOV_EXPLORER_RECURSIVE)
00755 return navauto_mov_explorer_rec(b_direction, options);
00756
00757
00758 return NAVAUTO_MOV_EMPTY;
00759 }
00760
00761 static __inline__ U8 navauto_mov_explorer_is_dir(Bool b_direction, navauto_mov_options_t options)
00762 {
00763 Bool status;
00764
00765
00766 if ((status = nav_filelist_set(0, b_direction)))
00767 status = nav_file_isdir();
00768
00769
00770 if (!status)
00771 {
00772 switch(is_dir_process_fct[(b_direction == FS_FIND_NEXT)?1:0](b_direction))
00773 {
00774 case NAVAUTO_MOV_EXPLORER_RECURSIVE:
00775 return navauto_mov_explorer_rec(b_direction, options);
00776 case NAVAUTO_MOV_EXPLORER_OK:
00777 return NAVAUTO_MOV_OK;
00778 default:
00779 break;
00780 }
00781 }
00782 else
00783 {
00784 g_navauto_u16_dir_level++;
00785
00786 nav_dir_cd();
00787
00788 bitfield_status.folder_change = 1;
00789
00790 return navauto_mov_explorer_rec(b_direction, options);
00791 }
00792
00793
00794
00795 if (navauto_mov_explorer_updir(b_direction) == NAVAUTO_MOV_EXPLORER_RECURSIVE)
00796 return navauto_mov_explorer_rec(b_direction, options);
00797
00798 return navauto_mov_ok_loop(b_direction, options);
00799 }
00800
00801 static __inline__ U8 navauto_mov_explorer_is_file(Bool b_direction, navauto_mov_options_t options)
00802 {
00803
00804 while(nav_filelist_set(0, b_direction))
00805 {
00806 if (nav_file_isdir())
00807 break;
00808 if (!nav_file_checkext(g_navauto_filter))
00809 continue;
00810 return NAVAUTO_MOV_OK;
00811 }
00812
00813
00814 if ( (options & NAVAUTO_MOV_OPTS_STAY_CURRENT_DIR)
00815 || (g_navauto_exp_mode == NAVAUTO_MODE_DIRONLY))
00816 {
00817
00818 while(nav_filelist_set(0, !b_direction))
00819 {
00820 if (nav_file_isdir())
00821 break;
00822 if (!nav_file_checkext(g_navauto_filter))
00823 continue;
00824 g_navauto_u16_pos += (!b_direction == FS_FIND_NEXT)?(1):(-1);
00825 }
00826
00827 if (navauto_mov_explorer_select_limit_file_cur_folder(b_direction) == NAVAUTO_MOV_EXPLORER_OK)
00828 {
00829 if (options & NAVAUTO_MOV_OPTS_STAY_CURRENT_DIR)
00830 return NAVAUTO_MOV_OK;
00831 else
00832 return NAVAUTO_MOV_OK_LOOP;
00833 }
00834 return NAVAUTO_MOV_EMPTY;
00835 }
00836
00837
00838 switch(is_file_process_fct[(b_direction == FS_FIND_NEXT)?1:0](b_direction))
00839 {
00840 case NAVAUTO_MOV_EXPLORER_RECURSIVE:
00841 return navauto_mov_explorer_rec(b_direction, options);
00842 case NAVAUTO_MOV_EXPLORER_OK:
00843 return NAVAUTO_MOV_OK;
00844 default:
00845 break;
00846 }
00847
00848
00849
00850 if (navauto_mov_explorer_updir(b_direction) == NAVAUTO_MOV_EXPLORER_RECURSIVE)
00851 return navauto_mov_explorer_rec(b_direction, options);
00852
00853 return navauto_mov_ok_loop(b_direction, options);
00854 }
00855
00856
00857
00865 static U8 navauto_mov_explorer_rec( Bool b_direction, navauto_mov_options_t options )
00866 {
00867
00868 if (!nav_filelist_validpos())
00869 return navauto_mov_explorer_new_dir(b_direction, options);
00870
00871
00872 if (nav_file_isdir())
00873 return navauto_mov_explorer_is_dir(b_direction, options);
00874 else
00875 return navauto_mov_explorer_is_file(b_direction, options);
00876 }
00877
00890 Navauto_mov_state navauto_mov_explorer( Bool b_direction, navauto_mov_options_t options )
00891 {
00892 Navauto_mov_state state;
00893 U16 u16_mov_pos = 0;
00894 size_t nb_loops = 1;
00895
00896
00897 memset(&bitfield_status, 0, sizeof(bitfield_status));
00898
00899
00900 if (g_navauto_rand == NAVAUTO_RAND_ON)
00901 {
00902 u16_mov_pos = navauto_rand_choose();
00903 if (!u16_mov_pos)
00904 {
00905 navauto_rand_init();
00906
00907 u16_mov_pos = navauto_rand_choose();
00908 if(!u16_mov_pos)
00909 {
00910 state.bitfield.all = bitfield_status.all;
00911 state.status = NAVAUTO_MOV_EMPTY;
00912 return state;
00913 }
00914 }
00915
00916 b_direction = (u16_mov_pos > g_navauto_u16_pos)?FS_FIND_NEXT:FS_FIND_PREV;
00917 nb_loops = (u16_mov_pos > g_navauto_u16_pos)?(u16_mov_pos-g_navauto_u16_pos):(g_navauto_u16_pos-u16_mov_pos);
00918
00919
00920
00921 if ( (options & NAVAUTO_MOV_OPTS_STAY_CURRENT_DIR)
00922 || (g_navauto_exp_mode == NAVAUTO_MODE_DIRONLY))
00923 nb_loops %= nav_filelist_nb(FS_FILE);
00924
00925
00926
00927 u16_mov_pos = g_navauto_u16_pos;
00928 }
00929
00930
00931 while(nb_loops--)
00932 {
00933
00934 state.status = navauto_mov_explorer_rec(b_direction, options);
00935
00936 switch(state.status)
00937 {
00938
00939
00940 case NAVAUTO_MOV_OK_LOOP:
00941
00942
00943 if (b_direction == FS_FIND_NEXT)
00944 {
00945 g_navauto_u16_nb = g_navauto_u16_pos + 1;
00946 g_navauto_u16_pos = 0;
00947 }
00948 else
00949 g_navauto_u16_pos = g_navauto_u16_nb - 1;
00950
00951
00952
00953
00954 switch(limit_process_fct[(b_direction == FS_FIND_NEXT)?1:0](b_direction))
00955 {
00956
00957 case NAVAUTO_MOV_EXPLORER_RECURSIVE:
00958
00959
00960 if (navauto_mov_explorer_rec(b_direction, options) == NAVAUTO_MOV_OK_LOOP)
00961 {
00962 state.bitfield.all = bitfield_status.all;
00963 state.status = NAVAUTO_MOV_EMPTY;
00964 return state;
00965 }
00966 break;
00967
00968 default:
00969 break;
00970 }
00971
00972 state.bitfield.all = bitfield_status.all;
00973 state.status = NAVAUTO_MOV_OK_LOOP;
00974 return state;
00975
00976
00977 case NAVAUTO_MOV_OK:
00978
00979 g_navauto_u16_pos += (b_direction == FS_FIND_NEXT)?(1):(-1);
00980
00981 if (g_navauto_rand == NAVAUTO_RAND_ON && u16_mov_pos == g_navauto_u16_pos && !nb_loops)
00982 {
00983 state.status = navauto_mov_explorer_rec(b_direction, options);
00984 state.bitfield.all = bitfield_status.all;
00985 return state;
00986 }
00987 break;
00988
00989 default:
00990 state.bitfield.all = bitfield_status.all;
00991 return state;
00992 }
00993 }
00994
00995 state.status = NAVAUTO_MOV_OK;
00996 state.bitfield.all = bitfield_status.all;
00997 return state;
00998 }
00999
01010 Navauto_mov_state navauto_mov_playlist( Bool b_direction )
01011 {
01012 Bool b_endof_loop;
01013 b_endof_loop = FALSE;
01014 Navauto_mov_state state;
01015
01016 state.bitfield.all = 0;
01017 while( 1 )
01018 {
01019 if( NAVAUTO_RAND_ON == g_navauto_rand )
01020 {
01021 g_navauto_u16_pos = navauto_rand_choose();
01022 if( 0 == g_navauto_u16_pos )
01023 {
01024
01025 if( b_endof_loop )
01026 {
01027 state.status = NAVAUTO_MOV_DISKERROR;
01028 return state;
01029 }
01030 b_endof_loop = TRUE;
01031 navauto_rand_init();
01032 g_navauto_u16_pos = navauto_rand_choose();
01033 }
01034 pl_nav_setpos( g_navauto_u16_pos );
01035 }
01036 else
01037 {
01038 g_navauto_u16_pos += (FS_FIND_NEXT==b_direction)? 1 : -1;
01039 if( !pl_nav_setpos( g_navauto_u16_pos ) )
01040 {
01041
01042 if( b_endof_loop )
01043 {
01044 state.status = NAVAUTO_MOV_DISKERROR;
01045 return state;
01046 }
01047 b_endof_loop = TRUE;
01048 if( FS_FIND_NEXT == b_direction )
01049 {
01050 g_navauto_u16_pos = 1-1;
01051 }else{
01052 g_navauto_u16_pos = pl_nav_getnbfile()+1;
01053 }
01054 }
01055 }
01056 if( nav_filelist_validpos() )
01057 break;
01058
01059 }
01060 g_navauto_u16_pos = pl_nav_getpos();
01061 if( b_endof_loop )
01062 {
01063 state.status = NAVAUTO_MOV_OK_LOOP;
01064 return state;
01065 }
01066 state.status = NAVAUTO_MOV_OK;
01067 return state;
01068 }
01069
01070
01071