file sorting use case. hard coded paths. little bit of good stuff needs splitting...
[ede] / explorer / src / Explorer.ec
1 import "ecere"
2 import "EDE"
3 import "ExplorerWindow"
4
5 //import "Finder"
6 //import "Search"
7 //import "Panels"
8
9 /*
10 #ifdef __WIN32__
11 #include <direct.h>
12 #else
13 #include <unistd.h>
14 #endif
15 */
16
17 DummyFileSystemCacheWindow dw;// { size = { 200, 200 } };
18
19
20 class Explorer : GuiApplication
21 {
22    //skin = "Acovel";
23
24    bool Init()
25    {
26       int c, argc = this.argc;
27       int openArgsStartAt = 0;
28       QuickPathTool searchPath { };
29       char * findWhat = null;
30       Array<String> comparedPaths = null;
31
32       SetLoggingMode(debug, null);
33
34       for(c = 1; c < argc; c++)
35       {
36          if(!strcmp(argv[c], "#"))
37          {
38             argc = c;
39             break;
40          }
41       }
42
43       if(argc > 1)
44       {
45          if(!strcmpi(argv[1], "go") && argc > 2)
46             openArgsStartAt = 2;
47          else if(!strcmpi(argv[1], "find") && argc > 2)
48          {
49             char * unquoted;
50             if(argv[2][0] == '\"')
51                StripQuotes(argv[2], unquoted);
52             else
53                unquoted = argv[2];
54             findWhat = CopyString(unquoted);
55             if(argc > 3)
56             {
57                if(!strcmpi(argv[3], "in") && argc > 4)
58                   searchPath = argv[4];
59                else
60                   searchPath = ""; // this should make it current dir
61             }
62             else
63                searchPath = ""; // same
64          } 
65          else if(!strcmpi(argv[1], "search") && argc > 2)
66             searchPath = argv[2];
67          else if(!strcmpi(argv[1], "compare") && argc > 2)
68          {
69             QuickPathTool goPath { };
70             comparedPaths = { };
71             if(argc == 3)
72             {
73                goPath = ""; // current dir
74                comparedPaths.Add(goPath);
75             }
76             for(c = 2; c < argc; c++)
77             {
78                char * s;
79                goPath = argv[c];
80                s = goPath;
81                if(s)
82                   comparedPaths.Add(CopyString(s));
83             }
84             if(comparedPaths.count < 2)
85                PrintLn("compare requires at least 2 existing directories to work.");
86          }
87          else if(!strcmpi(argv[1], "image") && argc > 2)
88             ;
89          else if(!strcmpi(argv[1], "slides") && argc > 2)
90             ;
91          else
92             openArgsStartAt = 1;
93       }
94       else
95          openArgsStartAt = -1;
96
97       if(openArgsStartAt)
98       {
99          QuickPathTool goPath { };
100          for(c = openArgsStartAt; c < argc; c++)
101          {
102             goPath = openArgsStartAt == -1 ? "" : argv[c];
103             if(goPath)
104             {
105                if(false)//(c == 1)
106                {
107                   FileStats stats;
108                   //Map<String, bool> linksPaths { };
109                   //Map<uint, Map<uint, bool>> devsInodesDone { };
110                   //FileSystemCache cache;
111                //   dw = { visible = false };
112                   ///*cache = */FileSystemCache::Cache("/", true, dw);
113
114                //   FileSystemCache::Cache("/s1", true, false, true, dw);
115                //   FileSystemCache::Cache("/s2/0z", true, false, true, dw);
116                   //dw.cache.Special("/s2/0z/0sort", dw);
117                   //dw.cache.Special("/s2/library", dw);
118                   //dw.cache.Special("/s2/mirror", dw);
119                //   dw.cache.SpecialPrint();
120                   //devsInodesDone.Free();
121                   //delete devsInodesDone;
122
123                   /*{
124                      ExplorerWindow explorerWnd { testCache = dw.cache };
125                      explorerWnd.Create();
126                      explorerWnd.location = goPath;//explorerWnd.GoTo(goPath, false, false);
127                   }*/
128                //   PrintLn("# of objects: ", dw.cache.objects.count);
129                //   PrintLn("# of non single file sizes: ", dw.cache.nonSingleSizes.count);
130                //   delete dw;
131                }
132                else
133                {
134                   ExplorerWindow explorerWnd { };
135                   explorerWnd.Create();
136                   explorerWnd.location = goPath;//explorerWnd.GoTo(goPath, false, false);
137                }
138             }
139          }
140       }
141       else if(searchPath)
142       {
143          ExplorerWindow explorerWnd { };
144          explorerWnd.Create();
145          //explorerWnd.SearchLocation(searchPath);
146       }
147       else if(comparedPaths && comparedPaths.count > 1)
148       {
149          // compare /s1/library/dummies /s1/library/movies /s1/oldlib/movies "/home/redj/.gvfs/d02-2tb on kimji/library/movies"
150          ExplorerWindow explorerWnd { };
151          explorerWnd.Create();
152          explorerWnd.view.columnsCompareStyle = true;
153          explorerWnd.comparedLocations = comparedPaths;
154          // delete comparedPaths;
155       }
156       return true;
157    }
158 }
159
160 struct QuickPathTool
161 {
162    char path[MAX_LOCATION];
163
164    property char * 
165    {
166       set
167       {
168          char * unquoted;
169          GetWorkingDir(path, MAX_LOCATION);
170          if(value[0] == '\"')
171             StripQuotes(value, unquoted);
172          else
173             unquoted = value;
174          PathCat(path, unquoted);
175          if(!FileExists(path))
176          {
177             // this incomplete functionality is not quite at it's place in this class
178             int len;
179             char * original = CopyString(path);
180             while((len = strlen(path)))
181             {
182                StripLastDirectory(path, path);
183                if(FileExists(path))
184                {
185                   // TODO: message location does not exist, 
186                   //       this higher location exists though
187                   //       go there?
188                   break;
189                }
190             }
191             if(!len)
192             {
193                // TODO: message location does not exist, 
194                //       unable to select alternate location
195             }
196             path[0] = '\0';
197             delete original;
198          }
199       }
200       get { return path[0] ? (char*)path : null; }
201    }
202    property bool { get { return path[0] != '\0'; } }
203 };
204
205 define app = ((Explorer)__thisModule);