explorer: fixed trying to access all drives list root tree
[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 class Explorer : GuiApplication
18 {
19    //skin = "Acovel";
20
21    bool Init()
22    {
23       QuickPathTool goPath { };
24       QuickPathTool searchPath { };
25       char * findWhat = null;
26       SetLoggingMode(debug, null);
27       if(argc > 1)
28       {
29          if(!strcmpi(argv[1], "go") && argc > 2)
30             goPath = argv[2];
31          else if(!strcmpi(argv[1], "find") && argc > 2)
32          {
33             char * unquoted;
34             if(argv[2][0] == '\"')
35                StripQuotes(argv[2], unquoted);
36             else
37                unquoted = argv[2];
38             findWhat = CopyString(unquoted);
39             if(argc > 3)
40             {
41                if(!strcmpi(argv[3], "in") && argc > 4)
42                   searchPath = argv[4];
43                else
44                   searchPath = ""; // this should make it current dir
45             }
46             else
47                searchPath = ""; // same
48          } 
49          else if(!strcmpi(argv[1], "search") && argc > 2)
50             searchPath = argv[2];
51          else if(!strcmpi(argv[1], "image") && argc > 2)
52             ;
53          else if(!strcmpi(argv[1], "slides") && argc > 2)
54             ;
55          else
56             goPath = argv[1];
57       }
58       else
59          goPath = "";
60       if(goPath)
61       {
62          ExplorerWindow explorerWnd { };
63          explorerWnd.Create();
64          //explorerWnd.GoToLocation(goPath);
65       }
66       else if(searchPath)
67       {
68          ExplorerWindow explorerWnd { };
69          explorerWnd.Create();
70          //explorerWnd.SearchLocation(searchPath);
71       }
72       return true;
73    }
74 }
75
76 struct QuickPathTool
77 {
78    char path[MAX_LOCATION];
79
80    property char * 
81    {
82       set
83       {
84          char * unquoted;
85          GetWorkingDir(path, MAX_LOCATION);
86          if(value[0] == '\"')
87             StripQuotes(value, unquoted);
88          else
89             unquoted = value;
90          PathCat(path, unquoted);
91          if(!FileExists(path))
92          {
93             // this incomplete functionality is not quite at it's place in this class
94             int len;
95             char * original = CopyString(path);
96             while((len = strlen(path)))
97             {
98                StripLastDirectory(path, path);
99                if(FileExists(path))
100                {
101                   // TODO: message location does not exist, 
102                   //       this higher location exists though
103                   //       go there?
104                   break;
105                }
106             }
107             if(!len)
108             {
109                // TODO: message location does not exist, 
110                //       unable to select alternate location
111             }
112             path[0] = '\0';
113             delete original;
114          }
115       }
116       get { return path[0] ? path : null; }
117    }
118    property bool { get { return (bool)path[0]; } }
119 };
120
121 define app = ((Explorer)__thisModule);