]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - tools/src/tools/configtool/standalone/wxwin/appsettings.cpp
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / tools / src / tools / configtool / standalone / wxwin / appsettings.cpp
1 //####COPYRIGHTBEGIN####
2 //
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 // Copyright (C) 2003 John Dallaway
6 //
7 // This program is part of the eCos host tools.
8 //
9 // This program is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by the Free
11 // Software Foundation; either version 2 of the License, or (at your option)
12 // any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but WITHOUT
15 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17 // more details.
18 //
19 // You should have received a copy of the GNU General Public License along with
20 // this program; if not, write to the Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 //
23 // ----------------------------------------------------------------------------
24 //
25 //####COPYRIGHTEND####
26 // appsettings.cpp :
27 //
28 //===========================================================================
29 //#####DESCRIPTIONBEGIN####
30 //
31 // Author(s):   julians, jld
32 // Contact(s):  julians
33 // Date:        2000/08/29
34 // Version:     $Id$
35 // Purpose:
36 // Description: Implementation file for the ecSettings
37 // Requires:
38 // Provides:
39 // See also:
40 // Known bugs:
41 // Usage:
42 //
43 //####DESCRIPTIONEND####
44 //
45 //===========================================================================
46
47 // ============================================================================
48 // declarations
49 // ============================================================================
50
51 // ----------------------------------------------------------------------------
52 // headers
53 // ----------------------------------------------------------------------------
54 #ifdef __GNUG__
55 #pragma implementation "appsettings.h"
56 #endif
57
58 // Includes other headers for precompiled compilation
59 #include "ecpch.h"
60
61 #ifdef __BORLANDC__
62 #pragma hdrstop
63 #endif
64
65 #include "wx/config.h"
66 #include "wx/file.h"
67
68 #include "appsettings.h"
69 #include "configtree.h"
70 #include "outputwin.h"
71 #include "shortdescrwin.h"
72 #include "mainwin.h"
73
74 // For SystemInfo
75 #ifdef __WXMSW__
76 #include <windows.h>
77 #include "wx/msw/winundef.h"
78 #if defined(GetTempPath) && !defined(__CYGWIN__)
79 #undef GetTempPath
80 #endif
81 #endif
82
83 /*
84 * User-changeable and other settings to be saved between sessions
85 */
86
87 IMPLEMENT_DYNAMIC_CLASS(ecSettings, wxObject)
88
89 ecSettings::ecSettings()
90 {
91     m_showToolBar = TRUE;
92     m_frameSize = wxRect(0, 0, 600, 500);
93     m_appName = _("eCos Configuration Tool");
94     m_showSplashScreen = TRUE;
95     m_userName = wxEmptyString;
96     m_serialNumber = 0;
97     m_frameStatus = ecSHOW_STATUS_NORMAL;
98     
99     m_treeSashSize = wxSize(400, 1000);
100     m_conflictsSashSize = wxSize(1000, 80);
101     m_propertiesSashSize = wxSize(1000, 80);
102     m_shortDescrSashSize = wxSize(1000, 80);
103     m_memorySashSize = wxSize(1000, 50);
104     m_outputSashSize = wxSize(1000, 50);
105     m_configPaneWidth = 200;
106     
107     m_showConflictsWindow = FALSE;
108     m_showPropertiesWindow = TRUE;
109     m_showShortDescrWindow = TRUE;
110     m_showMemoryWindow = FALSE;
111     m_showOutputWindow = TRUE;
112
113     m_showMacroNames = FALSE;
114     
115     m_bUseCustomViewer = FALSE;
116     m_bUseExternalBrowser = FALSE;
117     m_eUseCustomBrowser = ecAssociatedExternal;
118     m_bHex = FALSE;
119     m_nRuleChecking = Immediate|Deferred|SuggestFixes ;
120
121 #ifdef __WXMSW__
122     m_strViewer = wxT("notepad");
123 #endif
124
125     // Find dialog settings
126     m_findText = wxEmptyString;
127     m_findMatchWholeWord = FALSE;
128     m_findMatchCase = FALSE;
129     m_findDirection = TRUE; // Down is TRUE, Up is FALSE
130     m_findSearchWhat = _("Macro names"); // Macro names, item names etc.
131     m_findDialogPos = wxPoint(-1, -1);
132
133     m_editSaveFileOnly = FALSE;
134
135     // Packages dialog settings
136     m_omitHardwarePackages = FALSE;
137     m_matchPackageNamesExactly = FALSE;
138 }
139
140 // Copy constructor
141 ecSettings::ecSettings(const ecSettings& settings)
142 {
143     Copy(settings);
144 }
145
146 void ecSettings::Copy(const ecSettings& settings)
147 {
148     m_showToolBar = settings.m_showToolBar;
149     m_frameSize = settings.m_frameSize;
150     m_showSplashScreen = settings.m_showSplashScreen;
151     m_userName = settings.m_userName;
152     m_serialNumber = settings.m_serialNumber;
153     
154     m_treeSashSize = settings.m_treeSashSize;
155     m_conflictsSashSize = settings.m_conflictsSashSize;
156     m_propertiesSashSize = settings.m_propertiesSashSize;
157     m_memorySashSize = settings.m_memorySashSize;
158     m_outputSashSize = settings.m_outputSashSize;
159     m_configPaneWidth = settings.m_configPaneWidth;    
160     m_showMacroNames = settings.m_showMacroNames;
161     
162     m_bUseCustomViewer = settings.m_bUseCustomViewer;
163     m_bUseExternalBrowser = settings.m_bUseExternalBrowser;
164     m_eUseCustomBrowser = settings.m_eUseCustomBrowser;
165     m_bHex = settings.m_bHex;
166     m_nRuleChecking = settings.m_nRuleChecking;
167
168     // Find dialog settings
169     m_findText = settings.m_findText;
170     m_findMatchWholeWord = settings.m_findMatchWholeWord;
171     m_findMatchCase = settings.m_findMatchCase;
172     m_findDirection = settings.m_findDirection; // Down is TRUE, Up is FALSE
173     m_findSearchWhat = settings.m_findSearchWhat;
174     m_findDialogPos = settings.m_findDialogPos;
175
176     // Run tests settings
177     m_runTestsSettings = settings.m_runTestsSettings;
178
179     m_userToolsDir = settings.m_userToolsDir;
180     m_buildToolsDir = settings.m_buildToolsDir;
181
182     m_editSaveFileOnly = settings.m_editSaveFileOnly;
183
184     // Packages dialog settings
185     m_omitHardwarePackages = settings.m_omitHardwarePackages;
186     m_matchPackageNamesExactly = settings.m_matchPackageNamesExactly;
187 }
188
189 ecSettings::~ecSettings()
190 {
191 }
192
193 // Do some initialisation within ecApp::OnInit
194 bool ecSettings::Init()
195 {
196     return TRUE;
197 }
198
199 // Get a name suitable for the configuration file on all platforms:
200 // e.g. eCos Configuration Tool on Windows, .eCosConfigTool on Unix
201 wxString ecSettings::GetConfigAppName() const
202 {
203 #ifdef __WXGTK__
204     return wxString(wxT("eCosConfigTool"));
205 #else
206     return GetAppName();
207 #endif
208 }
209
210
211 // Create new filename
212 wxString ecSettings::GenerateFilename(const wxString& rootName)
213 {
214     wxString path;
215     if (!m_lastFilename.IsEmpty())
216         path = wxPathOnly(m_lastFilename);
217     else
218         //        path = wxGetApp().GetAppDir();
219         path = wxGetCwd();
220     
221     wxString filename(path);
222     if (filename.Last() != wxFILE_SEP_PATH )
223         filename += wxFILE_SEP_PATH;
224     filename += rootName;
225     
226     wxString fullFilename = filename + wxT(".ecc");
227     int i = 0;
228     wxString postfixStr;
229     while (wxFileExists(fullFilename))
230     {
231         i ++;
232         postfixStr.Printf("%d", i);
233         fullFilename = filename + postfixStr + wxT(".ecc");
234     }
235     
236     m_lastFilename = fullFilename;
237     return fullFilename;
238 }
239
240 // Load config info
241 bool ecSettings::LoadConfig()
242 {
243     wxConfig config(wxGetApp().GetSettings().GetConfigAppName());
244     
245     config.Read(_("/Window Status/FrameStatus"), & m_frameStatus);
246     config.Read(_("/Window Status/ShowToolBar"), (bool*) & m_showToolBar);
247     config.Read(_("/Window Status/ShowSplashScreen"), (bool*) & m_showSplashScreen);
248     config.Read(_("/Window Status/ShowConflictsWindow"), (bool*) & m_showConflictsWindow);
249     config.Read(_("/Window Status/ShowPropertiesWindow"), (bool*) & m_showPropertiesWindow);
250     config.Read(_("/Window Status/ShowShortDescrWindow"), (bool*) & m_showShortDescrWindow);
251     config.Read(_("/Window Status/ShowMemoryWindow"), (bool*) & m_showMemoryWindow);
252     config.Read(_("/Window Status/ShowOutputWindow"), (bool*) & m_showOutputWindow);
253     
254     config.Read(_("/Files/LastFile"), & m_lastFilename);
255     
256     config.Read(_("/Window Size/WindowX"), & m_frameSize.x);
257     config.Read(_("/Window Size/WindowY"), & m_frameSize.y);
258     config.Read(_("/Window Size/WindowWidth"), & m_frameSize.width);
259     config.Read(_("/Window Size/WindowHeight"), & m_frameSize.height);
260
261     config.Read(_("/Window Size/TreeSashWidth"), & m_treeSashSize.x);
262     config.Read(_("/Window Size/TreeSashHeight"), & m_treeSashSize.y);
263     config.Read(_("/Window Size/ConfigPaneWidth"), & m_configPaneWidth);
264     config.Read(_("/Window Size/ConflictsWidth"), & m_conflictsSashSize.x);
265     config.Read(_("/Window Size/ConflictsHeight"), & m_conflictsSashSize.y);
266     config.Read(_("/Window Size/PropertiesWidth"), & m_propertiesSashSize.x);
267     config.Read(_("/Window Size/PropertiesHeight"), & m_propertiesSashSize.y);
268     config.Read(_("/Window Size/ShortDescrWidth"), & m_shortDescrSashSize.x);
269     config.Read(_("/Window Size/ShortDescrHeight"), & m_shortDescrSashSize.y);
270     config.Read(_("/Window Size/OutputWidth"), & m_outputSashSize.x);
271     config.Read(_("/Window Size/OutputHeight"), & m_outputSashSize.y);
272     config.Read(_("/Window Size/MemoryWidth"), & m_memorySashSize.x);
273     config.Read(_("/Window Size/MemoryHeight"), & m_memorySashSize.y);
274
275     config.Read(_("/Options/ShowMacroNames"), (bool*) & m_showMacroNames);
276     config.Read(_("/Options/UseCustomViewer"), (bool*) & m_bUseCustomViewer);
277     config.Read(_("/Options/UseExternalBrowser"), (bool*) & m_bUseExternalBrowser);
278     
279     int tmp = (int) m_eUseCustomBrowser;
280     config.Read(_("/Options/UseCustomBrowser"), & tmp);
281     m_eUseCustomBrowser = (ecBrowserType) tmp;
282     
283     config.Read(_("/Options/Browser"), & m_strBrowser);
284     config.Read(_("/Options/Viewer"), & m_strViewer);
285     config.Read(_("/Options/HexDisplay"), (bool*) & m_bHex);
286     config.Read(_("/Options/UseDefaultFonts"), (bool*) & m_windowSettings.m_useDefaults);
287     config.Read(_("/Rule/Checking"), & m_nRuleChecking);
288
289     // Find dialog settings
290     config.Read(_("/Find/Text"), & m_findText);
291     config.Read(_("/Find/MatchWholeWord"), (bool*) & m_findMatchWholeWord);
292     config.Read(_("/Find/MatchCase"), & m_findMatchCase);
293     config.Read(_("/Find/Direction"), (bool*) & m_findDirection);
294     config.Read(_("/Find/SearchWhat"), & m_findSearchWhat);
295     config.Read(_("/Find/DialogX"), & m_findDialogPos.x);
296     config.Read(_("/Find/DialogY"), & m_findDialogPos.y);
297
298     // Package dialog settings
299     config.Read(_("/Packages/OmitHardwarePackages"), & m_omitHardwarePackages);
300     config.Read(_("/Packages/MatchPackageNamesExactly"), & m_matchPackageNamesExactly);
301
302     // Run tests settings
303     m_runTestsSettings.LoadConfig(config);
304
305     // Fonts
306     m_windowSettings.LoadConfig(config);   
307     
308     if (!config.Read(_("/Paths/UserToolsDir"), & m_userToolsDir))
309     {
310         // Use the default provided by the installer
311         config.Read(_("Default User Tools Path"), & m_userToolsDir);
312     }
313
314     // Only to be used if we fail to find the information installed
315     // with the Configuration Tool.
316     config.Read(_("/Paths/BuildToolsDir"), & m_buildToolsDir);
317     
318     if (!config.Read(_("/Build/Make Options"), & m_strMakeOptions))
319     {
320 #ifdef __WXMSW__
321         SYSTEM_INFO SystemInfo;
322         GetSystemInfo(&SystemInfo);
323 //        disable -j option for now due to problem with Cygwin 1.3.18
324 //        m_strMakeOptions.Printf(_T("-j%d"),SystemInfo.dwNumberOfProcessors);
325 #endif
326     }
327     
328     // Set default build tools binary directories as specified by the installer
329     ecFileName strDefaultBuildToolsPath;
330
331 #ifdef __WXMSW__
332     {
333         // This should look in HKEY_LOCAL_MACHINE
334
335         wxConfig config2(wxT("eCos"), wxEmptyString, wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_LOCAL_FILE);
336
337         wxString versionKey = GetInstallVersionKey();
338         wxConfigPathChanger path(& config2, wxString(wxT("/")) + versionKey + wxT("/"));
339
340         if (!versionKey.IsEmpty() && config2.Read(wxT("Default Build Tools Path"), & strDefaultBuildToolsPath))
341         {
342 #ifdef __WXMSW__
343             wxString gccExe(wxT("*-gcc.exe"));
344 #else
345             wxString gccExe(wxT("*-gcc"));
346 #endif
347             
348             // Note that this is not a recursive search. Compilers for
349             // different targets may be in the same directory. This finds all targets.
350             
351             // look for *-gcc[.exe] in the default build tools directory
352             wxLogNull log;
353             wxDir finder(strDefaultBuildToolsPath);
354             wxString filename;
355             
356             if (finder.IsOpened())
357             {
358                 bool bMore = finder.GetFirst(& filename, gccExe);
359                 while (bMore)
360                 {
361                     wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
362                     m_arstrBinDirs.Set(targetName, strDefaultBuildToolsPath);
363                     
364                     bMore = finder.GetNext(& filename);
365                 }
366             }
367         }
368     }
369 #endif
370
371 #ifndef __WXMSW__
372     // Look in the PATH for build tools, under Unix
373     {
374         wxString strPath;
375         if (wxGetEnv(wxT("PATH"), & strPath))
376         {
377             wxString gccExe(wxT("*-gcc"));
378
379             wxArrayString arstrPath;
380             ecUtils::Chop(strPath, arstrPath, wxT(':'));
381             
382             for (int i = arstrPath.GetCount()-1;i >= 0; --i)
383             { // Reverse order is important to treat path correctly
384                 wxLogNull log;
385                 wxDir finder(arstrPath[i]);
386                 wxString filename;
387             
388                 if (finder.IsOpened())
389                 {
390                     bool bMore = finder.GetFirst(& filename, gccExe);
391                     while (bMore)
392                     {
393                         wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
394                         m_arstrBinDirs.Set(targetName, arstrPath[i]);
395                     
396                         bMore = finder.GetNext(& filename);
397                     }
398                 }
399             }
400         }
401     }
402 #endif
403     
404     // Read build tools directories (current user)
405     
406     {
407         wxConfigPathChanger path(& config, wxT("/Build Tools/"));
408         //config.SetPath(wxT("/Build Tools"));
409         wxString key(wxT(""));
410         long index;
411         bool bMore = config.GetFirstEntry(key, index);
412         while (bMore)
413         {
414             wxString value;
415             if (config.Read(key, & value))
416             {
417                 m_arstrBinDirs.Set(key, value);
418             }
419             bMore = config.GetNextEntry(key, index);
420         }
421     }
422     
423     // Read toolchain paths (local machine again)
424 #ifdef __WXMSW__    
425     wxArrayString arstrToolChainPaths;
426     
427     // Use eCos just as a test.
428     //GetRepositoryRegistryClues(arstrToolChainPaths,_T("eCos"));
429     GetRepositoryRegistryClues(arstrToolChainPaths,_T("GNUPro eCos"));
430     
431     size_t i;
432     for (i = (size_t) 0; i < arstrToolChainPaths.GetCount(); i++)
433     {
434         ecFileName strDir(arstrToolChainPaths[i]);
435         strDir += wxT("H-i686-cygwin32\\bin");
436         
437         if (strDir.IsDir())
438         {
439             // This is a potential toolchain location. Look for *-gcc.exe
440             wxLogNull log;
441             wxDir finder(strDefaultBuildToolsPath);
442             wxString filename;
443             
444             if (finder.IsOpened())
445             {
446                 bool bMore = finder.GetFirst(& filename, wxT("*-gcc.exe"));
447                 while (bMore)
448                 {
449                     // TODO: if there is more than one path, we will have to
450                     // check the existance of this target name in m_arstrBinDirs and
451                     // append to the end, or something.
452                     wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
453                     m_arstrBinDirs.Set(targetName, strDefaultBuildToolsPath);
454                     
455                     bMore = finder.GetNext(& filename);
456                 }
457             }
458         }
459     }
460
461     // The official user tools are now Cygwin 00r1. If you can't find these,
462     // try GNUPro unsupported.
463     GetRepositoryRegistryClues(m_userToolPaths, wxT("GNUPro 00r1"));
464     if (m_userToolPaths.GetCount() == 0)
465     {
466         GetRepositoryRegistryClues(m_userToolPaths, wxT("Cygwin 00r1"));
467     }
468
469     if (m_userToolPaths.GetCount() > 0)
470     {
471         for ( i = (size_t) 0 ; i < m_userToolPaths.GetCount(); i++)
472         {
473             ecFileName str(m_userToolPaths[i]);
474             str += "H-i686-cygwin32\\bin";
475             if(str.IsDir())
476             {
477                 m_userToolPaths[i] = str;
478             } else
479             {
480                 m_userToolPaths.Remove(i);
481                 i--;
482             }
483         }
484     }
485     else
486     {
487         GetRepositoryRegistryClues(m_userToolPaths, wxT("GNUPro unsupported"));
488         
489         for ( i = (size_t) 0 ; i < m_userToolPaths.GetCount(); i++)
490         {
491             ecFileName str(m_userToolPaths[i]);
492             str += "H-i686-cygwin32\\bin";
493             if(str.IsDir())
494             {
495                 m_userToolPaths[i] = str;
496             } else
497             {
498                 m_userToolPaths.Remove(i);
499                 i--;
500             }
501         }
502     }
503 #endif
504     
505     // Include the path in the set of potential user paths
506     {
507         wxString strPath;
508         if (wxGetEnv(wxT("PATH"), & strPath))
509         {
510             wxArrayString arstrPath;
511             ecUtils::Chop(strPath, arstrPath, wxT(';'));
512             
513             for (int i = arstrPath.GetCount()-1;i >= 0; --i)
514             { // Reverse order is important to treat path correctly
515                 
516                 const ecFileName &strFolder = arstrPath[i];
517                 ecFileName strFile(strFolder);
518                 strFile += wxT("ls.exe");
519                 if ( strFile.Exists() )
520                 {
521                     if (!wxArrayStringIsMember(m_userToolPaths, strFolder))
522                     {
523                         m_userToolPaths.Add(strFolder);
524                     }
525                     
526                     if ( m_userToolsDir.IsEmpty() )
527                     {
528                         m_userToolsDir = strFolder;
529                     }
530                 }
531             }
532         }
533     }
534     
535     // Load current repository from eCos Configuration Tool/Paths/RepositoryDir
536     {
537         wxConfig eCosConfig(wxGetApp().GetSettings().GetConfigAppName(), wxEmptyString, wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_LOCAL_FILE);
538         wxConfigPathChanger path(& config, wxT("/Repository/"));
539
540         //if (!eCosConfig.Read(wxT("Folder"), & m_strRepository))
541         if (!eCosConfig.Read(wxT("/Paths/RepositoryDir"), & m_strRepository))
542         {
543 #ifdef __WXMSW__
544             // If we can't find the current folder, look for clues in the registry.
545             wxArrayString arstr;
546             switch (GetRepositoryRegistryClues(arstr, wxT("eCos")))
547             {
548             case 0:
549                 break;
550             case 1:
551             default:
552                 m_strRepository = arstr[0];
553                 break;
554             }
555 #elif defined(__WXGTK__)
556             // If we can't find the current folder, look for the latest version
557             // in /opt/ecos
558             m_strRepository = FindLatestVersion();
559 #else
560             // Unsupported platform
561             m_strRepositor = wxEmptyString;
562 #endif
563         }
564
565         // If we have set ECOS_REPOSITORY, this overrides whatever we have
566         // read or found.
567         wxString envVarValue = wxGetenv(wxT("ECOS_REPOSITORY"));
568         if (!envVarValue.IsEmpty())
569         {
570             // Note that ECOS_REPOSITORY has the packages (or ecc) folder in the name.
571             // In order to be in the form that is compatible with configtool operation,
572             // it needs to have that stripped off.
573             wxString packagesName = wxFileNameFromPath(envVarValue);
574             if (packagesName == wxT("ecc") || packagesName == wxT("packages"))
575                 envVarValue = wxPathOnly(envVarValue);
576
577             m_strRepository = envVarValue;
578         }
579     }
580
581 #ifdef __WXGTK__
582     if (m_userToolsDir.IsEmpty())
583         m_userToolsDir = wxT("/bin");
584 #endif
585     
586     return TRUE;
587 }
588
589 // Save config info
590 bool ecSettings::SaveConfig()
591 {
592     wxConfig config(wxGetApp().GetSettings().GetConfigAppName());
593     
594     config.Write(_("/Files/LastFile"), m_lastFilename);
595     
596     config.Write(_("/Window Status/FrameStatus"), (long) m_frameStatus);
597     config.Write(_("/Window Status/ShowToolBar"), m_showToolBar);
598     config.Write(_("/Window Status/ShowSplashScreen"), m_showSplashScreen);
599     config.Write(_("/Window Status/ShowConflictsWindow"), m_showConflictsWindow);
600     config.Write(_("/Window Status/ShowPropertiesWindow"), m_showPropertiesWindow);
601     config.Write(_("/Window Status/ShowShortDescrWindow"), m_showShortDescrWindow);
602     config.Write(_("/Window Status/ShowMemoryWindow"), m_showMemoryWindow);
603     config.Write(_("/Window Status/ShowOutputWindow"), m_showOutputWindow);
604     
605     config.Write(_("/Window Size/WindowX"), (long) m_frameSize.x);
606     config.Write(_("/Window Size/WindowY"), (long) m_frameSize.y);
607     config.Write(_("/Window Size/WindowWidth"), (long) m_frameSize.width);
608     config.Write(_("/Window Size/WindowHeight"), (long) m_frameSize.height);
609     config.Write(_("/Window Size/TreeSashWidth"), (long) m_treeSashSize.x);
610     config.Write(_("/Window Size/TreeSashHeight"), (long) m_treeSashSize.y);
611     config.Write(_("/Window Size/ConfigPaneWidth"), (long) m_configPaneWidth);
612     config.Write(_("/Window Size/ConflictsWidth"), (long) m_conflictsSashSize.x);
613     config.Write(_("/Window Size/ConflictsHeight"), (long) m_conflictsSashSize.y);
614     config.Write(_("/Window Size/PropertiesWidth"), (long) m_propertiesSashSize.x);
615     config.Write(_("/Window Size/PropertiesHeight"), (long) m_propertiesSashSize.y);
616     config.Write(_("/Window Size/ShortDescrWidth"), (long) m_shortDescrSashSize.x);
617     config.Write(_("/Window Size/ShortDescrHeight"), (long) m_shortDescrSashSize.y);
618     config.Write(_("/Window Size/OutputWidth"), (long) m_outputSashSize.x);
619     config.Write(_("/Window Size/OutputHeight"), (long) m_outputSashSize.y);
620     config.Write(_("/Window Size/MemoryWidth"), (long) m_memorySashSize.x);
621     config.Write(_("/Window Size/MemoryHeight"), (long) m_memorySashSize.y);
622     
623     config.Write(_("/Options/ShowMacroNames"), m_showMacroNames);
624     config.Write(_("/Options/UseCustomViewer"), m_bUseCustomViewer);
625     config.Write(_("/Options/UseExternalBrowser"), m_bUseExternalBrowser);
626     config.Write(_("/Options/UseCustomBrowser"), (long) m_eUseCustomBrowser);
627     config.Write(_("/Options/Browser"), m_strBrowser);
628     config.Write(_("/Options/Viewer"), m_strViewer);
629     config.Write(_("/Options/HexDisplay"), m_bHex);
630     config.Write(_("/Options/UseDefaultFonts"), m_windowSettings.m_useDefaults);
631
632     config.Write(_("/Rule/Checking"), (long) m_nRuleChecking);
633     
634     config.Write(_("/Paths/UserToolsDir"), m_userToolsDir);
635     config.Write(_("/Paths/BuildToolsDir"), m_buildToolsDir);
636     
637     config.Write(_("/Build/Make Options"), m_strMakeOptions);
638
639     // Find dialog settings
640     config.Write(_("/Find/Text"), m_findText);
641     config.Write(_("/Find/MatchWholeWord"), m_findMatchWholeWord);
642     config.Write(_("/Find/MatchCase"), m_findMatchCase);
643     config.Write(_("/Find/Direction"), m_findDirection);
644     config.Write(_("/Find/SearchWhat"), m_findSearchWhat);
645     config.Write(_("/Find/DialogX"), (long) m_findDialogPos.x);
646     config.Write(_("/Find/DialogY"), (long) m_findDialogPos.y);
647     
648     // Package dialog settings
649     config.Write(_("/Packages/OmitHardwarePackages"), m_omitHardwarePackages);
650     config.Write(_("/Packages/MatchPackageNamesExactly"), m_matchPackageNamesExactly);
651
652     // Save current repository to eCos Configuration Tool/Paths/RepositoryDir
653     // UNLESS it was overridden by ECOS_REPOSITORY
654     {
655         wxString envVarValue = wxGetenv(wxT("ECOS_REPOSITORY"));
656         if (m_strRepository == envVarValue)
657         {
658             // Don't override the value in the local settings
659         }
660         else
661             config.Write(wxT("/Paths/RepositoryDir"), m_strRepository);
662     }
663     
664     // Run tests settings
665     m_runTestsSettings.SaveConfig(config);
666
667     // Fonts
668     m_windowSettings.SaveConfig(config);
669     
670     return TRUE;
671 }
672
673 void ecSettings::ShowSettingsDialog(const wxString& page)
674 {
675 #if 0
676     ecSettingsDialog* dialog = new ecSettingsDialog(wxGetApp().GetTopWindow());
677     if (!page.IsEmpty())
678         dialog->GetNotebook()->SetSelection(ecFindNotebookPage(dialog->GetNotebook(), page));
679     
680     int ret = dialog->ShowModal();
681     dialog->Destroy();
682 #endif
683 }
684
685 #ifndef MAX_PATH
686 #define MAX_PATH 1024
687 #endif
688
689 // TODO for non-Windows platforms
690 const ecFileName& ecSettings::DefaultExternalBrowser()
691 {
692 #ifdef __WXMSW__
693     static bool bFirstTime=TRUE;
694     if(bFirstTime){
695         const ecFileName strFile(ecFileName::GetTempPath()+wxT("index.html"));
696         wxFile f;
697         if(f.Create(strFile, TRUE))
698         {
699             f.Close();
700             bool rc=((int)  ::FindExecutable(strFile,wxT("."),m_strDefaultExternalBrowser.GetWriteBuf(MAX_PATH))>32);
701             m_strDefaultExternalBrowser.UngetWriteBuf();
702             if(!rc){
703                 m_strDefaultExternalBrowser=wxT("");
704             }
705             wxRemoveFile(strFile);
706         }
707         bFirstTime=FALSE;
708     }
709 #endif
710     return m_strDefaultExternalBrowser;
711 }
712
713 ecFileName ecSettings::m_strDefaultExternalBrowser;
714
715 // Go looking for potential candidates in SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
716 int ecSettings::GetRepositoryRegistryClues(wxArrayString& arstr, const wxString& pszPrefix)
717 {
718     arstr.Clear();
719
720 #ifdef __WXMSW__
721     wxConfig config(wxT("Windows"), wxT("Microsoft"), wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE);
722     config.SetPath(wxT("/CurrentVersion/App Paths"));
723
724     wxString key(wxT(""));
725     long index;
726     bool bMore = config.GetFirstGroup(key, index);
727     while (bMore)
728     {
729         if (key.Find(pszPrefix) == 0)
730         {
731             wxString value;
732             //wxString key2(wxString(wxT("/")) + key + wxString(wxT("/Path")));
733             wxString key2(key + wxString(wxT("/Path")));
734             if (config.Read(key2, & value))
735             {
736                 arstr.Add(value);
737             }
738         }
739         bMore = config.GetNextGroup(key, index);
740     }
741     return arstr.GetCount();
742 #else
743     return 0;
744 #endif
745 }
746
747 // Finds the path of the latest installed eCos
748 wxString ecSettings::FindLatestVersion()
749 {
750 #ifdef __WXGTK__
751     wxString ecosRoot(wxT("/opt/ecos"));
752     wxLogNull log;
753     wxDir dir(ecosRoot);
754     
755     wxString latestDir;
756     wxString latestVersion;
757     
758     if (dir.IsOpened())
759     {
760         wxString filename;
761         bool cont = dir.GetFirst(& filename, wxT("ecos-*"), wxDIR_DIRS);
762         while (cont)
763         {
764             wxString ver(filename.Mid(5));
765             if (latestVersion.IsEmpty() || latestVersion.CompareTo(ver) < 0)
766             {
767                 latestVersion = ver;
768                 latestDir = ecosRoot + wxT("/") + filename;
769             }
770             
771             cont = dir.GetNext(& filename);
772         }
773     }
774     if (latestDir.IsEmpty())
775         latestDir = wxGetCwd();
776     return latestDir;
777 #else
778     wxMessageBox(wxT("FindLatestVersion() is only implemented for Unix."));
779     return wxEmptyString;
780 #endif
781 }
782
783 wxString ecSettings::GetInstallVersionKey ()
784 {
785 #ifdef __WXMSW__
786
787 #ifndef MAX_PATH
788 #define MAX_PATH 1024
789 #endif
790
791     wxString strKey = wxT("SOFTWARE\\eCos");
792     wxString strVersionKey = wxT("");
793     wxString rc = wxT("");
794     wxChar pszBuffer [MAX_PATH + 1];
795     HKEY hKey;
796     
797     // get the greatest eCos version subkey
798     if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) {
799         DWORD dwIndex = 0;
800         while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) {
801             if (strVersionKey.CompareTo (pszBuffer) < 0) {
802                 strVersionKey = pszBuffer;
803             }
804         }
805         RegCloseKey (hKey);
806     }
807     return strVersionKey;
808 #else
809     wxMessageBox(wxT("GetInstallVersionKey() is only implemented for Windows."));
810     return wxEmptyString;
811 #endif
812 }
813
814 /*
815  * ecRunTestSettings
816  * Settings relating to running tests
817  */
818
819 IMPLEMENT_DYNAMIC_CLASS(ecRunTestsSettings, wxObject)
820
821 ecRunTestsSettings::ecRunTestsSettings():
822     m_ep(CeCosTest::ExecutionParameters::RUN),
823     m_nTimeout(900),
824     m_nDownloadTimeout(120),
825     m_nTimeoutType(TIMEOUT_AUTOMATIC),
826     m_nDownloadTimeoutType(TIMEOUT_SPECIFIED),
827     m_bRemote(FALSE),
828     m_bSerial(TRUE),
829     m_strPort(wxT("COM1")),
830     m_nBaud(38400),
831     m_nLocalTCPIPPort(1),
832     m_nReset(RESET_MANUAL),
833     m_nResourcePort(1),
834     m_nRemotePort(1),
835     m_bFarmed(TRUE),
836     m_strRemoteHost(wxT("")),
837     m_strResourceHost(wxT("")),
838     m_strLocalTCPIPHost(wxT("")),
839     m_strReset(wxT(""))
840 {
841 }
842
843 ecRunTestsSettings::ecRunTestsSettings(const ecRunTestsSettings& settings)
844 {
845     Copy(settings);
846 }
847
848 void ecRunTestsSettings::Copy(const ecRunTestsSettings& settings)
849 {
850     m_nTimeoutType = settings.m_nTimeoutType;
851     m_nDownloadTimeoutType = settings.m_nDownloadTimeoutType;
852     m_bRemote = settings.m_bRemote;
853     m_bSerial = settings.m_bSerial;
854     m_strPort = settings.m_strPort;
855     m_nBaud = settings.m_nBaud;
856     m_nLocalTCPIPPort = settings.m_nLocalTCPIPPort;
857     m_nReset = settings.m_nReset;
858     m_nResourcePort = settings.m_nResourcePort;
859     m_nRemotePort = settings.m_nRemotePort;
860     m_bFarmed = settings.m_bFarmed;
861     m_strTarget = settings.m_strTarget;
862     m_strRemoteHost = settings.m_strRemoteHost;
863     m_strResourceHost = settings.m_strResourceHost;
864     m_strLocalTCPIPHost = settings.m_strLocalTCPIPHost;
865     m_strReset = settings.m_strReset;
866 }
867
868 bool ecRunTestsSettings::LoadConfig(wxConfig& config)
869 {
870     config.Read(_("/Run Tests/TimeoutType"), & m_nTimeoutType);
871     config.Read(_("/Run Tests/DownloadTimeoutType"), & m_nDownloadTimeoutType);
872     config.Read(_("/Run Tests/Remote"), (bool*) & m_bRemote);
873     config.Read(_("/Run Tests/Serial"), (bool*) & m_bSerial);
874     config.Read(_("/Run Tests/Port"), & m_strPort);
875     config.Read(_("/Run Tests/Baud"), & m_nBaud);
876     config.Read(_("/Run Tests/LocalTCPIPHost"), & m_strLocalTCPIPHost);
877     config.Read(_("/Run Tests/LocalTCPIPPort"), & m_nLocalTCPIPPort);
878 //  Reset type is determined at run-time for standalone configtool
879 //    config.Read(_("/Run Tests/ResetType"), & m_nReset);
880     config.Read(_("/Run Tests/ResetString"), & m_strReset);
881     config.Read(_("/Run Tests/ResourceHost"), & m_strResourceHost);
882     config.Read(_("/Run Tests/ResourcePort"), & m_nResourcePort);
883     config.Read(_("/Run Tests/RemoteHost"), & m_strRemoteHost);
884     config.Read(_("/Run Tests/RemotePort"), & m_nRemotePort);
885     config.Read(_("/Run Tests/Farmed"), (bool*) & m_bFarmed);
886
887     return TRUE;
888 }
889
890 bool ecRunTestsSettings::SaveConfig(wxConfig& config)
891 {
892     config.Write(_("/Run Tests/TimeoutType"), (long) m_nTimeoutType);
893     config.Write(_("/Run Tests/DownloadTimeoutType"), (long) m_nDownloadTimeoutType);
894     config.Write(_("/Run Tests/Remote"), m_bRemote);
895     config.Write(_("/Run Tests/Serial"), m_bSerial);
896     config.Write(_("/Run Tests/Port"), m_strPort);
897     config.Write(_("/Run Tests/Baud"), (long) m_nBaud);
898     config.Write(_("/Run Tests/LocalTCPIPHost"), m_strLocalTCPIPHost);
899     config.Write(_("/Run Tests/LocalTCPIPPort"), (long) m_nLocalTCPIPPort);
900     config.Write(_("/Run Tests/ResetType"), (long) m_nReset);
901     config.Write(_("/Run Tests/ResetString"), m_strReset);
902     config.Write(_("/Run Tests/ResourceHost"), m_strResourceHost);
903     config.Write(_("/Run Tests/ResourcePort"), (long) m_nResourcePort);
904     config.Write(_("/Run Tests/RemoteHost"), m_strRemoteHost);
905     config.Write(_("/Run Tests/RemotePort"), (long) m_nRemotePort);
906     config.Write(_("/Run Tests/Farmed"), m_bFarmed);
907
908     return TRUE;
909 }
910