1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 // Copyright (C) 2003 John Dallaway
7 // This program is part of the eCos host tools.
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)
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
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.
23 // ----------------------------------------------------------------------------
25 //####COPYRIGHTEND####
28 //===========================================================================
29 //#####DESCRIPTIONBEGIN####
31 // Author(s): julians, jld
32 // Contact(s): julians
36 // Description: Implementation file for the ecSettings
43 //####DESCRIPTIONEND####
45 //===========================================================================
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 #pragma implementation "appsettings.h"
58 // Includes other headers for precompiled compilation
65 #include "wx/config.h"
68 #include "appsettings.h"
69 #include "configtree.h"
70 #include "outputwin.h"
71 #include "shortdescrwin.h"
77 #include "wx/msw/winundef.h"
84 * User-changeable and other settings to be saved between sessions
87 IMPLEMENT_DYNAMIC_CLASS(ecSettings, wxObject)
89 ecSettings::ecSettings()
92 m_frameSize = wxRect(0, 0, 600, 500);
93 m_appName = _("eCos Configuration Tool");
94 m_showSplashScreen = TRUE;
95 m_userName = wxEmptyString;
97 m_frameStatus = ecSHOW_STATUS_NORMAL;
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;
107 m_showConflictsWindow = FALSE;
108 m_showPropertiesWindow = TRUE;
109 m_showShortDescrWindow = TRUE;
110 m_showMemoryWindow = FALSE;
111 m_showOutputWindow = TRUE;
113 m_showMacroNames = FALSE;
115 m_bUseCustomViewer = FALSE;
116 m_bUseExternalBrowser = FALSE;
117 m_eUseCustomBrowser = ecAssociatedExternal;
119 m_nRuleChecking = Immediate|Deferred|SuggestFixes ;
122 m_strViewer = wxT("notepad");
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);
133 m_editSaveFileOnly = FALSE;
135 // Packages dialog settings
136 m_omitHardwarePackages = FALSE;
137 m_matchPackageNamesExactly = FALSE;
141 ecSettings::ecSettings(const ecSettings& settings)
146 void ecSettings::Copy(const ecSettings& settings)
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;
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;
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;
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;
176 // Run tests settings
177 m_runTestsSettings = settings.m_runTestsSettings;
179 m_userToolsDir = settings.m_userToolsDir;
180 m_buildToolsDir = settings.m_buildToolsDir;
182 m_editSaveFileOnly = settings.m_editSaveFileOnly;
184 // Packages dialog settings
185 m_omitHardwarePackages = settings.m_omitHardwarePackages;
186 m_matchPackageNamesExactly = settings.m_matchPackageNamesExactly;
189 ecSettings::~ecSettings()
193 // Do some initialisation within ecApp::OnInit
194 bool ecSettings::Init()
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
204 return wxString(wxT("eCosConfigTool"));
211 // Create new filename
212 wxString ecSettings::GenerateFilename(const wxString& rootName)
215 if (!m_lastFilename.IsEmpty())
216 path = wxPathOnly(m_lastFilename);
218 // path = wxGetApp().GetAppDir();
221 wxString filename(path);
222 if (filename.Last() != wxFILE_SEP_PATH )
223 filename += wxFILE_SEP_PATH;
224 filename += rootName;
226 wxString fullFilename = filename + wxT(".ecc");
229 while (wxFileExists(fullFilename))
232 postfixStr.Printf("%d", i);
233 fullFilename = filename + postfixStr + wxT(".ecc");
236 m_lastFilename = fullFilename;
241 bool ecSettings::LoadConfig()
243 wxConfig config(wxGetApp().GetSettings().GetConfigAppName());
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);
254 config.Read(_("/Files/LastFile"), & m_lastFilename);
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);
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);
275 config.Read(_("/Options/ShowMacroNames"), (bool*) & m_showMacroNames);
276 config.Read(_("/Options/UseCustomViewer"), (bool*) & m_bUseCustomViewer);
277 config.Read(_("/Options/UseExternalBrowser"), (bool*) & m_bUseExternalBrowser);
279 int tmp = (int) m_eUseCustomBrowser;
280 config.Read(_("/Options/UseCustomBrowser"), & tmp);
281 m_eUseCustomBrowser = (ecBrowserType) tmp;
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);
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);
298 // Package dialog settings
299 config.Read(_("/Packages/OmitHardwarePackages"), & m_omitHardwarePackages);
300 config.Read(_("/Packages/MatchPackageNamesExactly"), & m_matchPackageNamesExactly);
302 // Run tests settings
303 m_runTestsSettings.LoadConfig(config);
306 m_windowSettings.LoadConfig(config);
308 if (!config.Read(_("/Paths/UserToolsDir"), & m_userToolsDir))
310 // Use the default provided by the installer
311 config.Read(_("Default User Tools Path"), & m_userToolsDir);
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 if (m_buildToolsDir.IsEmpty()) // first invocation by this user
319 // we have no clues as to the location of the build tools so
320 // test for ../../../gnutools relative to the configtool location
321 wxFileName gnutools = wxFileName (wxGetApp().GetAppDir(), wxEmptyString);
322 gnutools.Normalize(); // remove trailing "./" if present
323 if (2 < gnutools.GetDirCount())
325 gnutools.RemoveDir (gnutools.GetDirCount()-1);
326 gnutools.RemoveDir (gnutools.GetDirCount()-1);
327 gnutools.RemoveDir (gnutools.GetDirCount()-1);
328 gnutools.AppendDir (wxT("gnutools"));
329 if (gnutools.DirExists()) // we've found the gnutools
330 m_buildToolsDir = gnutools.GetFullPath();
334 // look for *objcopy in and under the build tools directory
335 if (! m_buildToolsDir.IsEmpty())
337 wxArrayString objcopyFiles;
338 wxString objcopyFileSpec(wxT("objcopy"));
340 objcopyFileSpec += wxT(".exe");
342 size_t objcopyCount = wxDir::GetAllFiles(m_buildToolsDir, &objcopyFiles, wxT("*") + objcopyFileSpec, wxDIR_FILES | wxDIR_DIRS);
343 for (int count=0; count < objcopyCount; count++)
345 wxFileName file (objcopyFiles [count]);
346 wxString new_prefix (file.GetFullName().Left (file.GetFullName().Find(objcopyFileSpec)));
347 if ((! new_prefix.IsEmpty()) && ('-' == new_prefix.Last()))
348 new_prefix = new_prefix.Left (new_prefix.Len() - 1); // strip off trailing hyphen
349 m_arstrBinDirs.Set(new_prefix, file.GetPath(wxPATH_GET_VOLUME));
353 if (!config.Read(_("/Build/Make Options"), & m_strMakeOptions))
356 SYSTEM_INFO SystemInfo;
357 GetSystemInfo(&SystemInfo);
358 // disable -j option for now due to problem with Cygwin 1.3.18
359 // m_strMakeOptions.Printf(_T("-j%d"),SystemInfo.dwNumberOfProcessors);
363 // Set default build tools binary directories as specified by the installer
364 ecFileName strDefaultBuildToolsPath;
368 // This should look in HKEY_LOCAL_MACHINE
370 wxConfig config2(wxT("eCos"), wxEmptyString, wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_LOCAL_FILE);
372 wxString versionKey = GetInstallVersionKey();
373 wxConfigPathChanger path(& config2, wxString(wxT("/")) + versionKey + wxT("/"));
375 if (!versionKey.IsEmpty() && config2.Read(wxT("Default Build Tools Path"), & strDefaultBuildToolsPath))
378 wxString gccExe(wxT("*-gcc.exe"));
380 wxString gccExe(wxT("*-gcc"));
383 // Note that this is not a recursive search. Compilers for
384 // different targets may be in the same directory. This finds all targets.
386 // look for *-gcc[.exe] in the default build tools directory
388 wxDir finder(strDefaultBuildToolsPath);
391 if (finder.IsOpened())
393 bool bMore = finder.GetFirst(& filename, gccExe);
396 wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
397 m_arstrBinDirs.Set(targetName, strDefaultBuildToolsPath);
399 bMore = finder.GetNext(& filename);
407 // Look in the PATH for build tools, under Unix
410 if (wxGetEnv(wxT("PATH"), & strPath))
412 wxString gccExe(wxT("*-gcc"));
414 wxArrayString arstrPath;
415 ecUtils::Chop(strPath, arstrPath, wxT(':'));
417 for (int i = arstrPath.GetCount()-1;i >= 0; --i)
418 { // Reverse order is important to treat path correctly
419 if (wxT(".") != arstrPath[i] && !arstrPath[i].IsEmpty())
422 wxDir finder(arstrPath[i]);
425 if (finder.IsOpened())
427 bool bMore = finder.GetFirst(& filename, gccExe);
430 wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
431 m_arstrBinDirs.Set(targetName, arstrPath[i]);
433 bMore = finder.GetNext(& filename);
442 // Read build tools directories (current user)
445 wxConfigPathChanger path(& config, wxT("/Build Tools/"));
446 //config.SetPath(wxT("/Build Tools"));
447 wxString key(wxT(""));
449 bool bMore = config.GetFirstEntry(key, index);
453 if (config.Read(key, & value))
455 m_arstrBinDirs.Set(key, value);
457 bMore = config.GetNextEntry(key, index);
461 // Read toolchain paths (local machine again)
463 wxArrayString arstrToolChainPaths;
465 // Use eCos just as a test.
466 //GetRepositoryRegistryClues(arstrToolChainPaths,_T("eCos"));
467 GetRepositoryRegistryClues(arstrToolChainPaths,_T("GNUPro eCos"));
470 for (i = (size_t) 0; i < arstrToolChainPaths.GetCount(); i++)
472 ecFileName strDir(arstrToolChainPaths[i]);
473 strDir += wxT("H-i686-cygwin32\\bin");
477 // This is a potential toolchain location. Look for *-gcc.exe
479 wxDir finder(strDefaultBuildToolsPath);
482 if (finder.IsOpened())
484 bool bMore = finder.GetFirst(& filename, wxT("*-gcc.exe"));
487 // TODO: if there is more than one path, we will have to
488 // check the existance of this target name in m_arstrBinDirs and
489 // append to the end, or something.
490 wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
491 m_arstrBinDirs.Set(targetName, strDefaultBuildToolsPath);
493 bMore = finder.GetNext(& filename);
499 // The official user tools are now Cygwin 00r1. If you can't find these,
500 // try GNUPro unsupported.
501 GetRepositoryRegistryClues(m_userToolPaths, wxT("GNUPro 00r1"));
502 if (m_userToolPaths.GetCount() == 0)
504 GetRepositoryRegistryClues(m_userToolPaths, wxT("Cygwin 00r1"));
507 if (m_userToolPaths.GetCount() > 0)
509 for ( i = (size_t) 0 ; i < m_userToolPaths.GetCount(); i++)
511 ecFileName str(m_userToolPaths[i]);
512 str += "H-i686-cygwin32\\bin";
515 m_userToolPaths[i] = str;
518 m_userToolPaths.Remove(i);
525 GetRepositoryRegistryClues(m_userToolPaths, wxT("GNUPro unsupported"));
527 for ( i = (size_t) 0 ; i < m_userToolPaths.GetCount(); i++)
529 ecFileName str(m_userToolPaths[i]);
530 str += "H-i686-cygwin32\\bin";
533 m_userToolPaths[i] = str;
536 m_userToolPaths.Remove(i);
543 // Include the path in the set of potential user paths
546 if (wxGetEnv(wxT("PATH"), & strPath))
548 wxArrayString arstrPath;
549 ecUtils::Chop(strPath, arstrPath, wxT(';'));
551 for (int i = arstrPath.GetCount()-1;i >= 0; --i)
552 { // Reverse order is important to treat path correctly
554 const ecFileName &strFolder = arstrPath[i];
555 if (wxT(".") != strFolder && !strFolder.IsEmpty())
557 ecFileName strFile(strFolder);
558 strFile += wxT("ls.exe");
559 if ( strFile.Exists() )
561 if (!wxArrayStringIsMember(m_userToolPaths, strFolder))
563 m_userToolPaths.Add(strFolder);
566 if ( m_userToolsDir.IsEmpty() )
568 m_userToolsDir = strFolder;
576 // Load current repository from eCos Configuration Tool/Paths/RepositoryDir
578 wxConfig eCosConfig(wxGetApp().GetSettings().GetConfigAppName(), wxEmptyString, wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_LOCAL_FILE);
579 wxConfigPathChanger path(& config, wxT("/Repository/"));
581 //if (!eCosConfig.Read(wxT("Folder"), & m_strRepository))
582 if (!eCosConfig.Read(wxT("/Paths/RepositoryDir"), & m_strRepository))
585 // If we can't find the current folder, look for clues in the registry.
587 switch (GetRepositoryRegistryClues(arstr, wxT("eCos")))
593 m_strRepository = arstr[0];
596 #elif defined(__WXGTK__)
597 // If we can't find the current folder, look for the latest version
599 m_strRepository = FindLatestVersion();
601 // Unsupported platform
602 m_strRepositor = wxEmptyString;
606 // If we have set ECOS_REPOSITORY, this overrides whatever we have
608 wxString envVarValue = wxGetenv(wxT("ECOS_REPOSITORY"));
609 if (!envVarValue.IsEmpty())
611 // Note that ECOS_REPOSITORY has the packages (or ecc) folder in the name.
612 // In order to be in the form that is compatible with configtool operation,
613 // it needs to have that stripped off.
614 envVarValue = ecUtils::PosixToNativePath(envVarValue); // accommodate posix-style ECOS_REPOSITORY value under Cygwin
615 wxString packagesName = wxFileNameFromPath(envVarValue);
616 if (packagesName == wxT("ecc") || packagesName == wxT("packages"))
617 envVarValue = wxPathOnly(envVarValue);
619 m_strRepository = envVarValue;
624 if (m_userToolsDir.IsEmpty())
625 m_userToolsDir = GetCygwinInstallPath() + wxT("\\bin");
627 if (m_userToolsDir.IsEmpty())
628 m_userToolsDir = wxT("/bin");
635 wxString ecSettings::GetCygwinInstallPath()
640 DWORD sz = sizeof(value);
641 wxString strCygwinInstallPath;
643 // look for the "/" mount point in the system registry settings
644 if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/", 0, KEY_READ, &hKey)) {
645 if (ERROR_SUCCESS == RegQueryValueEx(hKey, "native", NULL, & type, value, & sz)) {
646 strCygwinInstallPath = (const char*) value;
651 // if not yet found, look for the "/" mount point in the user's registry settings
654 if (strCygwinInstallPath.IsEmpty() && (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/", 0, KEY_READ, &hKey))) {
655 if (ERROR_SUCCESS == RegQueryValueEx(hKey, "native", NULL, & type, value, & sz)) {
656 strCygwinInstallPath = (const char*) value;
661 return strCygwinInstallPath;
666 bool ecSettings::SaveConfig()
668 wxConfig config(wxGetApp().GetSettings().GetConfigAppName());
670 config.Write(_("/Files/LastFile"), m_lastFilename);
672 config.Write(_("/Window Status/FrameStatus"), (long) m_frameStatus);
673 config.Write(_("/Window Status/ShowToolBar"), m_showToolBar);
674 config.Write(_("/Window Status/ShowSplashScreen"), m_showSplashScreen);
675 config.Write(_("/Window Status/ShowConflictsWindow"), m_showConflictsWindow);
676 config.Write(_("/Window Status/ShowPropertiesWindow"), m_showPropertiesWindow);
677 config.Write(_("/Window Status/ShowShortDescrWindow"), m_showShortDescrWindow);
678 config.Write(_("/Window Status/ShowMemoryWindow"), m_showMemoryWindow);
679 config.Write(_("/Window Status/ShowOutputWindow"), m_showOutputWindow);
681 config.Write(_("/Window Size/WindowX"), (long) m_frameSize.x);
682 config.Write(_("/Window Size/WindowY"), (long) m_frameSize.y);
683 config.Write(_("/Window Size/WindowWidth"), (long) m_frameSize.width);
684 config.Write(_("/Window Size/WindowHeight"), (long) m_frameSize.height);
685 config.Write(_("/Window Size/TreeSashWidth"), (long) m_treeSashSize.x);
686 config.Write(_("/Window Size/TreeSashHeight"), (long) m_treeSashSize.y);
687 config.Write(_("/Window Size/ConfigPaneWidth"), (long) m_configPaneWidth);
688 config.Write(_("/Window Size/ConflictsWidth"), (long) m_conflictsSashSize.x);
689 config.Write(_("/Window Size/ConflictsHeight"), (long) m_conflictsSashSize.y);
690 config.Write(_("/Window Size/PropertiesWidth"), (long) m_propertiesSashSize.x);
691 config.Write(_("/Window Size/PropertiesHeight"), (long) m_propertiesSashSize.y);
692 config.Write(_("/Window Size/ShortDescrWidth"), (long) m_shortDescrSashSize.x);
693 config.Write(_("/Window Size/ShortDescrHeight"), (long) m_shortDescrSashSize.y);
694 config.Write(_("/Window Size/OutputWidth"), (long) m_outputSashSize.x);
695 config.Write(_("/Window Size/OutputHeight"), (long) m_outputSashSize.y);
696 config.Write(_("/Window Size/MemoryWidth"), (long) m_memorySashSize.x);
697 config.Write(_("/Window Size/MemoryHeight"), (long) m_memorySashSize.y);
699 config.Write(_("/Options/ShowMacroNames"), m_showMacroNames);
700 config.Write(_("/Options/UseCustomViewer"), m_bUseCustomViewer);
701 config.Write(_("/Options/UseExternalBrowser"), m_bUseExternalBrowser);
702 config.Write(_("/Options/UseCustomBrowser"), (long) m_eUseCustomBrowser);
703 config.Write(_("/Options/Browser"), m_strBrowser);
704 config.Write(_("/Options/Viewer"), m_strViewer);
705 config.Write(_("/Options/HexDisplay"), m_bHex);
706 config.Write(_("/Options/UseDefaultFonts"), m_windowSettings.m_useDefaults);
708 config.Write(_("/Rule/Checking"), (long) m_nRuleChecking);
710 config.Write(_("/Paths/UserToolsDir"), m_userToolsDir);
711 config.Write(_("/Paths/BuildToolsDir"), m_buildToolsDir);
713 config.Write(_("/Build/Make Options"), m_strMakeOptions);
715 // Find dialog settings
716 config.Write(_("/Find/Text"), m_findText);
717 config.Write(_("/Find/MatchWholeWord"), m_findMatchWholeWord);
718 config.Write(_("/Find/MatchCase"), m_findMatchCase);
719 config.Write(_("/Find/Direction"), m_findDirection);
720 config.Write(_("/Find/SearchWhat"), m_findSearchWhat);
721 config.Write(_("/Find/DialogX"), (long) m_findDialogPos.x);
722 config.Write(_("/Find/DialogY"), (long) m_findDialogPos.y);
724 // Package dialog settings
725 config.Write(_("/Packages/OmitHardwarePackages"), m_omitHardwarePackages);
726 config.Write(_("/Packages/MatchPackageNamesExactly"), m_matchPackageNamesExactly);
728 // Save current repository to eCos Configuration Tool/Paths/RepositoryDir
729 // UNLESS it was overridden by ECOS_REPOSITORY
731 wxString envVarValue = wxGetenv(wxT("ECOS_REPOSITORY"));
732 if (m_strRepository == envVarValue)
734 // Don't override the value in the local settings
737 config.Write(wxT("/Paths/RepositoryDir"), m_strRepository);
740 // Run tests settings
741 m_runTestsSettings.SaveConfig(config);
744 m_windowSettings.SaveConfig(config);
749 void ecSettings::ShowSettingsDialog(const wxString& page)
752 ecSettingsDialog* dialog = new ecSettingsDialog(wxGetApp().GetTopWindow());
754 dialog->GetNotebook()->SetSelection(ecFindNotebookPage(dialog->GetNotebook(), page));
756 int ret = dialog->ShowModal();
762 #define MAX_PATH 1024
765 // TODO for non-Windows platforms
766 const ecFileName& ecSettings::DefaultExternalBrowser()
769 static bool bFirstTime=TRUE;
771 const ecFileName strFile(ecFileName::GetTempPath()+wxT("index.html"));
773 if(f.Create(strFile, TRUE))
776 bool rc=((int) ::FindExecutable(strFile,wxT("."),m_strDefaultExternalBrowser.GetWriteBuf(MAX_PATH))>32);
777 m_strDefaultExternalBrowser.UngetWriteBuf();
779 m_strDefaultExternalBrowser=wxT("");
781 wxRemoveFile(strFile);
786 return m_strDefaultExternalBrowser;
789 ecFileName ecSettings::m_strDefaultExternalBrowser;
791 // Go looking for potential candidates in SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
792 int ecSettings::GetRepositoryRegistryClues(wxArrayString& arstr, const wxString& pszPrefix)
797 wxConfig config(wxT("Windows"), wxT("Microsoft"), wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE);
798 config.SetPath(wxT("/CurrentVersion/App Paths"));
800 wxString key(wxT(""));
802 bool bMore = config.GetFirstGroup(key, index);
805 if (key.Find(pszPrefix) == 0)
808 //wxString key2(wxString(wxT("/")) + key + wxString(wxT("/Path")));
809 wxString key2(key + wxString(wxT("/Path")));
810 if (config.Read(key2, & value))
815 bMore = config.GetNextGroup(key, index);
817 return arstr.GetCount();
823 // Finds the path of the latest installed eCos
824 wxString ecSettings::FindLatestVersion()
827 wxString ecosRoot(wxT("/opt/ecos"));
832 wxString latestVersion;
837 bool cont = dir.GetFirst(& filename, wxT("ecos-*"), wxDIR_DIRS);
840 wxString ver(filename.Mid(5));
841 if (latestVersion.IsEmpty() || latestVersion.CompareTo(ver) < 0)
844 latestDir = ecosRoot + wxT("/") + filename;
847 cont = dir.GetNext(& filename);
850 // if (latestDir.IsEmpty())
851 // latestDir = wxGetCwd();
854 wxMessageBox(wxT("FindLatestVersion() is only implemented for Unix."));
855 return wxEmptyString;
859 wxString ecSettings::GetInstallVersionKey ()
864 #define MAX_PATH 1024
867 wxString strKey = wxT("SOFTWARE\\eCos");
868 wxString strVersionKey = wxT("");
869 wxString rc = wxT("");
870 wxChar pszBuffer [MAX_PATH + 1];
873 // get the greatest eCos version subkey
874 if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) {
876 while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) {
877 if (strVersionKey.CompareTo (pszBuffer) < 0) {
878 strVersionKey = pszBuffer;
883 return strVersionKey;
885 wxMessageBox(wxT("GetInstallVersionKey() is only implemented for Windows."));
886 return wxEmptyString;
892 * Settings relating to running tests
895 IMPLEMENT_DYNAMIC_CLASS(ecRunTestsSettings, wxObject)
897 ecRunTestsSettings::ecRunTestsSettings():
898 m_ep(CeCosTest::ExecutionParameters::RUN),
900 m_nDownloadTimeout(120),
901 m_nTimeoutType(TIMEOUT_AUTOMATIC),
902 m_nDownloadTimeoutType(TIMEOUT_SPECIFIED),
905 m_strPort(wxT("COM1")),
907 m_nLocalTCPIPPort(1),
908 m_nReset(RESET_MANUAL),
912 m_strRemoteHost(wxT("")),
913 m_strResourceHost(wxT("")),
914 m_strLocalTCPIPHost(wxT("")),
919 ecRunTestsSettings::ecRunTestsSettings(const ecRunTestsSettings& settings)
924 void ecRunTestsSettings::Copy(const ecRunTestsSettings& settings)
926 m_nTimeoutType = settings.m_nTimeoutType;
927 m_nDownloadTimeoutType = settings.m_nDownloadTimeoutType;
928 m_bRemote = settings.m_bRemote;
929 m_bSerial = settings.m_bSerial;
930 m_strPort = settings.m_strPort;
931 m_nBaud = settings.m_nBaud;
932 m_nLocalTCPIPPort = settings.m_nLocalTCPIPPort;
933 m_nReset = settings.m_nReset;
934 m_nResourcePort = settings.m_nResourcePort;
935 m_nRemotePort = settings.m_nRemotePort;
936 m_bFarmed = settings.m_bFarmed;
937 m_strTarget = settings.m_strTarget;
938 m_strRemoteHost = settings.m_strRemoteHost;
939 m_strResourceHost = settings.m_strResourceHost;
940 m_strLocalTCPIPHost = settings.m_strLocalTCPIPHost;
941 m_strReset = settings.m_strReset;
944 bool ecRunTestsSettings::LoadConfig(wxConfig& config)
946 config.Read(_("/Run Tests/TimeoutType"), & m_nTimeoutType);
947 config.Read(_("/Run Tests/DownloadTimeoutType"), & m_nDownloadTimeoutType);
948 config.Read(_("/Run Tests/Remote"), (bool*) & m_bRemote);
949 config.Read(_("/Run Tests/Serial"), (bool*) & m_bSerial);
950 config.Read(_("/Run Tests/Port"), & m_strPort);
951 config.Read(_("/Run Tests/Baud"), & m_nBaud);
952 config.Read(_("/Run Tests/LocalTCPIPHost"), & m_strLocalTCPIPHost);
953 config.Read(_("/Run Tests/LocalTCPIPPort"), & m_nLocalTCPIPPort);
954 // Reset type is determined at run-time for standalone configtool
955 // config.Read(_("/Run Tests/ResetType"), & m_nReset);
956 config.Read(_("/Run Tests/ResetString"), & m_strReset);
957 config.Read(_("/Run Tests/ResourceHost"), & m_strResourceHost);
958 config.Read(_("/Run Tests/ResourcePort"), & m_nResourcePort);
959 config.Read(_("/Run Tests/RemoteHost"), & m_strRemoteHost);
960 config.Read(_("/Run Tests/RemotePort"), & m_nRemotePort);
961 config.Read(_("/Run Tests/Farmed"), (bool*) & m_bFarmed);
966 bool ecRunTestsSettings::SaveConfig(wxConfig& config)
968 config.Write(_("/Run Tests/TimeoutType"), (long) m_nTimeoutType);
969 config.Write(_("/Run Tests/DownloadTimeoutType"), (long) m_nDownloadTimeoutType);
970 config.Write(_("/Run Tests/Remote"), m_bRemote);
971 config.Write(_("/Run Tests/Serial"), m_bSerial);
972 config.Write(_("/Run Tests/Port"), m_strPort);
973 config.Write(_("/Run Tests/Baud"), (long) m_nBaud);
974 config.Write(_("/Run Tests/LocalTCPIPHost"), m_strLocalTCPIPHost);
975 config.Write(_("/Run Tests/LocalTCPIPPort"), (long) m_nLocalTCPIPPort);
976 config.Write(_("/Run Tests/ResetType"), (long) m_nReset);
977 config.Write(_("/Run Tests/ResetString"), m_strReset);
978 config.Write(_("/Run Tests/ResourceHost"), m_strResourceHost);
979 config.Write(_("/Run Tests/ResourcePort"), (long) m_nResourcePort);
980 config.Write(_("/Run Tests/RemoteHost"), m_strRemoteHost);
981 config.Write(_("/Run Tests/RemotePort"), (long) m_nRemotePort);
982 config.Write(_("/Run Tests/Farmed"), m_bFarmed);