Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <vlCore/FileSystem.hpp>
00033 #include <vlCore/DiskDirectory.hpp>
00034 #include <vlCore/GlobalSettings.hpp>
00035
00036 using namespace vl;
00037
00038
00061 ref<VirtualFile> FileSystem::locateFile(const String& full_path, const String& alternate_path) const
00062 {
00063 std::vector<String> paths;
00064 paths.push_back(full_path);
00065 if (!alternate_path.empty())
00066 paths.push_back(alternate_path + '/' + full_path);
00067 if( full_path.extractFileName() != full_path )
00068 {
00069 paths.push_back(full_path.extractFileName());
00070 if (!alternate_path.empty())
00071 paths.push_back(alternate_path + '/' + full_path.extractFileName());
00072 }
00073
00074 for(unsigned ipath=0; ipath<paths.size(); ++ipath)
00075 {
00076 paths[ipath].normalizeSlashes();
00077
00078
00079 ref<DiskFile> disk_file = new DiskFile( paths[ipath] );
00080 if ( disk_file->exists() )
00081 return disk_file;
00082
00083
00084 for( int idir=directories().size(); idir--; )
00085 {
00086
00087 ref<VirtualFile> file = directories()[idir]->file( paths[ipath] );
00088 if (file)
00089 return file;
00090 }
00091 }
00092
00093 return NULL;
00094 }
00095
00096 ref<VirtualDirectory> FileSystem::locateDirectory(const String& name) const
00097 {
00098
00099 ref<DiskDirectory> disk_directory = new DiskDirectory( name );
00100 if ( disk_directory->exists() )
00101 return disk_directory;
00102
00103
00104 for( int idir=directories().size(); idir--; )
00105 {
00106
00107 ref<VirtualDirectory> dir = directories()[idir]->subDir(name);
00108 if (dir)
00109 return dir;
00110 }
00111
00112 return NULL;
00113 }
00114
00115 void FileSystem::listFilesRecursive(std::vector<String>& file_list ) const
00116 {
00117 file_list.clear();
00118 std::vector<String> file_list_part;
00119
00120 for( int idir=directories().size(); idir--; )
00121 {
00122 directories()[idir]->listFilesRecursive(file_list_part);
00123 file_list.reserve( file_list.size() + file_list_part.size() );
00124 for(unsigned j=0; j<file_list_part.size(); ++j)
00125 file_list.push_back( file_list_part[j] );
00126 }
00127 }
00128
00129 void FileSystem::listFilesRecursive(std::vector<String>& file_list, const String& match) const
00130 {
00131 file_list.clear();
00132 std::vector<String> file_list_part;
00133
00134 for( int idir=directories().size(); idir--; )
00135 {
00136 directories()[idir]->listFilesRecursive(file_list_part, match);
00137 file_list.reserve( file_list.size() + file_list_part.size() );
00138 for(unsigned j=0; j<file_list_part.size(); ++j)
00139 file_list.push_back( file_list_part[j] );
00140 }
00141 }
00142