[Scummvm-cvs-logs] CVS: scummvm/backends/fs/windows windows-fs.cpp,1.7,1.8
Nicolas Bacca
arisme at users.sourceforge.net
Tue Nov 19 13:22:03 CET 2002
Update of /cvsroot/scummvm/scummvm/backends/fs/windows
In directory sc8-pr-cvs1:/tmp/cvs-serv30478
Modified Files:
windows-fs.cpp
Log Message:
Fix parent
Index: windows-fs.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/fs/windows/windows-fs.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- windows-fs.cpp 19 Nov 2002 13:42:57 -0000 1.7
+++ windows-fs.cpp 19 Nov 2002 21:21:19 -0000 1.8
@@ -38,7 +38,6 @@
bool _isValid;
bool _isPseudoRoot;
String _path;
- WindowsFilesystemNode *_parentNode;
public:
WindowsFilesystemNode();
@@ -57,7 +56,7 @@
private:
static char *toAscii(TCHAR *x);
static TCHAR* toUnicode(char *x);
- static void addFile (FSList* list, ListMode mode, const WindowsFilesystemNode *parentNode, const char *base, WIN32_FIND_DATA* find_data);
+ static void addFile (FSList* list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data);
};
@@ -83,7 +82,7 @@
#endif
}
-void WindowsFilesystemNode::addFile (FSList* list, ListMode mode, const WindowsFilesystemNode *parentNode, const char *base, WIN32_FIND_DATA* find_data) {
+void WindowsFilesystemNode::addFile (FSList* list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) {
WindowsFilesystemNode entry;
char *asciiName = toAscii(find_data->cFileName);
bool isDirectory;
@@ -99,7 +98,6 @@
return;
entry._isDirectory = isDirectory;
- entry._parentNode = (entry._isDirectory ? (WindowsFilesystemNode*)parentNode : NULL);
entry._displayName = asciiName;
entry._path = base;
entry._path += asciiName;
@@ -128,8 +126,7 @@
_isValid = true;
_path = "\\";
_isPseudoRoot = false;
-#endif
- _parentNode = this;
+#endif
}
WindowsFilesystemNode::WindowsFilesystemNode(const WindowsFilesystemNode *node) {
@@ -138,7 +135,6 @@
_isValid = node->_isValid;
_isPseudoRoot = node->_isPseudoRoot;
_path = node->_path;
- _parentNode = node->_parentNode;
}
FSList *WindowsFilesystemNode::listDir(ListMode mode) const {
@@ -179,9 +175,9 @@
handle = FindFirstFile(toUnicode(searchPath), &desc);
if (handle == INVALID_HANDLE_VALUE)
return myList;
- addFile(myList, mode, this, _path.c_str(), &desc);
+ addFile(myList, mode, _path.c_str(), &desc);
while (FindNextFile(handle, &desc))
- addFile(myList, mode, this, _path.c_str(), &desc);
+ addFile(myList, mode, _path.c_str(), &desc);
FindClose(handle);
}
@@ -189,9 +185,31 @@
return myList;
}
+const char *lastPathComponent(const ScummVM::String &str) {
+ const char *start = str.c_str();
+ const char *cur = start + str.size() - 2;
+
+ while (cur > start && *cur != '\\') {
+ --cur;
+ }
+
+ return cur+1;
+}
+
FilesystemNode *WindowsFilesystemNode::parent() const {
- assert(_isDirectory); // FIXME - Why this restriction? Files have parent dirs, too!
- return _parentNode->clone();
+ assert(_isValid || _isPseudoRoot);
+ WindowsFilesystemNode *p = new WindowsFilesystemNode();
+ if (!_isPseudoRoot) {
+ const char *start = _path.c_str();
+ const char *end = lastPathComponent(_path);
+
+ p->_path = String(start, end - start);
+ p->_isValid = true;
+ p->_isDirectory = true;
+ p->_displayName = lastPathComponent(p->_path);
+ p->_isPseudoRoot = false;
+ }
+ return p;
}
#endif // defined(_MSC_VER) || defined(__MINGW32__)
More information about the Scummvm-git-logs
mailing list