37 #include <sys/types.h> 39 #if defined(__APPLE__) || (__FreeBSD__) 40 #define dirent64 dirent 41 #define readdir64_r readdir_r 69 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
73 std::vector<String> dir_list;
77 for(
int i=0; i<(int)dir_list.size(); ++i)
79 dir_list[i] = dir_list[i].right(-cur_p.
length()-1);
80 if (p.
startsWith(dir_list[i]+
'/') || p == dir_list[i])
85 cur_p = cur_p +
'/' + dir_list[i];
100 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
103 #if defined(VL_PLATFORM_WINDOWS) 104 WIN32_FIND_DATA FindFileData;
105 memset( &FindFileData, 0,
sizeof(FindFileData) );
107 HANDLE hFind = FindFirstFile( (
wchar_t*)wild.
ptr(), &FindFileData );
108 if( hFind == INVALID_HANDLE_VALUE )
115 #elif defined(__GNUG__) 116 std::vector<unsigned char> utf8;
118 DIR* dp = opendir((
char*)&utf8[0]);
135 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
138 #if defined(VL_PLATFORM_WINDOWS) 139 WIN32_FIND_DATA FindFileData;
140 memset( &FindFileData, 0,
sizeof(FindFileData) );
142 HANDLE hFind = FindFirstFile( (
wchar_t*)wild.
ptr(), &FindFileData );
143 if( hFind == INVALID_HANDLE_VALUE )
144 Log::error(
Say(
"Cannot open directory '%s' for directory listing.\n") <<
path() );
149 if ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
152 name = FindFileData.cFileName;
153 if (name != L
"." && name != L
"..")
154 dirs.push_back(
path() + name +
'/' );
156 }
while( FindNextFile(hFind, &FindFileData) != 0 );
158 DWORD dwError = GetLastError();
160 if (dwError != ERROR_NO_MORE_FILES)
166 #elif defined(__GNUG__) 167 std::vector<unsigned char> utf8;
169 struct dirent64 dirp;
170 struct dirent64* dirp2;
171 DIR* dp = opendir((
char*)&utf8[0]);
174 while(readdir64_r(dp, &dirp, &dirp2) == 0 && dirp2 !=
NULL)
176 String name = dirp.d_name;
177 if (name ==
".." || name ==
".")
180 name =
path() + name +
'/';
182 name.
toUTF8( utf8,
false );
183 DIR* is_dir = opendir((
char*)&utf8[0]);
192 dirs.push_back( name );
197 Log::error(
Say(
"Cannot open directory '%s' for directory listing.\n") <<
path() );
206 std::vector<String> file_names;
208 for(
unsigned i=0; i<file_names.size(); ++i)
212 file->
setPath( file_names[i] );
213 file_list.push_back(file);
223 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
226 #if defined(VL_PLATFORM_WINDOWS) 227 WIN32_FIND_DATA FindFileData;
228 memset( &FindFileData, 0,
sizeof(FindFileData) );
230 HANDLE hFind = FindFirstFile( (
wchar_t*)wild.
ptr(), &FindFileData );
231 if( hFind == INVALID_HANDLE_VALUE )
239 if ( (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 )
242 name = FindFileData.cFileName;
244 files.push_back(
path() + name );
246 }
while( FindNextFile(hFind, &FindFileData) != 0 );
248 DWORD dwError = GetLastError();
250 if (dwError != ERROR_NO_MORE_FILES)
256 #elif defined(__GNUG__) 257 std::vector<unsigned char> utf8;
259 struct dirent64 dirp;
260 struct dirent64* dirp2;
261 DIR* dp = opendir((
char*)&utf8[0]);
264 while(readdir64_r(dp, &dirp, &dirp2) == 0 && dirp2 !=
NULL)
266 String name = dirp.d_name;
267 if (name ==
".." || name ==
".")
270 name =
path() + name;
272 name.
toUTF8( utf8,
false );
273 DIR* is_dir = opendir((
char*)&utf8[0]);
282 files.push_back( name );
311 std::vector<String> dir_list;
313 for(
unsigned i=0; i<dir_list.size(); ++i)
virtual bool setPath(const String &path)
Changes the path name of a VirtualDirectory. Must not be an empty string.
A simple String formatting class.
virtual ref< VirtualFile > file(const String &name) const
Returns the VirtualFile with the given name if any, NULL otherwise.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void listFiles(std::vector< String > &file_list, bool append=false) const
A VirtualDirectory that operates on reguar disk directories.
void listFilesRecursive_internal(std::vector< String > &file_list) const
ref< DiskDirectory > diskSubDir(const String &subdir_name) const
const wchar_t * ptr() const
Returns the 0-terminated utf16 string.
void toUTF8(std::vector< unsigned char > &utf8, bool include_utf8_signature=true) const
Encodes the String into a UTF8 encoded string.
Visualization Library main namespace.
virtual const String & path() const
void listSubDirs(std::vector< String > &dirs, bool append=false) const
int length() const
Returns the length of the string.
bool empty() const
Returns true if length() == 0.
bool startsWith(const String &str) const
Returns true if a String starts with the specified String str.
void setPath(const String &name)
Changes the path bound to a VirtualFile. Use carefully this function, you shouldn't rename a VirtualF...
A VirtualFile that operates on regular disk files.
The ref<> class is used to reference-count an Object.
String right(int count) const
Returns the count rightmost caracters of a String. If count is negative the function returns all but ...
virtual bool exists() const
Returns true if the file exists.
void listFilesRecursive(std::vector< String > &file_list) const
Use carefully this function, since this search the whole given file system tree.
virtual ref< DiskFile > diskFile(const String &name) const
String translatePath(const String &p) const