MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / ListOSFiles

Method ListOSFiles

neo/framework/FileSystem.cpp:1849–1892  ·  view source on GitHub ↗

=============== idFileSystemLocal::ListOSFiles call to the OS for a listing of files in an OS directory optionally, perform some caching of the entries =============== */

Source from the content-addressed store, hash-verified

1847===============
1848*/
1849int idFileSystemLocal::ListOSFiles( const char *directory, const char *extension, idStrList &list ) {
1850 int i, j, ret;
1851
1852 if ( !extension ) {
1853 extension = "";
1854 }
1855
1856 if ( !fs_caseSensitiveOS.GetBool() ) {
1857 return Sys_ListFiles( directory, extension, list );
1858 }
1859
1860 // try in cache
1861 i = dir_cache_index - 1;
1862 while( i >= dir_cache_index - dir_cache_count ) {
1863 j = (i+MAX_CACHED_DIRS) % MAX_CACHED_DIRS;
1864 if ( dir_cache[j].Matches( directory, extension ) ) {
1865 if ( fs_debug.GetInteger() ) {
1866 //common->Printf( "idFileSystemLocal::ListOSFiles: cache hit: %s\n", directory );
1867 }
1868 list = dir_cache[j];
1869 return list.Num();
1870 }
1871 i--;
1872 }
1873
1874 if ( fs_debug.GetInteger() ) {
1875 //common->Printf( "idFileSystemLocal::ListOSFiles: cache miss: %s\n", directory );
1876 }
1877
1878 ret = Sys_ListFiles( directory, extension, list );
1879
1880 if ( ret == -1 ) {
1881 return -1;
1882 }
1883
1884 // push a new entry
1885 dir_cache[dir_cache_index].Init( directory, extension, list );
1886 dir_cache_index = (dir_cache_index + 1) % MAX_CACHED_DIRS;
1887 if ( dir_cache_count < MAX_CACHED_DIRS ) {
1888 dir_cache_count++;
1889 }
1890
1891 return ret;
1892}
1893
1894/*
1895================

Callers

nothing calls this directly

Calls 6

MatchesMethod · 0.80
GetIntegerMethod · 0.80
Sys_ListFilesFunction · 0.50
GetBoolMethod · 0.45
NumMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected