libede:FileSystemBox: fixed FileSystemBox::Find couldn't find root (/) node.
authorRejean Loyer <rejean.loyer@gmail.com>
Fri, 16 Sep 2011 11:58:12 +0000 (07:58 -0400)
committerRejean Loyer <rejean.loyer@gmail.com>
Fri, 16 Sep 2011 11:58:12 +0000 (07:58 -0400)
libede/src/FileSystemBox.ec

index f21d8a6..a4bfd34 100644 (file)
@@ -229,16 +229,75 @@ public:
       }
    }
 
       }
    }
 
+   FileSystemNode SelectLocation(char * location)
+   {
+      int c;
+      char * temp;
+      char step[MAX_LOCATION];
+
+      //StringArray steps { growingFactor = 4 };
+      Array<String> steps { };
+      FileSystemNode result = null;
+      FileSystemNode node = null;
+
+      temp = CopyString(location);
+      while(temp[0])
+      {
+         GetLastDirectory(temp, step);
+         StripLastDirectory(temp, temp);
+         steps.Add(CopyString(step));
+      }
+
+      for(c = steps.count - 1; c >= 0; c--)
+      {
+         char * t = steps[c];
+         node = Find(steps[c], node);
+         if(!node)
+            break;
+         //Select(node);
+      }
+      if(node)
+      {
+         result = node;
+         Select(result);
+      }
+
+      steps.Free();
+      delete temp;
+      delete steps;
+
+      return result;
+   }
+
    FileSystemNode Find(const char * name, FileSystemNode parent)
    {
    FileSystemNode Find(const char * name, FileSystemNode parent)
    {
-      FileSystemNode node;
-      FileSystemNode start = parent ? parent : root;
-      if(!start.loaded || !start.childrenLoaded)
-         LoadTreeNode(start);
-      for(node = start.children.first; node; node = node.next)
-         if(node.name && !strcmpi(node.name, name))
-            return node;
-      return null;
+      FileSystemNode node = null;
+      FileSystemNode result = null;
+      if(!parent/* && !strcmp(name, "/")*/)
+      {
+         DataRow row;
+         for(row = list.firstRow; row; row = row.next)
+         {
+            node = (FileSystemNode)row.tag;
+            if(node.name && !fstrcmp(node.name, name))
+               break;
+         }
+         if(node)
+            result = node;
+         //result = root;
+      }
+      else
+      {
+         FileSystemNode start = parent ? parent : root;
+         if(!start.loaded || !start.childrenLoaded)
+            LoadTreeNode(start);
+         for(node = start.children.first; node; node = node.next)
+            if(node.name && !fstrcmp(node.name, name))
+               break;
+         if(node)
+            result = node;
+      }
+      return result;
    }
 
    void Refresh()
    }
 
    void Refresh()