222abe64f33a42a12071a5ee26cb7cc6a1dda7b7
[sdk] / ide / src / dialogs / CompilersDetectionDialog.ec
1 import "ecere"
2 import "IDESettings"
3
4 //static Color unfocusedSelectorColor { 70, 96, 166 };
5
6 // how to detect express vs pro?
7 static const char * compilerSignatureEnvVars[CompilerType] = { "", "", "", "VS80COMNTOOLS", "VS90COMNTOOLS", "VS100COMNTOOLS" };
8
9 class CompilersDetectionDialog : Window
10 {
11    background = formColor;
12    minClientSize = { 320, 180 };
13    maxClientSize = { 640, 360 };
14    borderStyle = sizable;
15    tabCycle = true;
16    hasClose = true;
17    showInTaskBar = false;
18    text = $"Compilers Detection";
19
20    CompilerType selectedCompilerType;
21
22    //property Array<NamedString> compilerEnvVars
23    property CompilerConfig compilerConfig
24    {
25       get
26       {
27          //Array<NamedString> result { };
28          CompilerConfig result = null;
29          if(selectedCompilerType)
30          {
31             char compilerPath[MAX_LOCATION];
32             compilerPath[0] = '\0';
33             GetEnvironment(compilerSignatureEnvVars[selectedCompilerType], compilerPath, sizeof(compilerPath));
34             if(compilerPath && compilerPath[0] && FileExists(compilerPath).isDirectory)
35             {
36                PathCat(compilerPath, "vsvars32.bat"); // is this file name constant and this file always present?
37                if(FileExists(compilerPath).isFile)
38                {
39                   File f = FileOpen(compilerPath, read);
40                   if(f)
41                   {
42                      char line[65536];
43                      result = MakeDefaultCompiler(selectedCompilerType, false);
44                      result.type = selectedCompilerType;
45                      if(selectedCompilerType.isVC)
46                      {
47                         //result.cppCommand = "";
48                         //result.ccCommand = "";
49                         result.makeCommand = "vcbuild";
50                      }
51                      while(f.GetLine(line, 65536))
52                      {
53                         char * var = SearchString(line, 0, "@SET ", false, false);
54                         if(var/* == line*/)
55                         {
56                            char * equal;
57                            var = &var[5];
58                            equal = strstr(var, "=");
59                            if(equal)
60                            {
61                               char * val = equal + 1;
62                               Array<String> dirs = null;
63                               equal[0] = '\0';
64                               TrimLSpaces(var, var);
65                               TrimRSpaces(var, var);
66                               if(!strcmpi(var, "VSINSTALLDIR") || !strcmpi(var, "VCINSTALLDIR") ||
67                                     !strcmpi(var, "FrameworkDir") || !strcmpi(var, "FrameworkVersion") || !strcmpi(var, "FrameworkSDKDir") ||
68                                     !strcmpi(var, "DevEnvDir") || !strcmpi(var, "LIBPATH"))
69                               {
70                                  result.environmentVars.Add(NamedString { name = CopyString(var), string = CopyString(val) });
71                               }
72                               else if(!strcmpi(var, "PATH"))
73                                  dirs = result.executableDirs;
74                               else if(!strcmpi(var, "LIB"))
75                                  dirs = result.libraryDirs;
76                               else if(!strcmpi(var, "INCLUDE"))
77                                  dirs = result.includeDirs;
78                               if(dirs)
79                               {
80                                  char * tokens[256];
81                                  int c, numTokens;
82                                  char * refId = new char[strlen(var)+3];
83                                  sprintf(refId, "%%%s%%", var);
84                                  numTokens = TokenizeWith(val, sizeof(tokens) / sizeof(byte *), tokens, ";", false);
85                                  for(c = 0; c < numTokens; c++)
86                                  {
87                                     if(strcmpi(tokens[c], refId))
88                                        dirs.Add(CopyString(tokens[c]));
89                                  }
90                               }
91                            }
92                         }
93                         else if(!strcmp(line, "@goto end"))
94                            break;
95                      }
96                      delete f;
97                   }
98                }
99             }
100          }
101          return result;
102       }
103    }
104
105    Label labelCompilersList { this, position = { 8, 8 }, labeledWindow = compilersList };
106    ListBox compilersList
107    {
108       this, borderStyle = deep, hasVertScroll = true, hasHorzScroll = true;
109       // multiSelect = true, selectionColor = unfocusedSelectorColor;
110       fullRowSelect = true;
111       alwaysHighLight = true;
112
113       size = { 180 };
114       anchor = Anchor { left = 8, top = 24, right = 8, bottom = 36 };
115       text = $"Compilers";
116
117       bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
118       {
119          if(row)
120          {
121             selectedCompilerType = (CompilerType)row.tag;
122             ok.disabled = !selectedCompilerType;
123          }
124          return true;
125       }
126    };
127
128    Button ok
129    {
130       this, isDefault = true, disabled = true, text = $"OK";
131       size = { 60 }, anchor = { right = 76, bottom = 8 };
132       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
133       {
134
135          Destroy(1);
136          return true;
137       }
138    };
139
140    Button
141    {
142       this, hotKey = escape, text = $"Cancel";
143       size = { 60 }, anchor = { right = 8, bottom = 8 };
144       NotifyClicked = ButtonCloseDialog;
145    };
146
147    bool OnPostCreate()
148    {
149       CompilerType compilerType;
150       char compilerPath[MAX_LOCATION];
151       for(compilerType = firstCompilerType; compilerType <= lastCompilerType; compilerType++)
152       {
153          const char * varName = compilerSignatureEnvVars[compilerType];
154          if(varName && *varName)
155          {
156             compilerPath[0] = '\0';
157             GetEnvironment(varName, compilerPath, sizeof(compilerPath));
158             if(compilerPath && compilerPath[0] && FileExists(compilerPath).isDirectory)
159             {
160                PathCat(compilerPath, "vsvars32.bat"); // is this file name constant and this file always present?
161                if(FileExists(compilerPath).isFile)
162                {
163                   DataRow row = compilersList.AddString(compilerType.longName);
164                   row.tag = (int64)compilerType;
165                   // maybe try to read this line in vsvars32.bat instead of hard coded compiler names or not
166                   // @echo Setting environment for using Microsoft Visual Studio 2005 x86 tools.
167                }
168             }
169          }
170       }
171       if(compilersList.rowCount)
172          compilersList.SelectRow(compilersList.firstRow);
173       return true;
174    }
175 }