- Timestamp:
- Jun 8, 2006, 5:21:29 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/gui/gl/glgui_style.h
r8145 r8276 34 34 virtual ~GLGuiStyle(); 35 35 36 37 36 private: 38 37 float _borderLeft; //!< The Distance to the left Border of the widget, before any internal Element starts. -
trunk/src/lib/shell/shell_completion_plugin.cc
r7661 r8276 100 100 dir.setFileName(ResourceManager::getInstance()->getDataDir() + this->_subDir); 101 101 dir.open(); 102 while(dir)102 for(unsigned int i = 0; i < dir.fileCount(); i++ ) 103 103 { 104 completionList.push_back(this->_subDir + "/" + dir .next());104 completionList.push_back(this->_subDir + "/" + dir[i]); 105 105 } 106 106 } … … 118 118 std::string fileName; 119 119 std::string currFile; 120 while(dir)120 for(unsigned int i = 0; i < dir.fileCount(); i++) 121 121 { 122 currFile = dir .next();122 currFile = dir[i]; 123 123 if (currFile[0] == '.') 124 124 continue; -
trunk/src/lib/util/directory.cc
r7661 r8276 38 38 39 39 #if not defined (__WIN32__) 40 #include <sys/stat.h> 41 #include <sys/types.h> 40 #include <sys/types.h> 41 #include <sys/stat.h> 42 #include <dirent.h> 43 #else 44 #include <windows.h> 45 #include <winbase.h> 42 46 #endif 47 48 #include <iostream> 49 50 /** 51 * @brief Constructs a Directory handler. 52 * @param directoryName the name of the Directory to access. 53 */ 43 54 Directory::Directory(const std::string& directoryName) 44 : File(directoryName), willfail(false)55 : File(directoryName) 45 56 { 46 this->handle = 0; 47 this->willfail = true; 57 this->_opened = false; 48 58 } 49 59 60 /** 61 * @brief destructs the Directory. 62 */ 50 63 Directory::~Directory() 51 64 { 65 this->close(); 52 66 } 53 67 68 69 /** 70 * @brief openes the Directory 71 * @returns true on success, false on error. (does not exist, no rights -> test with functions of File) 72 * 73 * Fills the List of Files, and sets the Directory to open state 74 */ 54 75 bool Directory::open() 55 76 { 77 if (this->_opened) 78 this->close(); 79 80 // Openes the Directory for reading: 56 81 #if not defined(__WIN32__) 57 if (this->handle != NULL) 58 this->close(); 59 this->handle = opendir(this->name().c_str()); 82 DIR* handle; 83 handle = opendir(this->name().c_str()); 60 84 if (!handle) 61 willfail = true; 85 { 86 std::cerr << "could not open directory " << this->name() << " for reading" << std::endl; 87 return false; 88 } 89 #else 90 HANDLE handle; 91 92 // First check the attributes trying to access a non-Directory with 93 // FindFirstFile takes ages 94 DWORD attrs = GetFileAttributes(this->name().c_str()); 95 if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) ) 96 { 97 return false; 98 } 99 std::string Full(this->name()); 100 // Circumvent a problem in FindFirstFile with c:\\* as parameter 101 if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') ) 102 Full += "\\"; 103 WIN32_FIND_DATA entry; 104 handle = FindFirstFile( (Full+"*").c_str(), &entry); 105 if (handle == INVALID_HANDLE_VALUE) 106 { 107 std::cerr << "could not open directory " << this->name() << " for reading" << std::endl; 108 return false; 109 } 62 110 else 63 111 { 64 willfail = false; 65 dirent* entry = readdir(handle); 66 if (entry) 67 current = entry->d_name; 68 else 69 willfail = true; 112 this->_fileNames.push_back(entry.cFileName); 70 113 } 71 #else72 if (handle != INVALID_HANDLE_VALUE)73 this->close();74 75 // First check the attributes trying to access a non-Directory with76 // FindFirstFile takes ages77 DWORD attrs = GetFileAttributes(this->name().c_str());78 if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )79 {80 willfail = true;81 return false;82 }83 std::string Full(this->name());84 // Circumvent a problem in FindFirstFile with c:\\* as parameter85 if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') )86 Full += "\\";87 WIN32_FIND_DATA entry;88 handle = FindFirstFile( (Full+"*").c_str(), &entry);89 if (handle == INVALID_HANDLE_VALUE)90 {91 willfail = true;92 return false;93 }94 else95 {96 willfail = false;97 current = entry.cFileName;98 return true;99 }100 114 #endif 101 115 116 // BUILDING the list of contained Files. (only the names) 117 #if not defined(__WIN32__) 118 dirent* entry; 119 while ((entry = readdir(handle)) != NULL) 120 this->_fileNames.push_back(entry->d_name); 121 closedir(handle); 122 #else 123 WIN32_FIND_DATA entry; 124 while ((int ok = FindNextFile(handle, &entry)) != 0) 125 this->_fileNames.push_back(entry.cFileName); 126 FindClose(handle); 127 #endif 128 this->_opened = true; 129 return true; 102 130 } 103 131 132 /** 133 * @brief closes the directory 134 * @returns true. 135 * 136 * Clears the List of Files in the Directory. 137 */ 104 138 bool Directory::close() 105 139 { 106 #if not defined(__WIN32__) 107 if (this->handle != NULL) 108 closedir(handle); 109 this->handle = NULL; 110 #else 111 if (handle != INVALID_HANDLE_VALUE) 112 FindClose(handle); 113 handle = 0; 114 #endif 115 this->willfail = true; 116 this->current = ""; 140 this->_opened = false; 141 this->_fileNames.clear(); 117 142 return true; 118 143 } 119 144 120 145 121 122 std::string Directory::next() 123 { 124 #if not defined(__WIN32__) 125 std::string prev(current); 126 dirent* entry = readdir(handle); 127 if (entry) 128 current = entry->d_name; 129 else 130 willfail = true; 131 return prev; 132 133 #else 134 std::string prev = current; 135 WIN32_FIND_DATA entry; 136 int ok = FindNextFile(handle, &entry); 137 if (!ok) 138 willfail = true; 139 else 140 current = entry.cFileName; 141 return current; 142 #endif 143 } 144 145 146 /** 147 * @brief creates the directory 148 * @returns true on success, false on error 149 */ 146 150 bool Directory::create() 147 151 { -
trunk/src/lib/util/directory.h
r7661 r8276 27 27 28 28 #include "file.h" 29 30 #if not defined (__WIN32__) 31 #include <sys/types.h> 32 #include <dirent.h> 33 #else 34 #include <windows.h> 35 #include <winbase.h> 36 #endif 29 #include <vector> 37 30 38 31 class Directory : public File … … 44 37 virtual bool open(); 45 38 virtual bool close(); 46 operator void*() const { return willfail ? (void*)0:(void*)(-1); }47 48 std::string next();49 39 50 40 bool create(); 51 41 42 /** @returns if the Directory was opened */ 43 bool isOpen() const { return this->_opened; } 44 /** @returns the FileCount (count of files contained in this directory) */ 45 unsigned int fileCount() const { return _fileNames.size(); }; 46 /** @returns the FileNames contained inside of the Directory */ 47 const std::vector<std::string>& fileNames() const { return this->_fileNames; }; 48 /** @returns the i'th FileName @param fileNumber the fileNumber (must not bigger than fileCount()) */ 49 const std::string& operator[](unsigned int fileNumber) const { return this->_fileNames[fileNumber]; }; 50 /** @returns a formated string containing the FileName, prepended with the directory-Name */ 51 std::string fileNameInDir(unsigned int fileNumber) const { return this->name() + "/" + _fileNames[fileNumber]; }; 52 /** @returns a File pointing to the File @param fileNumber the fileNumber (must not bigger than fileCount()) */ 53 File getFile(unsigned int fileNumber) const { return File(fileNameInDir(fileNumber)); }; 54 52 55 private: 53 #if not defined(__WIN32__) 54 DIR* handle; 55 #else 56 HANDLE handle; 57 #endif 58 bool willfail; 59 std::string current; 56 bool _opened; //!< If the directory was opened. 57 std::vector<std::string> _fileNames; //!< The List of Files contained in the directory. (will be filled when open was called.) 60 58 }; 61 59 -
trunk/src/lib/util/file.cc
r7674 r8276 160 160 { 161 161 #warning implement 162 return false; 162 163 } 163 164 … … 165 166 { 166 167 #warning implement 168 return false; 167 169 } 168 170 … … 249 251 oFile.put(ch); 250 252 } 253 return true; 251 254 } 252 255 … … 298 301 bool File::remove() 299 302 { 303 if (!this->exists()) 304 return false; 305 300 306 this->close(); 301 307 unlink(this->_name.c_str()); 302 308 delete this->_status; 303 309 this->_status = NULL; 310 311 return true; 304 312 } 305 313
Note: See TracChangeset
for help on using the changeset viewer.