@@ -494,29 +494,27 @@ bool CLocatorAPI::load_all_unloaded_archives()
494
494
}
495
495
496
496
497
- void CLocatorAPI::ProcessOne (LPCSTR path, void * _F )
497
+ void CLocatorAPI::ProcessOne (LPCSTR path, const _finddata_t & entry )
498
498
{
499
- _finddata_t & F = *((_finddata_t *)_F);
500
-
501
499
string_path N;
502
500
xr_strcpy (N,sizeof (N),path);
503
- xr_strcat (N,F .name );
501
+ xr_strcat (N,entry .name );
504
502
xr_strlwr (N);
505
503
506
- if (F .attrib &_A_HIDDEN) return ;
504
+ if (entry .attrib &_A_HIDDEN) return ;
507
505
508
- if (F .attrib &_A_SUBDIR) {
506
+ if (entry .attrib &_A_SUBDIR) {
509
507
if (bNoRecurse) return ;
510
- if (0 ==xr_strcmp (F .name ," ." )) return ;
511
- if (0 ==xr_strcmp (F .name ," .." )) return ;
508
+ if (0 ==xr_strcmp (entry .name ," ." )) return ;
509
+ if (0 ==xr_strcmp (entry .name ," .." )) return ;
512
510
xr_strcat (N," \\ " );
513
- Register (N,0xffffffff ,0 ,0 ,F .size ,F .size ,(u32 )F .time_write );
511
+ Register (N,0xffffffff ,0 ,0 ,entry .size ,entry .size ,(u32 )entry .time_write );
514
512
Recurse (N);
515
513
} else {
516
514
if (strext (N) && (0 ==strncmp (strext (N)," .db" ,3 ) || 0 ==strncmp (strext (N)," .xdb" ,4 )) )
517
515
ProcessArchive (N);
518
516
else
519
- Register (N,0xffffffff ,0 ,0 ,F .size ,F .size ,(u32 )F .time_write );
517
+ Register (N,0xffffffff ,0 ,0 ,entry .size ,entry .size ,(u32 )entry .time_write );
520
518
}
521
519
}
522
520
@@ -551,66 +549,49 @@ bool ignore_path(const char* _path){
551
549
552
550
bool CLocatorAPI::Recurse (const char * path)
553
551
{
554
- _finddata_t sFile ;
555
- intptr_t hFile;
556
-
557
- string_path N;
558
- xr_strcpy (N,sizeof (N),path);
559
- xr_strcat (N," *.*" );
560
-
561
- rec_files.reserve (1224 );
562
-
563
- // find all files
564
- if (-1 ==(hFile=_findfirst (N, &sFile )))
565
- {
566
- // Log ("! Wrong path: ",path);
567
- return false ;
552
+ string_path scanPath;
553
+ xr_strcpy (scanPath, sizeof (scanPath), path);
554
+ xr_strcat (scanPath, " *.*" );
555
+ _finddata_t findData;
556
+ intptr_t handle = _findfirst (scanPath, &findData);
557
+ if (handle == -1 )
558
+ {
559
+ Log (" ! FS: Invalid path: " , path);
560
+ return false ;
568
561
}
569
-
570
- string1024 full_path;
571
- if (m_Flags.test (flNeedCheck))
572
- {
573
- xr_strcpy (full_path,sizeof (full_path), path);
574
- xr_strcat (full_path, sFile .name );
575
-
576
- // çàãîíÿåì â âåêòîð äëÿ òîãî *.db* ïðèõîäèëè â ñîðòèðîâàííîì ïîðÿäêå
577
- if (!ignore_name (sFile .name ) && !ignore_path (full_path))
578
- rec_files.push_back (sFile );
579
-
580
- while ( _findnext ( hFile, &sFile ) == 0 )
581
- {
582
- xr_strcpy (full_path,sizeof (full_path), path);
583
- xr_strcat (full_path, sFile .name );
584
- if (!ignore_name (sFile .name ) && !ignore_path (full_path))
585
- rec_files.push_back (sFile );
586
- }
587
- }
588
- else
589
- {
590
- // çàãîíÿåì â âåêòîð äëÿ òîãî *.db* ïðèõîäèëè â ñîðòèðîâàííîì ïîðÿäêå
591
- if (!ignore_name (sFile .name ))
592
- rec_files.push_back (sFile );
593
-
594
- while ( _findnext ( hFile, &sFile ) == 0 )
595
- {
596
- if (!ignore_name (sFile .name ))
597
- rec_files.push_back (sFile );
598
- }
599
-
600
- }
601
-
602
- _findclose ( hFile );
603
-
604
- FFVec buffer (rec_files);
605
- rec_files.clear_not_free ();
606
- std::sort (buffer.begin (), buffer.end (), pred_str_ff);
607
- for (FFIt I = buffer.begin (), E = buffer.end (); I != E; ++I)
608
- ProcessOne (path, &*I);
609
-
610
- // insert self
611
- if (path&&path[0 ])\
612
- Register (path,0xffffffff ,0 ,0 ,0 ,0 ,0 );
613
-
562
+ rec_files.reserve (256 );
563
+ size_t oldSize = rec_files.size ();
564
+ intptr_t done = handle;
565
+ while (done != -1 )
566
+ {
567
+ string1024 fullPath;
568
+ bool ignore = false ;
569
+ if (m_Flags.test (flNeedCheck))
570
+ {
571
+ xr_strcpy (fullPath, sizeof (fullPath), path);
572
+ xr_strcat (fullPath, findData.name );
573
+ ignore = ignore_name (findData.name ) || ignore_path (fullPath);
574
+ }
575
+ else
576
+ {
577
+ ignore = ignore_name (findData.name );
578
+ }
579
+ if (!ignore)
580
+ rec_files.push_back (findData);
581
+ done = _findnext (handle, &findData);
582
+ }
583
+ _findclose (handle);
584
+ size_t newSize = rec_files.size ();
585
+ if (newSize > oldSize)
586
+ {
587
+ std::sort (rec_files.begin ()+oldSize, rec_files.end (), pred_str_ff);
588
+ for (size_t i = oldSize; i < newSize; i++)
589
+ ProcessOne (path, rec_files[i]);
590
+ rec_files.erase (rec_files.begin ()+oldSize, rec_files.end ());
591
+ }
592
+ // insert self
593
+ if (path && path[0 ] != 0 )
594
+ Register (path, 0xffffffff , 0 , 0 , 0 , 0 , 0 );
614
595
return true ;
615
596
}
616
597
0 commit comments