@@ -203,7 +203,16 @@ CLocatorAPI::~CLocatorAPI()
203203 _dump_open_files (1 );
204204}
205205
206- void CLocatorAPI::Register (LPCSTR name, u32 vfs, u32 crc, u32 ptr, u32 size_real, u32 size_compressed, u32 modif)
206+ const CLocatorAPI::file* CLocatorAPI::RegisterExternal (const char * name)
207+ {
208+ struct stat buffer;
209+ if (stat (name, &buffer) == -1 )
210+ return nullptr ;
211+ return Register (name, u32 (-1 ), 0 , 0 , buffer.st_size , buffer.st_size , u32 (buffer.st_mtime ));
212+ }
213+
214+ const CLocatorAPI::file* CLocatorAPI::Register (LPCSTR name, u32 vfs, u32 crc, u32 ptr,
215+ u32 size_real, u32 size_compressed, u32 modif)
207216{
208217 // Msg("Register[%d] [%s]",vfs,name);
209218 string256 temp_file_name;
@@ -231,15 +240,15 @@ void CLocatorAPI::Register(LPCSTR name, u32 vfs, u32 crc, u32 ptr, u32 size_real
231240 // sad but true, performance option
232241 // correct way is to erase and then insert new record:
233242 const_cast <file&>(*I) = desc;
234- return ;
243+ return &*I ;
235244 }
236245 else
237246 {
238247 desc.name = xr_strdup (desc.name );
239248 }
240249
241250 // otherwise insert file
242- m_files.insert (desc);
251+ auto result = m_files.insert (desc). first ;
243252
244253 // Try to register folder(s)
245254 string_path temp;
@@ -265,6 +274,7 @@ void CLocatorAPI::Register(LPCSTR name, u32 vfs, u32 crc, u32 ptr, u32 size_real
265274 xr_strcpy (temp, sizeof (temp), folder);
266275 if (xr_strlen (temp)) temp[xr_strlen (temp) - 1 ] = 0 ;
267276 }
277+ return &*result;
268278}
269279
270280IReader* open_chunk (void * ptr, u32 ID)
@@ -874,31 +884,50 @@ void CLocatorAPI::_destroy()
874884 m_archives.clear ();
875885}
876886
877- const CLocatorAPI::file* CLocatorAPI::exist (const char * fn )
887+ const CLocatorAPI::file* CLocatorAPI::GetFileDesc (const char * path )
878888{
879- files_it it = file_find_it (fn);
880- return (it != m_files.end ()) ? &(*it) : 0 ;
889+ auto it = file_find_it (path);
890+ return it != m_files.end () ? &*it : nullptr ;
891+ }
892+
893+ FileStatus CLocatorAPI::exist (const char * fn, FSType fsType /* = FSType::Virtual*/ )
894+ {
895+ if ((fsType | FSType::Virtual) == FSType::Virtual)
896+ {
897+ files_it it = file_find_it (fn);
898+ if (it != m_files.end ())
899+ return FileStatus (true , false );
900+ }
901+ if ((fsType | FSType::External) == FSType::External)
902+ {
903+ struct stat buffer;
904+ buffer.st_size ;
905+ return FileStatus (stat (fn, &buffer) == 0 , true );
906+ }
907+ return FileStatus (false , false );
881908}
882909
883- const CLocatorAPI::file* CLocatorAPI:: exist (const char * path, const char * name)
910+ FileStatus CLocatorAPI::exist (const char * path, const char * name, FSType fsType /* = FSType::Virtual */ )
884911{
885912 string_path temp;
886913 update_path (temp, path, name);
887- return exist (temp);
914+ return exist (temp, fsType );
888915}
889916
890- const CLocatorAPI::file* CLocatorAPI::exist (string_path& fn, LPCSTR path, LPCSTR name)
917+ FileStatus CLocatorAPI::exist (string_path& fn, LPCSTR path, LPCSTR name,
918+ FSType fsType /* = FSType::Virtual*/ )
891919{
892920 update_path (fn, path, name);
893- return exist (fn);
921+ return exist (fn, fsType );
894922}
895923
896- const CLocatorAPI::file* CLocatorAPI::exist (string_path& fn, LPCSTR path, LPCSTR name, LPCSTR ext)
924+ FileStatus CLocatorAPI::exist (string_path& fn, LPCSTR path, LPCSTR name, LPCSTR ext,
925+ FSType fsType /* = FSType::Virtual*/ )
897926{
898927 string_path nm;
899928 strconcat (sizeof (nm), nm, name, ext);
900929 update_path (fn, path, nm);
901- return exist (fn);
930+ return exist (fn, fsType );
902931}
903932
904933xr_vector<char *>* CLocatorAPI::file_list_open (const char * initial, const char * folder, u32 flags)
@@ -1306,13 +1335,19 @@ bool CLocatorAPI::check_for_file(LPCSTR path, LPCSTR _fname, string_path& fname,
13061335 // Search entry
13071336 file desc_f;
13081337 desc_f.name = fname;
1309-
13101338 files_it I = m_files.find (desc_f);
13111339 if (I == m_files.end ())
1312- return (false );
1313-
1340+ {
1341+ if (!exist (fname, FSType::External))
1342+ return false ;
1343+ const file* extFile = RegisterExternal (fname);
1344+ if (!extFile)
1345+ return false ;
1346+ desc = extFile;
1347+ }
1348+ else
1349+ desc = &*I;
13141350 ++dwOpenCounter;
1315- desc = &*I;
13161351 return (true );
13171352}
13181353
@@ -1546,8 +1581,13 @@ void CLocatorAPI::file_rename(LPCSTR src, LPCSTR dest, bool bOwerwrite)
15461581
15471582int CLocatorAPI::file_length (LPCSTR src)
15481583{
1549- files_it I = file_find_it (src);
1550- return (I != m_files.end ()) ? I->size_real : -1 ;
1584+ files_it it = file_find_it (src);
1585+ if (it != m_files.end ())
1586+ return it->size_real ;
1587+ struct stat buffer;
1588+ if (stat (src, &buffer) != -1 )
1589+ return buffer.st_size ;
1590+ return -1 ;
15511591}
15521592
15531593bool CLocatorAPI::path_exist (LPCSTR path)
0 commit comments