file sorting use case. hard coded paths. little bit of good stuff needs splitting... use
authorRejean Loyer <redj@ecere.com>
Sun, 6 Oct 2013 02:43:23 +0000 (22:43 -0400)
committerRejean Loyer <redj@ecere.com>
Sun, 6 Oct 2013 02:43:23 +0000 (22:43 -0400)
explorer/explorer.epj
explorer/src/Explorer.ec
libede/EDE.epj
libede/src/FileSystemCache.ec
libede/src/FileSystemIterator.ec

index 804866e..ead4c0f 100644 (file)
          "Name" : "Release",
          "Options" : {
             "Debug" : false,
-            "Optimization" : "Speed"
+            "Optimization" : "Speed",
+            "InstallCommands" : [
+               "$(if $(WINDOWS_HOST),$(call cpq,$(TARGET),\"$(BINDIR)/\"),install $(INSTALL_FLAGS) $(TARGET) $(BINDIR)/$(MODULE)$(E))"
+            ]
          }
       },
       {
          "Folder" : "extern",
          "Files" : [
             {
-               "FileName" : "../../../sdk/extras/gui/controls/ToolBar.ec",
+               "FileName" : "../../../ecere-sdk/extras/gui/controls/ToolBar.ec",
                "Options" : {
                   "ExcludeFromBuild" : true
                }
             },
-            "../../../sdk/extras/gui/controls/SearchBox.ec"
+            "../../../ecere-sdk/extras/gui/controls/SearchBox.ec"
          ],
          "Configurations" : [
             {
index 134b675..58c86a2 100644 (file)
@@ -102,9 +102,39 @@ class Explorer : GuiApplication
             goPath = openArgsStartAt == -1 ? "" : argv[c];
             if(goPath)
             {
-               ExplorerWindow explorerWnd { };
-               explorerWnd.Create();
-               explorerWnd.location = goPath;//explorerWnd.GoTo(goPath, false, false);
+               if(false)//(c == 1)
+               {
+                  FileStats stats;
+                  //Map<String, bool> linksPaths { };
+                  //Map<uint, Map<uint, bool>> devsInodesDone { };
+                  //FileSystemCache cache;
+               //   dw = { visible = false };
+                  ///*cache = */FileSystemCache::Cache("/", true, dw);
+
+               //   FileSystemCache::Cache("/s1", true, false, true, dw);
+               //   FileSystemCache::Cache("/s2/0z", true, false, true, dw);
+                  //dw.cache.Special("/s2/0z/0sort", dw);
+                  //dw.cache.Special("/s2/library", dw);
+                  //dw.cache.Special("/s2/mirror", dw);
+               //   dw.cache.SpecialPrint();
+                  //devsInodesDone.Free();
+                  //delete devsInodesDone;
+
+                  /*{
+                     ExplorerWindow explorerWnd { testCache = dw.cache };
+                     explorerWnd.Create();
+                     explorerWnd.location = goPath;//explorerWnd.GoTo(goPath, false, false);
+                  }*/
+               //   PrintLn("# of objects: ", dw.cache.objects.count);
+               //   PrintLn("# of non single file sizes: ", dw.cache.nonSingleSizes.count);
+               //   delete dw;
+               }
+               else
+               {
+                  ExplorerWindow explorerWnd { };
+                  explorerWnd.Create();
+                  explorerWnd.location = goPath;//explorerWnd.GoTo(goPath, false, false);
+               }
             }
          }
       }
index 6509ee5..2285586 100644 (file)
@@ -1,6 +1,7 @@
 {
    "Version" : 0.2,
    "ModuleName" : "EDE",
+   "ModuleVersion" : "0.44",
    "Options" : {
       "Warnings" : "All",
       "DefaultNameSpace" : "ede",
          "Name" : "Release",
          "Options" : {
             "Debug" : false,
-            "Optimization" : "Speed"
+            "Optimization" : "Speed",
+            "InstallCommands" : [
+               "$(call cpq,$(TARGET),\"$(DESTLIBDIR)/\")",
+               "$(if $(WINDOWS_HOST),,ln -sf $(LP)$(MODULE)$(SOV) $(DESTLIBDIR)/$(LP)$(MODULE)$(SO).0)",
+               "$(if $(WINDOWS_HOST),,ln -sf $(LP)$(MODULE)$(SOV) $(DESTLIBDIR)/$(LP)$(MODULE)$(SO))"
+            ]
          }
       },
       {
index 03920bd..34ec228 100644 (file)
@@ -94,6 +94,8 @@ private:
 class FileSystemCacheBits
 {
    bool indexInodes:1;
+   bool indexByName:1;
+   bool indexBySize:1;
 }
 
 public class DummyFileSystemCacheWindow : Window
@@ -110,9 +112,16 @@ public:
    Array<FSCacheObject> normalParentStack;
    Map<uint, FileSystemDeviceCache> deviceCaches { };
 
+   Map<String, Array<FSCacheObject>> nameIndex { };
+   Map<String, bool> nonSingleNames { };
+   Map<FileSize, Array<FSCacheObject>> sizeIndex { };
+   Map<FileSize, bool> nonSingleSizes { };
+
    property bool indexInodes { set { bits.indexInodes = value; } get { return bits.indexInodes; } };
+   property bool indexByName { set { bits.indexByName = value; } get { return bits.indexByName; } };
+   property bool indexBySize { set { bits.indexBySize = value; } get { return bits.indexBySize; } };
 
-   void/*FileSystemCache*/ ::Cache(char * path, bool indexInodes, DummyFileSystemCacheWindow dummyWindow)
+   void/*FileSystemCache*/ ::Cache(char * path, bool indexInodes, bool indexByName, bool indexBySize, DummyFileSystemCacheWindow dummyWindow)
    {
       FileSystemCache cache = dummyWindow.cache;
       // TOIMP: for now we will assume the cache includes files from a single domain (partition/share)
@@ -122,6 +131,8 @@ public:
       {
          cache = dummyWindow.cache;// = { };
          cache.indexInodes = indexInodes;
+         cache.indexByName = indexByName;
+         cache.indexBySize = indexBySize;
          cache.normalParentStack = { };
          //cache.domainParentStack = { };
          if(pathAttribs.isDirectory)
@@ -136,8 +147,8 @@ public:
                {
                   bool result = true;
                   FileSystemCache cache = this.cache;
-                  uint dev = stats.dev;
-                  uint inode = stats.inode;
+                  uint dev = 0;//stats.dev;
+                  uint inode = 0;//stats.inode;
                   char * p;
                   FSCacheObject parent = isRootObject ? null : cache.normalParentStack.lastIterator.data;
                   FSCacheObject o { parent, name = CopyString(isRootObject ? path : name), stats = stats };
@@ -165,6 +176,7 @@ public:
 #if _DEBUG
                   if(cache.objects.count % 1000 == 0)
                      PrintLn(path, " ----- ", cache.objects.count / 1000, " --------- ", dev);
+#if 0
                   FileGetStatsLink(path, s);
                   if(s.inode != inode)
                   {
@@ -189,19 +201,31 @@ public:
                   }
                   delete p;
 #endif
-                  if(dev && inode && cache.bits.indexInodes)
+#endif
+                  if(!stats.attribs.isDirectory)
                   {
-                     FileSystemDeviceCache devCache = cache.deviceCaches[dev];
-                     if(!devCache)
-                        cache.deviceCaches[dev] = devCache = { };
+                     if(dev && inode && cache.bits.indexInodes)
                      {
-                        Array<FSCacheObject> inodes = devCache.inodes[inode];
-                        if(!inodes)
-                           devCache.inodes[inode] = inodes = { };
-                        else if(inodes.count == 1)
-                           devCache.nonSingleLinks[inode] = true;
-                        inodes.Add(o);
+                        FileSystemDeviceCache devCache = cache.deviceCaches[dev];
+                        if(!devCache)
+                           cache.deviceCaches[dev] = devCache = { };
+                        {
+                           Array<FSCacheObject> files = devCache.inodes[inode];
+                           if(!files)
+                           {
+                              devCache.inodes[inode] = files = { };
+                              if(cache.bits.indexBySize)
+                                 CacheAddFileToIndexBySize(cache, o, stats.size);
+                           }
+                           else if(files.count == 1)
+                              devCache.nonSingleLinks[inode] = true;
+                           files.Add(o);
+                        }
                      }
+                     else if(cache.bits.indexBySize)
+                        CacheAddFileToIndexBySize(cache, o, stats.size);
+                     if(cache.bits.indexByName)
+                        CacheAddFileToIndexByName(cache, o, name);
                   }
                   return result;
                }
@@ -307,6 +331,7 @@ public:
 
    Map<uint, Map<uint, bool>> devsInodesDone { };
    Map<String, bool> linksPaths { };
+#if 0
    void Special(char * path/*, Map<String, bool> linksPaths*//*Map<uint, Map<uint, bool>> devsInodesDone*/, DummyFileSystemCacheWindow dummyWindow)
    {
       FileSystemCacheIterator fsci { owner = dummyWindow, cache = this, iterateStartPath = true;
@@ -364,10 +389,41 @@ public:
       MapNode<String, bool> mn;
       PrintLn(" -------------------------------------------- Special -------------------------------------------- ");
       PrintLn(" ------------------------------------------------------------------------------------------------- ");
-      for(mn = linksPaths.root.minimum; mn; mn = mn.next)
+      if(linksPaths.count)
+      {
+         for(mn = linksPaths.root.minimum; mn; mn = mn.next)
+         {
+            PrintLn(mn.key);
+         }
+      }
+      else
+         PrintLn("   no hard linked files");
+      PrintLn(" ------------------------------------------------------------------------------------------------- ");
+   }
+#endif
+   void Special(char * path/*, Map<String, bool> linksPaths*//*Map<uint, Map<uint, bool>> devsInodesDone*/, DummyFileSystemCacheWindow dummyWindow)
+   {
+   }
+   void SpecialPrint()
+   {
+      MapNode<FileSize, bool> mn;
+      PrintLn(" -------------------------------------------- Special -------------------------------------------- ");
+      PrintLn(" ------------------------------------------------------------------------------------------------- ");
+      if(nonSingleSizes.count)
       {
-         PrintLn(mn.key);
+         for(mn = nonSingleSizes.root.minimum; mn; mn = mn.next)
+         {
+            Array<FSCacheObject> files = sizeIndex[mn.key];
+            PrintLn("     size: ", mn.value, "# of files: ", files.count);
+            for(o : files)
+            {
+               char * p = o.GetPath();
+               PrintLn(p);
+               delete p;
+            }
+         }
       }
+      PrintLn(" ------------------------------------------------------------------------------------------------- ");
    }
 
 private:
@@ -378,8 +434,30 @@ private:
       objects.Free();
       delete objects;
    }
+
+}
+
+static inline void CacheAddFileToIndexBySize(FileSystemCache cache, FSCacheObject o, FileSize size)
+{
+   Array<FSCacheObject> files = cache.sizeIndex[size];
+   if(!files)
+      cache.sizeIndex[size] = files = { };
+   else if(files.count == 1)
+      cache.nonSingleSizes[size] = true;
+   files.Add(o);
 }
 
+static inline void CacheAddFileToIndexByName(FileSystemCache cache, FSCacheObject o, char * name)
+{
+   Array<FSCacheObject> files = cache.nameIndex[name];
+   if(!files)
+      cache.nameIndex[name] = files = { };
+   else if(files.count == 1)
+      cache.nonSingleNames[name] = true;
+   files.Add(o);
+}
+
+
 public class FileSystemDeviceCache : struct
 {
 public:
index 6c2cab3..0a5fa34 100644 (file)
@@ -25,10 +25,10 @@ public:
       {
          char name[MAX_LOCATION] = "";
          FileStats stats;
-         if(followLinks)
+         //if(followLinks)
             FileGetStats(startPath, stats);
-         else
-            FileGetStatsLink(startPath, stats);
+         //else
+         //   FileGetStatsLink(startPath, stats);
          GetLastDirectory(startPath, name);
          listDirEntries = OnObject(owner, name, startPath, stats, true);
          if(listDirEntries)
@@ -45,7 +45,7 @@ public:
          {
             if(frame.listing.Find())
             {
-               FileStats stats = followLinks ? frame.listing.stats : frame.listing.lstats;
+               FileStats stats = frame.listing.stats; //FileStats stats = followLinks ? frame.listing.stats : frame.listing.lstats;
                listDirEntries = OnObject(owner, frame.listing.name, frame.listing.path, stats, !iterateStartPath && stack.count == 1);
                if(stats.attribs.isDirectory)
                {