Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 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 // first look in the "." directory 00079 ref<DiskFile> disk_file = new DiskFile( paths[ipath] ); 00080 if ( disk_file->exists() ) 00081 return disk_file; 00082 00083 // iterate backwards 00084 for( int idir=directories().size(); idir--; ) 00085 { 00086 // returns the first one found 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 // first look in the "." directory 00099 ref<DiskDirectory> disk_directory = new DiskDirectory( name ); 00100 if ( disk_directory->exists() ) 00101 return disk_directory; 00102 00103 // iterate backwards 00104 for( int idir=directories().size(); idir--; ) 00105 { 00106 // returns the first one found 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 // iterate backwards 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 // iterate backwards 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 //-----------------------------------------------------------------------------