00001
00014
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
00047 #include <string.h>
00048 #include "conf_explorer.h"
00049 #include "navigation.h"
00050 #include "file.h"
00051 #include "reader_txt.h"
00052 #include "play_list.h"
00053
00054
00055
00056 #ifndef PL_READONLY
00057 # define PL_READONLY DISABLED
00058 #endif
00059
00060 #if( PL_READONLY == DISABLED )
00061 # error the modification of play list file is not available
00062 #endif
00063
00064 #if defined(PLAYLIST_USE_NON_BLOCKING_FUNCTION_SET) && \
00065 PLAYLIST_USE_NON_BLOCKING_FUNCTION_SET == ENABLED
00066 #include "audio_interface.h"
00067 #if !defined(AI_ASYNC_STACK_NB_ELEMENTS) || AI_ASYNC_STACK_NB_ELEMENTS < 1
00068 #error This version of the play_list.c file needs a context that can support \
00069 at least 1 element. Therefore, AI_ASYNC_STACK_NB_ELEMENTS must be defined with \
00070 a value greater or equals to 1.
00071 #endif
00072 #endif
00073
00074
00075
00076
00078 typedef enum {
00079 E_PL_M3U,
00080 E_PL_PLS,
00081 E_PL_SMP
00082 } E_pl_type;
00083
00084
00085 Bool pl_g_list_is_open = FALSE;
00086 _MEM_TYPE_SLOW_ E_pl_type pl_g_list_type;
00087 _MEM_TYPE_SLOW_ U16 pl_g_u16_list_size = 0;
00088 _MEM_TYPE_SLOW_ U16 pl_g_u16_list_sel = 0;
00089
00090 #if( PL_READONLY == DISABLED )
00091 Bool pl_g_list_is_modify;
00092 Bool pl_g_list_is_readonly;
00093 Bool pl_g_list_undo;
00094 _MEM_TYPE_SLOW_ Fs_index copyfile_index;
00095 #endif
00096
00097
00098
00099
00100 Bool pl_main_modify ( void );
00101
00102
00103
00104
00105
00110 Bool pl_main_isopen( void )
00111 {
00112 fs_g_status = FS_ERR_PL_NOT_OPEN;
00113 return pl_g_list_is_open;
00114 }
00115
00116
00121 Bool pl_main_ismodify( void )
00122 {
00123 #if( PL_READONLY == DISABLED )
00124 return pl_g_list_is_modify;
00125 #else
00126 return FALSE;
00127 #endif
00128 }
00129
00130
00131 #if( PL_READONLY == DISABLED )
00140 Bool pl_main_new( const FS_STRING sz_name , Bool b_undo )
00141 {
00142 if( pl_main_isopen() )
00143 return FALSE;
00144
00145
00146 if( !reader_txt_new( sz_name, UNI_TYPE_UTF16BE ))
00147 return FALSE;
00148 reader_txt_close();
00149
00150
00151 return pl_main_open( b_undo );
00152 }
00153 #endif
00154
00155
00163 Bool pl_main_open( Bool b_undo )
00164 {
00165 U8 nav_id_save;
00166
00167 if( pl_main_isopen() )
00168 return FALSE;
00169
00170
00171 nav_id_save = nav_get();
00172 nav_copy( FS_NAV_ID_PLAYLIST );
00173 nav_select( FS_NAV_ID_PLAYLIST );
00174
00175
00176 if( nav_file_checkext("m3u") )
00177 {
00178 pl_g_list_type = E_PL_M3U;
00179 }else
00180 if( nav_file_checkext("pls") )
00181 {
00182 pl_g_list_type = E_PL_PLS;
00183 }else
00184 if( nav_file_checkext("smp") )
00185 {
00186 pl_g_list_type = E_PL_SMP;
00187 }else
00188 goto pl_main_open_end;
00189
00190
00191 #if( PL_READONLY == DISABLED )
00192 pl_g_list_undo = b_undo;
00193 pl_g_list_is_modify = FALSE;
00194 pl_g_list_is_readonly = nav_file_isreadonly();
00195 if( pl_g_list_is_readonly )
00196 {
00197 if( !reader_txt_open( TRUE ))
00198 goto pl_main_open_end;
00199 }else{
00200 if( !reader_txt_open( FALSE ))
00201 goto pl_main_open_end;
00202 }
00203 #else
00204 if( !reader_txt_open( TRUE ))
00205 goto pl_main_open_end;
00206 #endif
00207
00208
00209 pl_g_u16_list_size = 0;
00210 while( 0 == file_eof() )
00211 {
00212 if( pl_main_readline(PL_MAIN_READLINE_OPT_CHECKLINE,0,NULL,NULL) )
00213 pl_g_u16_list_size++;
00214 }
00215
00216
00217 reader_txt_beg();
00218
00219 pl_g_u16_list_sel = 0;
00220 pl_g_list_is_open = TRUE;
00221 nav_select( nav_id_save );
00222 nav_filelist_reset();
00223
00224 pl_main_open_end:
00225 nav_select( nav_id_save );
00226 return pl_g_list_is_open;
00227 }
00228
00229
00235 #if( PL_READONLY == DISABLED )
00236 Bool pl_main_save( void )
00237 {
00238 _MEM_TYPE_SLOW_ Fs_index index;
00239 U8 nav_id_save;
00240 U16 u16_pos;
00241
00242
00243 if( !pl_main_isopen() )
00244 return FALSE;
00245 if( !pl_g_list_is_modify )
00246 return TRUE;
00247 pl_g_list_is_modify = FALSE;
00248
00249
00250 if( !pl_g_list_undo )
00251 return TRUE;
00252
00253
00254 nav_id_save = nav_get();
00255 nav_select( FS_NAV_ID_PLAYLIST );
00256 u16_pos = pl_g_u16_list_sel;
00257 file_close();
00258 index = nav_getindex();
00259 pl_g_list_is_open = FALSE;
00260 if( nav_gotoindex( ©file_index ) )
00261 nav_file_del( TRUE );
00262 nav_gotoindex( &index );
00263 pl_main_open( TRUE );
00264 pl_nav_setpos(u16_pos);
00265 nav_select( nav_id_save );
00266
00267 return TRUE;
00268 }
00269 #endif
00270
00271
00277 Bool pl_main_close( void )
00278 {
00279 _MEM_TYPE_SLOW_ Fs_index index;
00280 U8 nav_id_save;
00281
00282 if( !pl_main_isopen() )
00283 return FALSE;
00284
00285
00286 nav_id_save = nav_get();
00287 nav_select( FS_NAV_ID_PLAYLIST );
00288 file_close();
00289
00290 #if( PL_READONLY == DISABLED )
00291 if( pl_g_list_is_modify )
00292 {
00293 if( pl_g_list_undo )
00294 {
00295 U16 size_name;
00296 FS_STRING sz_name;
00297
00298
00299
00300 nav_string_length_enable();
00301 nav_file_name( (FS_STRING)&size_name, 1, FS_NAME_GET, FALSE );
00302 nav_string_length_disable();
00303 sz_name = PLAYLIST_BUF_ALLOC( size_name* (Is_unicode? 2 : 1 ) );
00304 if( NULL != sz_name )
00305 {
00306 if( nav_file_name( sz_name, size_name, FS_NAME_GET, FALSE ) )
00307 {
00308
00309 if( nav_file_del( TRUE ) )
00310 {
00311 nav_gotoindex( ©file_index );
00312 nav_file_rename( sz_name );
00313 }
00314 }
00315 PLAYLIST_BUF_FREE( sz_name );
00316 }
00317 }
00318 }
00319 #endif
00320
00321
00322 index = nav_getindex();
00323 nav_select( nav_id_save );
00324 nav_gotoindex( &index );
00325 pl_g_list_is_open = FALSE;
00326 return TRUE;
00327 }
00328
00329
00330 #if( PL_READONLY == DISABLED )
00336 Bool pl_main_modify( void )
00337 {
00338 _MEM_TYPE_SLOW_ U8 name_copyfile[]="~copy.m3u";
00339 _MEM_TYPE_SLOW_ Fs_index index;
00340 U8 nav_id_save;
00341 U16 u16_pos;
00342 U8 status;
00343 Bool b_copy_finish = FALSE;
00344
00345 if( !pl_main_isopen() )
00346 return FALSE;
00347 if( pl_g_list_is_modify )
00348 return TRUE;
00349
00350 fs_g_status = FS_ERR_PL_READ_ONLY;
00351 if( pl_g_list_is_readonly )
00352 return FALSE;
00353 if( !pl_g_list_undo )
00354 {
00355 pl_g_list_is_modify = TRUE;
00356 return TRUE;
00357 }
00358
00359
00360 nav_id_save = nav_get();
00361 nav_select( FS_NAV_ID_PLAYLIST );
00362 u16_pos = pl_g_u16_list_sel;
00363 file_close();
00364 pl_g_list_is_open = FALSE;
00365 index = nav_getindex();
00366
00367
00368 #if( (FS_ASCII == ENABLED) && (FS_UNICODE == ENABLED) )
00369 nav_string_ascii();
00370 #endif
00371 if( !nav_file_copy())
00372 goto pl_main_modify_end;
00373 if( !nav_file_paste_start( name_copyfile ) )
00374 {
00375 if( FS_ERR_FILE_EXIST != fs_g_status)
00376 goto pl_main_modify_end;
00377
00378 if( !nav_file_del(TRUE) )
00379 goto pl_main_modify_end;
00380
00381 if( !nav_file_paste_start( name_copyfile ) )
00382 goto pl_main_modify_end;
00383 }
00384
00385 do{
00386 status = nav_file_paste_state(FALSE);
00387 }while( COPY_BUSY == status );
00388 if( COPY_FINISH != status )
00389 goto pl_main_modify_end;
00390
00391 copyfile_index = nav_getindex();
00392 b_copy_finish = TRUE;
00393
00394 pl_main_modify_end:
00395
00396 #if( (FS_ASCII == ENABLED) && (FS_UNICODE == ENABLED) )
00397 nav_string_unicode();
00398 #endif
00399 nav_gotoindex( &index );
00400 pl_main_open( TRUE );
00401 pl_g_list_is_modify = b_copy_finish;
00402 nav_select( nav_id_save );
00403 pl_nav_setpos(u16_pos);
00404 return pl_g_list_is_modify;
00405 }
00406 #endif
00407
00408
00409
00410
00411
00416 U16 pl_nav_getnbfile( void )
00417 {
00418 return pl_g_u16_list_size;
00419 }
00420
00421
00426 U16 pl_nav_getpos( void )
00427 {
00428 return pl_g_u16_list_sel;
00429 }
00430
00435 Bool pl_nav_eol( void )
00436 {
00437 return (pl_g_u16_list_size == pl_g_u16_list_sel);
00438 }
00439
00444 Bool pl_nav_setpos( U16 u16_position )
00445 {
00446 U8 nav_id_save;
00447
00448 if( (0 == u16_position )
00449 || (pl_g_u16_list_size < u16_position) )
00450 {
00451 fs_g_status = FS_ERR_PL_OUT_LST;
00452 return FALSE;
00453 }
00454
00455 if( pl_g_u16_list_sel == u16_position )
00456 return TRUE;
00457
00458
00459 nav_filelist_reset();
00460
00461
00462 nav_id_save = nav_get();
00463 nav_select( FS_NAV_ID_PLAYLIST );
00464
00465 if( pl_g_u16_list_sel > u16_position )
00466 {
00467
00468 reader_txt_beg();
00469 pl_g_u16_list_sel = 0;
00470 }
00471 while( pl_g_u16_list_sel != u16_position )
00472 {
00473 FS_STRING sz_path;
00474 Bool next_pos = FALSE;
00475
00476 if( 0 != file_eof() )
00477 {
00478 nav_select( nav_id_save );
00479 return FALSE;
00480 }
00481 if (pl_g_u16_list_sel+1 == u16_position)
00482 {
00483 next_pos = pl_main_readline(PL_MAIN_READLINE_OPT_GOTOPATH, nav_id_save, &sz_path, NULL);
00484 if (sz_path)
00485 PLAYLIST_BUF_FREE(sz_path);
00486 }
00487 else
00488 next_pos = pl_main_readline(PL_MAIN_READLINE_OPT_CHECKLINE, 0, NULL, NULL);
00489 if (next_pos)
00490 pl_g_u16_list_sel++;
00491 }
00492 nav_select( nav_id_save );
00493 return TRUE;
00494 }
00495
00502 Bool pl_nav_readentry(U16 u16_position, FS_STRING *sz_path, U16 *u16_size_line )
00503 {
00504 U8 nav_id_save;
00505 U16 u16_current_pos;
00506 U32 u32_file_pos;
00507
00508
00509 *sz_path = NULL;
00510
00511
00512 if ((0 == u16_position)
00513 || (pl_g_u16_list_size < u16_position))
00514 {
00515 fs_g_status = FS_ERR_PL_OUT_LST;
00516 return FALSE;
00517 }
00518
00519
00520 nav_id_save = nav_get();
00521 nav_select(FS_NAV_ID_PLAYLIST);
00522
00523
00524 u32_file_pos = file_getpos();
00525
00526 if (pl_g_u16_list_sel > u16_position)
00527 {
00528
00529 reader_txt_beg();
00530 u16_current_pos = 0;
00531 }
00532 else
00533 {
00534 u16_current_pos = pl_g_u16_list_sel;
00535 }
00536
00537 while(u16_current_pos != u16_position)
00538 {
00539 if (file_eof())
00540 {
00541
00542 file_seek(u32_file_pos, FS_SEEK_SET);
00543
00544 nav_select(nav_id_save);
00545 return FALSE;
00546 }
00547 if (u16_current_pos+1 == u16_position)
00548 {
00549 if (pl_main_readline(PL_MAIN_READLINE_OPT_GOTOPATH, nav_id_save, sz_path, u16_size_line))
00550 break;
00551 }
00552 else if (pl_main_readline(PL_MAIN_READLINE_OPT_CHECKLINE, 0, NULL, NULL))
00553 u16_current_pos++;
00554 }
00555
00556
00557 file_seek(u32_file_pos, FS_SEEK_SET);
00558
00559 nav_select(nav_id_save);
00560
00561 return TRUE;
00562 }
00563
00577 Bool pl_main_readline( readline_opt_t opt, U8 id_nav, FS_STRING *sz_path, U16 *u16_size_line )
00578 {
00579 U16 line_beg[8];
00580 U32 u32_file_pos;
00581 U16 u16_alt_length = 0;
00582 U8 u8_pos_path_in_line = 0;
00583
00584
00585 *sz_path = NULL;
00586
00587
00588 u32_file_pos = file_getpos();
00589 if( E_PL_M3U == pl_g_list_type )
00590 {
00591
00592
00593 u16_alt_length = reader_txt_get_line( TRUE, (FS_STRING)line_beg, 2 );
00594 if( (2 > u16_alt_length)
00595 || ('#' == line_beg[0]) )
00596 {
00597 return FALSE;
00598 }
00599 u8_pos_path_in_line=0;
00600 }
00601 if( (E_PL_PLS == pl_g_list_type) || (E_PL_SMP == pl_g_list_type) )
00602 {
00603
00604
00605 u16_alt_length = reader_txt_get_line( TRUE, (FS_STRING)line_beg, 8 );
00606 if(6 > u16_alt_length)
00607 return FALSE;
00608
00609 if( ('F' != line_beg[0])
00610 || ('i' != line_beg[1])
00611 || ('l' != line_beg[2])
00612 || ('e' != line_beg[3]) )
00613 {
00614 return FALSE;
00615 }
00616 u8_pos_path_in_line=5;
00617 if('=' != line_beg[4])
00618 {
00619 u8_pos_path_in_line++;
00620 if('=' != line_beg[5])
00621 {
00622 u8_pos_path_in_line++;
00623 if('=' != line_beg[6])
00624 {
00625 u8_pos_path_in_line++;
00626 if('=' != line_beg[7])
00627 return FALSE;
00628 }
00629 }
00630 }
00631 }
00632
00633
00634
00635 if (u16_size_line)
00636 *u16_size_line = u16_alt_length - u8_pos_path_in_line;
00637 if (opt == PL_MAIN_READLINE_OPT_CHECKLINE)
00638 return TRUE;
00639
00640
00641
00642 file_seek( u32_file_pos, FS_SEEK_SET );
00643 *sz_path = PLAYLIST_BUF_ALLOC( u16_alt_length * (Is_unicode? 2 : 1 ) );
00644 if( NULL == *sz_path )
00645 return FALSE;
00646 if( 0 == reader_txt_get_line( (FS_UNICODE==ENABLED), *sz_path, u16_alt_length ) )
00647 return FALSE;
00648 if( 0 != u8_pos_path_in_line )
00649 {
00650
00651 memmove(*sz_path, *sz_path + u8_pos_path_in_line * ((FS_UNICODE==ENABLED) ? 2 : 1),
00652 (u16_alt_length - u8_pos_path_in_line) * ((FS_UNICODE==ENABLED) ? 2 : 1));
00653 }
00654 if (opt == PL_MAIN_READLINE_OPT_READSTRING)
00655 return TRUE;
00656
00657
00658 nav_copy( id_nav );
00659 nav_select( id_nav );
00660
00661 if( !nav_setcwd( (FS_STRING) *sz_path , FALSE, FALSE ) )
00662 {
00663
00664 nav_filelist_reset();
00665 }
00666 nav_select( FS_NAV_ID_PLAYLIST );
00667
00668 return TRUE;
00669 }
00670
00671
00672
00673
00674
00679 Bool pl_sel_isvalid( void )
00680 {
00681 if(!pl_main_isopen())
00682 return FALSE;
00683 if(0 == pl_g_u16_list_sel)
00684 return FALSE;
00685 return nav_filelist_validpos();
00686 }
00687
00688
00689
00690
00691
00692 #if( PL_READONLY == DISABLED )
00705 Bool pl_add( const FS_STRING sz_filterext , U8 u8_mode )
00706 {
00707 U8 nav_id_save;
00708 U8 u8_folder_level;
00709
00710 if( !pl_main_modify() )
00711 return FALSE;
00712 nav_id_save = nav_get();
00713
00714
00715 nav_select( FS_NAV_ID_PLAYLIST );
00716 if( 0!=nav_file_lgt() )
00717 {
00718 #if( PL_UNICODE == ENABLED)
00719 file_string_unicode();
00720 file_seek( 2, FS_SEEK_END);
00721 if( '\n' != file_getc())
00722 {
00723 file_seek( 2, FS_SEEK_END);
00724 file_putc('\n');
00725 }
00726 file_string_ascii();
00727 #else
00728 file_seek( 1, FS_SEEK_END);
00729 if( '\n' != file_getc())
00730 {
00731 file_seek( 1, FS_SEEK_END);
00732 file_putc('\n');
00733 }
00734 #endif
00735 }
00736 nav_select( nav_id_save );
00737
00738
00739
00740 if( PL_ADD_FILE == u8_mode )
00741 goto pl_add_file;
00742
00743
00744 u8_folder_level = 0;
00745 nav_filelist_reset();
00746 while(1)
00747 {
00748 while(1)
00749 {
00750 if( nav_filelist_set( 0 , FS_FIND_NEXT ) )
00751 break;
00752
00753 if( 0 == u8_folder_level )
00754 goto pl_add_end;
00755
00756 u8_folder_level--;
00757 if( !nav_dir_gotoparent() )
00758 return FALSE;
00759 }
00760
00761 if( nav_file_isdir())
00762 {
00763 if( PL_ADD_SUBDIR == u8_mode )
00764 {
00765 if( !nav_dir_cd())
00766 return FALSE;
00767 u8_folder_level++;
00768 }
00769 }
00770 else
00771 {
00772 pl_add_file:
00773 if( nav_file_checkext( sz_filterext ) )
00774 {
00775
00776
00777 #if( (FS_ASCII == ENABLED) && (FS_UNICODE == ENABLED) && (PL_UNICODE == DISABLED) )
00778 nav_string_ascii();
00779 #endif
00780 nav_getcwd( (FS_STRING)pl_cache_path, PL_CACHE_PATH_MAX_SIZE, TRUE );
00781 #if( (FS_ASCII == ENABLED) && (FS_UNICODE == ENABLED) && (PL_UNICODE == DISABLED) )
00782 nav_string_unicode();
00783 #endif
00784
00785 nav_select( FS_NAV_ID_PLAYLIST );
00786 #if( PL_UNICODE == ENABLED)
00787 file_string_unicode();
00788 #endif
00789 if( file_puts(pl_cache_path))
00790 file_putc('\n');
00791 #if( PL_UNICODE == ENABLED)
00792 file_string_ascii();
00793 #endif
00794 nav_select( nav_id_save );
00795 pl_g_u16_list_size++;
00796 }
00797 if( PL_ADD_FILE == u8_mode )
00798 goto pl_add_end;
00799 }
00800 }
00801
00802 pl_add_end:
00803
00804 nav_select( FS_NAV_ID_PLAYLIST );
00805 file_seek( 0 , FS_SEEK_SET );
00806 pl_g_u16_list_sel = 0;
00807 nav_select( nav_id_save );
00808 return TRUE;
00809 }
00810 #endif
00811
00812
00813
00814
00815 #if( PL_READONLY == DISABLED )
00816
00822 Bool pl_rem_sel_all( void )
00823 {
00824 U8 nav_id_save;
00825 Bool b_status;
00826
00827 if( !pl_main_modify() )
00828 return FALSE;
00829
00830 nav_id_save = nav_get();
00831 nav_select( FS_NAV_ID_PLAYLIST );
00832
00833 file_seek( 0 , FS_SEEK_SET );
00834 b_status = file_set_eof();
00835 nav_select( nav_id_save );
00836 return b_status;
00837 }
00838
00839
00845 Bool pl_rem_sel( void )
00846 {
00847 U8 nav_id_save;
00848 Bool b_status = FALSE;
00849
00850 if( !pl_main_modify() )
00851 return FALSE;
00852 if( 0 == pl_g_u16_list_sel )
00853 {
00854 fs_g_status = FS_ERR_PL_OUT_LST;
00855 return FALSE;
00856 }
00857 nav_id_save = nav_get();
00858 nav_select( FS_NAV_ID_PLAYLIST );
00859
00860
00861 #if( PL_UNICODE == ENABLED)
00862 file_string_unicode();
00863 if( !file_seek( pl_g_u16_path_size*2 , FS_SEEK_CUR_RE ))
00864 goto pl_rem_sys_err;
00865 #else
00866 if( !file_seek( pl_g_u16_path_size , FS_SEEK_CUR_RE ))
00867 goto pl_rem_sys_err;
00868 #endif
00869
00870
00871 if( !file_putc('#'))
00872 goto pl_rem_sys_err;
00873 b_status = TRUE;
00874 pl_g_u16_list_size--;
00875
00876 pl_rem_sys_err:
00877 #if( PL_UNICODE == ENABLED)
00878 file_string_ascii();
00879 #endif
00880
00881 file_seek( 0 , FS_SEEK_SET );
00882 pl_g_u16_list_sel = 0;
00883 nav_select( nav_id_save );
00884 return b_status;
00885 }
00886
00887
00893 Bool pl_rem_dead( void )
00894 {
00895 U8 nav_id_save;
00896
00897 pl_g_u16_list_sel = 0;
00898
00899 nav_id_save = nav_get();
00900 nav_select( FS_NAV_ID_PLAYLIST );
00901
00902 while( pl_g_u16_list_sel < pl_g_u16_list_size )
00903 {
00904 if( nav_gotoindex( &pl_g_list[ pl_g_u16_list_sel ] ))
00905 {
00906
00907 pl_g_u16_list_sel++;
00908 continue;
00909 }
00910
00911
00912 pl_rem_sel();
00913 }
00914 nav_select( nav_id_save );
00915 pl_nav_setpos(0);
00916 }
00917
00918 #endif // ( PL_READONLY == DISABLED )
00919
00920 #if defined(PLAYLIST_USE_NON_BLOCKING_FUNCTION_SET) && \
00921 PLAYLIST_USE_NON_BLOCKING_FUNCTION_SET == ENABLED
00922
00923
00924
00935 Bool pl_main_open_non_blocking(U16 u16_n)
00936 {
00937 ai_async_context_t ctx;
00938 U16 u16_current_count = 0;
00939 static U8 nav_id_save;
00940 typedef enum
00941 {
00942 STATE_INITIALIZATION = 0,
00943 STATE_GET_LINK_COUNT,
00944 STATE_INIT_PLAYLIST_CONTEXT,
00945 STATE_END
00946 } state_t;
00947
00948
00949 if (!ai_async_context_pop(&ctx))
00950 ctx.state = (state_t) STATE_INITIALIZATION;
00951
00952 ctx.status = CMD_DONE;
00953
00954 switch((state_t) ctx.state)
00955 {
00956
00957 case STATE_INITIALIZATION:
00958 if (pl_main_isopen())
00959 return FALSE;
00960
00961
00962 nav_id_save = nav_get();
00963 nav_copy(FS_NAV_ID_PLAYLIST);
00964 nav_select(FS_NAV_ID_PLAYLIST);
00965
00966 if (nav_file_checkext("m3u"))
00967 pl_g_list_type = E_PL_M3U;
00968 else if (nav_file_checkext("pls"))
00969 pl_g_list_type = E_PL_PLS;
00970 else if (nav_file_checkext("smp"))
00971 pl_g_list_type = E_PL_SMP;
00972 else
00973 {
00974 ctx.status = CMD_EXECUTING;
00975 ctx.state = (state_t) STATE_END;
00976 break;
00977 }
00978
00979 if (!reader_txt_open(TRUE))
00980 {
00981 ctx.status = CMD_EXECUTING;
00982 ctx.state = (state_t) STATE_END;
00983 break;
00984 }
00985 pl_g_u16_list_size = 0;
00986 ctx.status = CMD_EXECUTING;
00987 if (u16_n)
00988 ctx.state = (state_t) STATE_GET_LINK_COUNT;
00989 else
00990 ctx.state = (state_t) STATE_INIT_PLAYLIST_CONTEXT;
00991 break;
00992
00993 case STATE_GET_LINK_COUNT:
00994 u16_current_count = 0;
00995 nav_select(FS_NAV_ID_PLAYLIST);
00996 while (!file_eof() && u16_current_count < u16_n)
00997 {
00998 if (pl_main_readline(PL_MAIN_READLINE_OPT_CHECKLINE, 0, NULL, NULL))
00999 pl_g_u16_list_size++;
01000
01001 else if (fs_g_status == FS_ERR_FS)
01002 {
01003
01004 ctx.status = CMD_EXECUTING;
01005 ctx.state = (state_t) STATE_END;
01006 break;
01007 }
01008 u16_current_count++;
01009 }
01010 ctx.status = CMD_EXECUTING;
01011 if (file_eof())
01012 ctx.state = (state_t) STATE_INIT_PLAYLIST_CONTEXT;
01013 break;
01014
01015 case STATE_INIT_PLAYLIST_CONTEXT:
01016 nav_select(FS_NAV_ID_PLAYLIST);
01017
01018 reader_txt_beg();
01019
01020 pl_g_u16_list_sel = 0;
01021
01022 pl_g_list_is_open = TRUE;
01023
01024 nav_select(nav_id_save);
01025 nav_filelist_reset();
01026 break;
01027
01028 case STATE_END:
01029
01030 nav_select(nav_id_save);
01031 break;
01032 }
01033
01034 if (ctx.status == CMD_EXECUTING)
01035 {
01036 if (!ai_async_context_push(&ctx))
01037 return FALSE;
01038 }
01039
01040 return pl_g_list_is_open;
01041 }
01042
01053 Bool pl_nav_readentry_non_blocking(pl_nav_readentry_context_t *data, U16 u16_position, FS_STRING *sz_path, U16 *u16_size_line, U16 u16_n)
01054 {
01055 ai_async_context_t ctx;
01056 U16 u16_current_n;
01057 typedef enum
01058 {
01059 STATE_INITIALIZATION = 0,
01060 STATE_SET_POS,
01061 STATE_READ_ENTRY
01062 } state_t;
01063 Bool b_update;
01064
01065
01066 if (!ai_async_context_pop(&ctx))
01067 ctx.state = (state_t) STATE_INITIALIZATION;
01068
01069 ctx.status = CMD_DONE;
01070
01071 switch((state_t) ctx.state)
01072 {
01073
01074 case STATE_INITIALIZATION:
01075
01076 *sz_path = NULL;
01077
01078 if (u16_position == 0)
01079 {
01080 fs_g_status = FS_ERR_PL_OUT_LST;
01081 return FALSE;
01082 }
01083
01084 data->nav_id_saved = nav_get();
01085 nav_select(FS_NAV_ID_PLAYLIST);
01086
01087 data->u32_file_pos_saved = file_getpos();
01088
01089
01090
01091
01092
01093 b_update = TRUE;
01094 if (data->fs_entry.u8_open_mode)
01095 {
01096 if (data->u16_current_pos + 1 <= u16_position)
01097 b_update = FALSE;
01098 }
01099 if (b_update)
01100 {
01101
01102 reader_txt_beg();
01103 data->u16_current_pos = 0;
01104
01105 memcpy(&(data->fs_entry), &fs_g_nav_entry, sizeof(data->fs_entry));
01106 }
01107 ctx.status = CMD_EXECUTING;
01108 ctx.state = (state_t) STATE_SET_POS;
01109 break;
01110
01111 case STATE_SET_POS:
01112 nav_select(FS_NAV_ID_PLAYLIST);
01113
01114 memcpy(&fs_g_nav_entry, &(data->fs_entry), sizeof(fs_g_nav_entry));
01115
01116 u16_current_n = 0;
01117 while ((data->u16_current_pos + 1 != u16_position) &&
01118 !file_eof() &&
01119 u16_current_n < u16_n)
01120 {
01121 if (pl_main_readline(PL_MAIN_READLINE_OPT_CHECKLINE, 0, NULL, NULL))
01122 data->u16_current_pos++;
01123 u16_current_n++;
01124 }
01125
01126 if (file_eof())
01127 {
01128
01129 file_seek(data->u32_file_pos_saved, FS_SEEK_SET);
01130
01131 nav_select(data->nav_id_saved);
01132 return FALSE;
01133 }
01134
01135 ctx.status = CMD_EXECUTING;
01136 if (data->u16_current_pos + 1 == u16_position)
01137 ctx.state = (state_t) STATE_READ_ENTRY;
01138
01139
01140 memcpy(&(data->fs_entry), &fs_g_nav_entry, sizeof(data->fs_entry));
01141 break;
01142
01143 case STATE_READ_ENTRY:
01144 nav_select(FS_NAV_ID_PLAYLIST);
01145 u16_current_n = 0;
01146 b_update = FALSE;
01147 while (!file_eof() && u16_current_n < u16_n)
01148 {
01149 if ((b_update = pl_main_readline(PL_MAIN_READLINE_OPT_GOTOPATH, data->nav_id_saved, sz_path, u16_size_line)))
01150 break;
01151 u16_current_n++;
01152 }
01153
01154 if (u16_current_n >= u16_n)
01155 {
01156 ctx.status = CMD_EXECUTING;
01157 break;
01158 }
01159
01160 if (file_eof() && !b_update)
01161 {
01162
01163 file_seek(data->u32_file_pos_saved, FS_SEEK_SET);
01164
01165 nav_select(data->nav_id_saved);
01166 return FALSE;
01167 }
01168
01169
01170 data->u16_current_pos = u16_position;
01171
01172 memcpy(&(data->fs_entry), &fs_g_nav_entry, sizeof(data->fs_entry));
01173
01174
01175 file_seek(data->u32_file_pos_saved, FS_SEEK_SET);
01176
01177 nav_select(data->nav_id_saved);
01178 break;
01179 }
01180
01181 if (ctx.status == CMD_EXECUTING)
01182 {
01183 if (!ai_async_context_push(&ctx))
01184 return FALSE;
01185 }
01186
01187 return TRUE;
01188 }
01189
01190 #endif