Changeset 7610 in orxonox.OLD for branches/qt_gui
- Timestamp:
- May 12, 2006, 11:49:48 AM (19 years ago)
- Location:
- branches/qt_gui/src/lib
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/qt_gui/src/lib/Makefile.am
r7609 r7610 25 25 util/preferences.cc \ 26 26 util/threading.cc \ 27 util/directory.cc \ 27 28 \ 28 29 data/data_tank.cc -
branches/qt_gui/src/lib/shell/shell_completion_plugin.cc
r7609 r7610 94 94 void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const 95 95 { 96 OS::Directory dir;96 Directory dir; 97 97 98 98 if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir. -
branches/qt_gui/src/lib/util/directory.h
r7609 r7610 17 17 */ 18 18 19 #ifndef OSLINK_OSDIR_HEADER_H_20 #define OSLINK_OSDIR_HEADER_H_19 #ifndef __DIRECTORY_H_ 20 #define __DIRECTORY_H_ 21 21 22 22 #if defined(unix) || defined(__unix) || defined(__unix__) … … 31 31 32 32 #if defined(OSLINK_OSDIR_NOTSUPPORTED) 33 34 namespace OS 35 { 36 class Directory 37 { 38 public: 39 Directory(const std::string&) { } 40 bool open(const std::string&) {}; 41 void close() {}; 42 43 operator void*() const { return (void*)0; } 44 std::string next() { return ""; } 45 }; 46 } 33 #warning DIRECTORY NOT SUPPORTET 47 34 48 35 #elif defined(OSLINK_OSDIR_POSIX) 49 50 36 #include <sys/types.h> 51 37 #include <dirent.h> 52 38 53 namespace OS54 {55 class Directory56 {57 public:58 Directory(const std::string& directoryName = "")59 : willfail(false)60 {61 this->handle = NULL;62 this->willfail = true;63 this->open(directoryName);64 }65 66 ~Directory()67 {68 this->close();69 }70 71 bool open(const std::string& directoryName)72 {73 if (this->handle != NULL)74 this->close();75 this->handle = opendir(directoryName.c_str());76 if (!handle)77 willfail = true;78 else79 {80 willfail = false;81 dirent* entry = readdir(handle);82 if (entry)83 current = entry->d_name;84 else85 willfail = true;86 }87 }88 89 void close()90 {91 if (this->handle != NULL)92 closedir(handle);93 this->handle = NULL;94 this->willfail = true;95 this->current = "";96 }97 98 operator void*() const99 {100 return willfail ? (void*)0:(void*)(-1);101 }102 103 std::string next()104 {105 std::string prev(current);106 dirent* entry = readdir(handle);107 if (entry)108 current = entry->d_name;109 else110 willfail = true;111 return prev;112 }113 114 private:115 DIR* handle;116 bool willfail;117 std::string current;118 };119 }120 121 39 #elif defined(OSLINK_OSDIR_WINDOWS) 122 40 41 /// HACK 123 42 #ifdef DATADIR 124 43 #undef DATADIR … … 128 47 #include <winbase.h> 129 48 130 namespace OS 49 #endif 50 51 class Directory 131 52 { 132 class Directory 133 { 134 public: 135 Directory(const std::string& directoryName = "") 136 : handle(INVALID_HANDLE_VALUE), willfail(true) 137 { 138 this->open(directoryName); 139 } 53 public: 54 Directory(const std::string& directoryName = ""); 55 ~Directory(); 140 56 141 ~Directory() 142 { 143 this->close(); 144 } 57 bool open(const std::string& directoryName); 58 void close(); 59 operator void*() const { return willfail ? (void*)0:(void*)(-1); } 145 60 146 bool open(const std::string& directoryName) 147 { 148 if (handle != INVALID_HANDLE_VALUE) 149 this->close(); 61 std::string next(); 150 62 151 // First check the attributes trying to access a non-Directory with 152 // FindFirstFile takes ages 153 DWORD attrs = GetFileAttributes(directoryName.c_str()); 154 if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) ) 155 { 156 willfail = true; 157 return false; 158 } 159 std::string Full(directoryName); 160 // Circumvent a problem in FindFirstFile with c:\\* as parameter 161 if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') ) 162 Full += "\\"; 163 WIN32_FIND_DATA entry; 164 handle = FindFirstFile( (Full+"*").c_str(), &entry); 165 if (handle == INVALID_HANDLE_VALUE) 166 { 167 willfail = true; 168 return false; 169 } 170 else 171 { 172 willfail = false; 173 current = entry.cFileName; 174 return true; 175 } 176 } 177 178 void close() 179 { 180 if (handle != INVALID_HANDLE_VALUE) 181 FindClose(handle); 182 this->willfail = true; 183 } 184 185 operator void*() const 186 { 187 return willfail ? (void*)0:(void*)(-1); 188 } 189 190 std::string next() 191 { 192 std::string prev = current; 193 WIN32_FIND_DATA entry; 194 int ok = FindNextFile(handle, &entry); 195 if (!ok) 196 willfail = true; 197 else 198 current = entry.cFileName; 199 return current; 200 } 63 private: 64 #if defined(OSLINK_OSDIR_POSIX) 65 DIR* handle; 66 #elif defined(OSLINK_OSDIR_WINDOWS) 67 HANDLE handle; 68 #endif 69 bool willfail; 70 std::string current; 71 }; 201 72 202 73 203 private:204 HANDLE handle;205 bool willfail;206 std::string current;207 };208 }209 74 210 211 #endif 212 213 #endif 75 #endif /* __DIRECTORY_H_ */ 214 76 215 77 /**
Note: See TracChangeset
for help on using the changeset viewer.