Ticket #8583: abox-fs.cpp.patch
File abox-fs.cpp.patch, 7.6 KB (added by , 18 years ago) |
---|
-
.cpp
old new 16 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 17 * 18 18 * $URL: https://svn.sourceforge.net/svnroot/scummvm/scummvm/trunk/backends/fs/morphos/abox-fs.cpp $ 19 * $Id: abox-fs.cpp 23 974 2006-09-23 00:42:35Z fingolfin $19 * $Id: abox-fs.cpp 23274 2006-06-24 08:07:48Z fingolfin $ 20 20 */ 21 21 22 22 #if defined(__MORPHOS__) … … 24 24 #include <proto/dos.h> 25 25 26 26 #include <stdio.h> 27 #include <sys/stat.h> 27 28 28 #include "engines/engine.h" 29 #include <common/stdafx.h> 30 31 #include "common/util.h" 32 #include "base/engine.h" 29 33 #include "backends/fs/abstract-fs.h" 30 34 31 35 /* … … 43 47 public: 44 48 ABoxFilesystemNode(); 45 49 ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL); 50 ABoxFilesystemNode(const String &p); 51 ABoxFilesystemNode(const ABoxFilesystemNode &node); 52 46 53 ~ABoxFilesystemNode(); 47 54 48 55 virtual String displayName() const { return _displayName; } 49 virtual String name() const { return _displayName; } 56 virtual String name() const { return _displayName; }; 50 57 virtual bool isValid() const { return _isValid; } 51 58 virtual bool isDirectory() const { return _isDirectory; } 52 59 virtual String path() const { return _path; } … … 54 61 virtual bool listDir(AbstractFSList &list, ListMode mode) const; 55 62 static AbstractFSList listRoot(); 56 63 virtual AbstractFilesystemNode *parent() const; 57 virtual AbstractFilesystemNode *child(const String &n ) const;64 virtual AbstractFilesystemNode *child(const String &name) const; 58 65 }; 59 66 60 67 … … 62 69 return AbstractFilesystemNode::getRoot(); 63 70 } 64 71 72 AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { 73 return new ABoxFilesystemNode(path); 74 } 75 65 76 AbstractFilesystemNode *AbstractFilesystemNode::getRoot() 66 77 { 67 78 return new ABoxFilesystemNode(); … … 83 94 _lock = NULL; 84 95 for (;;) 85 96 { 86 char n [bufsize];87 if (NameFromLock(lock, n , bufsize) != DOSFALSE)97 char name[bufsize]; 98 if (NameFromLock(lock, name, bufsize) != DOSFALSE) 88 99 { 89 _path = n ;90 _displayName = display_name ? display_name : FilePart(n );100 _path = name; 101 _displayName = display_name ? display_name : FilePart(name); 91 102 break; 92 103 } 93 104 if (IoErr() != ERROR_LINE_TOO_LONG) 94 105 { 95 106 _isValid = false; 96 warning("Error while retrieving path name: %d", IoErr());107 debug(6, "Error while retrieving path name: %ld", IoErr()); 97 108 return; 98 109 } 99 110 bufsize *= 2; 100 111 } 101 112 113 _isDirectory = false; 102 114 _isValid = false; 103 115 104 116 FileInfoBlock *fib = (FileInfoBlock*) AllocDosObject(DOS_FIB, NULL); 105 117 if (fib == NULL) 106 118 { 107 warning("Failed to allocate memory for FileInfoBlock");119 debug(6, "Failed to allocate memory for FileInfoBlock"); 108 120 return; 109 121 } 110 122 … … 119 131 _isValid = (_lock != NULL); 120 132 } 121 133 else 134 { 122 135 _isValid = true; 136 } 123 137 } 124 138 FreeDosObject(DOS_FIB, fib); 125 139 } 126 140 141 ABoxFilesystemNode::ABoxFilesystemNode(const String &p) { 142 int len = 0, offset = p.size(); 143 144 assert(offset > 0); 145 146 _path = p; 147 148 // Extract last component from path 149 const char *str = p.c_str(); 150 while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':') ) 151 offset--; 152 while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) { 153 len++; 154 offset--; 155 } 156 _displayName = String(str + offset, len); 157 _lock = NULL; 158 _isDirectory = false; 159 160 struct FileInfoBlock *fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, NULL); 161 if (!fib) 162 { 163 debug(6, "FileInfoBlock is NULL"); 164 return; 165 } 166 167 // Check whether the node exists and if it is a directory 168 169 BPTR pLock = Lock((STRPTR)_path.c_str(), SHARED_LOCK); 170 if (pLock) 171 { 172 if (Examine(pLock, fib) != DOSFALSE) { 173 if (fib->fib_EntryType > 0) 174 { 175 _isDirectory = true; 176 _lock = DupLock(pLock); 177 _isValid = (_lock != 0); 178 179 // Add a trailing slash if it is needed 180 const char c = _path.lastChar(); 181 if (c != '/' && c != ':') 182 _path += '/'; 183 184 } 185 else 186 { 187 _isDirectory = false; 188 _isValid = true; 189 } 190 } 191 192 UnLock(pLock); 193 } 194 195 FreeDosObject(DOS_FIB, fib); 196 } 197 198 ABoxFilesystemNode::ABoxFilesystemNode(const ABoxFilesystemNode& node) 199 { 200 _displayName = node._displayName; 201 _isValid = node._isValid; 202 _isDirectory = node._isDirectory; 203 _path = node._path; 204 _lock = DupLock(node._lock); 205 } 206 127 207 ABoxFilesystemNode::~ABoxFilesystemNode() 128 208 { 129 209 if (_lock) … … 136 216 bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const 137 217 { 138 218 if (!_isValid) 139 error("listDir() called on invalid node"); 140 219 { 220 debug(6, "listDir() called on invalid node"); 221 return false; 222 } 141 223 if (!_isDirectory) 142 error("listDir() called on file node"); 224 { 225 debug(6, "listDir() called on file node"); 226 return false; 227 } 143 228 144 229 if (_lock == NULL) 145 230 { … … 153 238 154 239 if (fib == NULL) 155 240 { 156 warning("Failed to allocate memory for FileInfoBlock");241 debug(6, "Failed to allocate memory for FileInfoBlock"); 157 242 return false; 158 243 } 159 244 … … 165 250 String full_path; 166 251 BPTR lock; 167 252 168 if ((fib->fib_EntryType > 0 && (mode & FilesystemNode::kListDirectoriesOnly)) || 253 if ((mode == FilesystemNode::kListAll) || 254 (fib->fib_EntryType > 0 && (mode & FilesystemNode::kListDirectoriesOnly)) || 169 255 (fib->fib_EntryType < 0 && (mode & FilesystemNode::kListFilesOnly))) 170 256 { 171 257 full_path = _path; … … 173 259 lock = Lock(full_path.c_str(), SHARED_LOCK); 174 260 if (lock) 175 261 { 176 entry = new ABoxFilesystemNode(lock );262 entry = new ABoxFilesystemNode(lock, fib->fib_FileName); 177 263 if (entry) 178 264 { 179 265 if (entry->isValid()) … … 187 273 } 188 274 189 275 if (IoErr() != ERROR_NO_MORE_ENTRIES) 190 warning("Error while reading directory: %d", IoErr());276 debug(6, "Error while reading directory: %ld", IoErr()); 191 277 } 192 278 193 279 FreeDosObject(DOS_FIB, fib); 194 280 195 return tr ee;281 return true; 196 282 } 197 283 198 284 AbstractFilesystemNode *ABoxFilesystemNode::parent() const … … 200 286 AbstractFilesystemNode *node = NULL; 201 287 202 288 if (!_isDirectory) 203 error("parent() called on file node"); 289 { 290 debug(6, "parent() called on file node"); 291 return NULL; 292 } 204 293 205 294 if (_lock == NULL) { 206 295 /* Parent of the root is the root itself */ 207 node = 0;296 return new ABoxFilesystemNode(*this); 208 297 } else { 209 298 BPTR parent_lock = ParentDir(_lock); 210 299 if (parent_lock) { … … 217 306 return node; 218 307 } 219 308 220 AbstractFilesystemNode *ABoxFilesystemNode::child(const String &n) const { 221 TODO 309 AbstractFilesystemNode *ABoxFilesystemNode::child(const String &name) const { 310 assert(_isDirectory); 311 String newPath(_path); 312 313 if (_path.lastChar() != '/') 314 newPath += '/'; 315 newPath += name; 316 317 BPTR lock = Lock(newPath.c_str(), SHARED_LOCK); 318 319 if (!lock) 320 { 321 return 0; 322 } 323 324 UnLock(lock); 325 326 return new ABoxFilesystemNode(newPath); 222 327 } 223 328 224 329 AbstractFSList ABoxFilesystemNode::listRoot() … … 226 331 AbstractFSList myList; 227 332 DosList *dosList; 228 333 CONST ULONG lockDosListFlags = LDF_READ | LDF_VOLUMES; 229 char n [256];334 char name[256]; 230 335 231 336 dosList = LockDosList(lockDosListFlags); 232 337 if (dosList == NULL) 233 338 { 234 warning("Could not lock dos list");235 339 return myList; 236 340 } 237 341 … … 248 352 CONST_STRPTR device_name = (CONST_STRPTR)((struct Task *)dosList->dol_Task->mp_SigTask)->tc_Node.ln_Name; 249 353 BPTR volume_lock; 250 354 251 strcpy(n , volume_name);252 strcat(n , ":");253 volume_lock = Lock(n , SHARED_LOCK);355 strcpy(name, volume_name); 356 strcat(name, ":"); 357 volume_lock = Lock(name, SHARED_LOCK); 254 358 if (volume_lock) 255 359 { 256 sprintf(n , "%s (%s)", volume_name, device_name);257 entry = new ABoxFilesystemNode(volume_lock, n );360 sprintf(name, "%s (%s)", volume_name, device_name); 361 entry = new ABoxFilesystemNode(volume_lock, name); 258 362 if (entry) 259 363 { 260 364 if (entry->isValid())