1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // ConfigTool.cpp : Defines the class behaviors for the application.
28 //===========================================================================
29 //#####DESCRIPTIONBEGIN####
36 // Description: This is the implementation of the application class
43 //####DESCRIPTIONEND####
45 //===========================================================================
49 #include "ConfigTool.h"
50 #include "ConfigToolDoc.h"
51 #include "ControlView.h"
52 #include "CSHDialog.h"
54 #include "eCosDialog.h"
56 #include "eCosSocket.h"
59 #include "OutputView.h"
64 #include <afxdisp.h> // for AfxEnableControlContainer()
68 static char THIS_FILE[] = __FILE__;
71 CString CConfigTool::strHelpFile;
73 /////////////////////////////////////////////////////////////////////////////
76 BEGIN_MESSAGE_MAP(CConfigToolApp, CWinApp)
77 //{{AFX_MSG_MAP(CConfigToolApp)
78 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
80 // Standard file based document commands
81 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
82 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
83 // Standard print setup command
84 ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
89 /////////////////////////////////////////////////////////////////////////////
90 // CConfigToolApp construction
91 CConfigToolApp::CConfigToolApp()
93 m_GrayPen.CreatePen(PS_SOLID,1,RGB(192,192,192));
94 m_VersionInfo.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
95 ::GetVersionEx(&m_VersionInfo);
98 /////////////////////////////////////////////////////////////////////////////
99 // The one and only CConfigToolApp object
101 CConfigToolApp theApp;
103 /////////////////////////////////////////////////////////////////////////////
104 // CConfigToolApp initialization
106 BOOL CConfigToolApp::InitInstance()
109 CeCosTestPlatform::Load();
110 CFileName strCSHFile;
111 ::GetModuleFileName(::GetModuleHandle(NULL),strCSHFile.GetBuffer(1+MAX_PATH),MAX_PATH);
112 strCSHFile.ReleaseBuffer();
113 strCSHFile.ReplaceExtension(_T(".chm"));
114 CConfigTool::strHelpFile=strCSHFile;
115 CCSHDialog::SetCSHFilePath(strCSHFile);
117 extern UINT arCommonDialogMap[];
118 CeCosDialog::AddDialogMap(arCommonDialogMap);
120 extern UINT arStandaloneDialogMap[];
121 CeCosDialog::AddDialogMap(arStandaloneDialogMap);
123 extern UINT arPkgAdminDialogMap[];
124 CeCosDialog::AddDialogMap(arPkgAdminDialogMap);
126 extern UINT arTestToolDialogMap[];
127 CeCosDialog::AddDialogMap(arTestToolDialogMap);
129 // CG: The following block was added by the Splash Screen component.
133 CCommandLineInfo cmdInfo;
135 ParseCommandLine(cmdInfo);
139 CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
142 AfxEnableControlContainer();
143 // Standard initialization
144 // If you are not using these features and wish to reduce the size
145 // of your final executable, you should remove from the following
146 // the specific initialization routines you do not need.
148 int nSize=GetEnvironmentVariable(_T("PATH"), NULL, 0);
150 GetEnvironmentVariable(_T("PATH"),m_strOriginalPath.GetBuffer(1+nSize),nSize);
151 m_strOriginalPath.ReleaseBuffer();
155 Enable3dControls(); // Call this when using MFC in a shared DLL
157 Enable3dControlsStatic(); // Call this when linking to MFC statically
159 SetRegistryKey(IDS_REGKEY);
160 LoadStdProfileSettings(); // Load standard INI file options (including MRU)
162 // Register the application's document templates. Document templates
163 // serve as the connection between documents, frame windows and views.
165 CSingleDocTemplate* pDocTemplate;
166 pDocTemplate = new CSingleDocTemplate(
168 RUNTIME_CLASS(CConfigToolDoc),
169 RUNTIME_CLASS(CMainFrame), // main SDI frame window
170 RUNTIME_CLASS(CControlView));
171 AddDocTemplate(pDocTemplate);
173 // Parse command line for standard shell commands, DDE, file open
174 CCommandLineInfo cmdInfo;
175 //ParseCommandLine(cmdInfo);
177 CString strCmdLine(GetCommandLine());
179 int nWords=CUtils::Chop(strCmdLine,arArgs,_TCHAR(' '),/*bObserveStrings=*/true,/*bBackslashQuotes=*/false);
182 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
183 for(int i=1;i<nWords;i++)
185 CString &str=arArgs[i];
186 if(0==str.Compare(_T("-R")) && i<nWords-1){
187 pDoc->SetRepository(arArgs[++i]);
188 } else if (0==str.CompareNoCase(_T("-S")) && i<nWords-1){
189 // Load settings file
190 } else if (0==str.CompareNoCase(_T("-B"))){
193 } else if (0==str.CompareNoCase(_T("-R"))){
197 cmdInfo.m_nShellCommand=CCommandLineInfo::FileOpen;
198 cmdInfo.m_strFileName=str;
202 // Dispatch commands specified on the command line
203 if (!ProcessShellCommand(cmdInfo))
206 CMenu* pMenu = m_pMainWnd->GetMenu();
207 if (pMenu)pMenu->DestroyMenu();
208 HMENU hMenu = ((CMainFrame*) m_pMainWnd)->NewMenu();
209 pMenu = CMenu::FromHandle( hMenu );
210 m_pMainWnd->SetMenu(pMenu);
211 ((CMainFrame*)m_pMainWnd)->m_hMenuDefault = hMenu;
214 // The one and only window has been initialized, so show and update it.
215 m_pMainWnd->ShowWindow(SW_SHOW);
216 m_pMainWnd->UpdateWindow();
221 /////////////////////////////////////////////////////////////////////////////
222 // CAboutDlg dialog used for App About
224 class CAboutDlg : public CDialog
230 //{{AFX_DATA(CAboutDlg)
231 enum { IDD = IDD_ABOUTBOX };
235 // ClassWizard generated virtual function overrides
236 //{{AFX_VIRTUAL(CAboutDlg)
238 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
243 //{{AFX_MSG(CAboutDlg)
244 virtual BOOL OnInitDialog();
245 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
247 DECLARE_MESSAGE_MAP()
250 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
252 //{{AFX_DATA_INIT(CAboutDlg)
256 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
258 CDialog::DoDataExchange(pDX);
259 //{{AFX_DATA_MAP(CAboutDlg)
260 DDX_Control(pDX, IDC_STATIC_ABOUT, m_static);
264 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
265 //{{AFX_MSG_MAP(CAboutDlg)
266 ON_WM_LBUTTONDBLCLK()
270 // App command to run the dialog
271 void CConfigToolApp::OnAppAbout()
277 /////////////////////////////////////////////////////////////////////////////
278 // CConfigToolApp commands
281 int CConfigToolApp::ExitInstance()
283 // Save persistence info
284 WriteProfileString(_T("Build"), _T("MakeOptions"),m_strMakeOptions);
285 WriteProfileString(CUtils::LoadString(IDS_KEY_USER_DIR), _T("Folder"), m_strUserToolsDir);
286 // Write any target bindirs to the registry
287 for(POSITION pos = m_arstrBinDirs.GetStartPosition(); pos != NULL; ){
288 CString strPrefix,strBinDir;
289 m_arstrBinDirs.GetNextAssoc(pos, strPrefix, strBinDir);
290 WriteProfileString(CUtils::LoadString(IDS_KEY_TOOLS_DIR),strPrefix,strBinDir);
292 ::DeleteFile(CConfigToolDoc::HTMLHelpLinkFileName());
294 CeCosTestPlatform::RemoveAllPlatforms();
295 return CWinApp::ExitInstance();
298 void CConfigToolApp::LoadStdProfileSettings()
300 CWinApp::LoadStdProfileSettings(4);
303 FindExecutable(_T("Notepad.exe"),_T(""),strNotepad.GetBuffer(MAX_PATH));
304 strNotepad.ReleaseBuffer();
306 m_strMakeOptions= GetProfileString(_T("Build"), _T("MakeOptions"),_T(""));
307 if(m_strMakeOptions.IsEmpty()){
308 SYSTEM_INFO SystemInfo;
309 GetSystemInfo(&SystemInfo);
310 m_strMakeOptions.Format(_T("-j%d"),SystemInfo.dwNumberOfProcessors);
313 CRegKeyEx InstallKey (HKEY_LOCAL_MACHINE, GetInstallVersionKey (), KEY_READ);
315 m_strUserToolsDir= GetProfileString(CUtils::LoadString(IDS_KEY_USER_DIR), _T("Folder"), _T(""));
316 if(!m_strUserToolsDir.IsDir()){ // if the user specified user tools dir does not exist
317 InstallKey.QueryValue (_T("Default User Tools Path"), m_strUserToolsDir); // use the installer default
318 if (!m_strUserToolsDir.IsDir()) { // if the default user tools dir does not exist
319 m_strUserToolsDir=_T(""); // force prompting for the user tools dir
323 // set default build tools binary directories as specified by the installer
324 CFileName strDefaultBuildToolsPath;
325 if (InstallKey.QueryValue (_T("Default Build Tools Path"), strDefaultBuildToolsPath)) {
326 // look for *-gcc.exe in the default build tools directory
328 BOOL bMore=finder.FindFile (strDefaultBuildToolsPath + _T("*-gcc.exe"));
329 while (bMore) { // for each file matching the globbing pattern
330 bMore = finder.FindNextFile ();
331 CFileName strFile (finder.GetFileName ());
332 m_arstrBinDirs.SetAt (strFile.Left (strFile.Find (_T("-gcc"))), strDefaultBuildToolsPath);
337 k.Attach(GetSectionKey(CUtils::LoadString(IDS_KEY_TOOLS_DIR)));
340 for(int i=0;k.QueryValue(i,strPrefix,strDir);i++){
342 m_arstrBinDirs.SetAt(strPrefix,strDir);
346 CStringArray arstrToolChainPaths;
347 GetRepositoryRegistryClues(arstrToolChainPaths,_T("GNUPro eCos"));
348 for(i=0;i<arstrToolChainPaths.GetSize();i++){
349 CFileName strDir(arstrToolChainPaths[i]);
350 strDir+="H-i686-cygwin32\\bin";
352 // This is a potential toolchain location. Look for *-gcc.exe
354 BOOL bMore=finder.FindFile(strDir+"*-gcc.exe");
356 bMore = finder.FindNextFile();
357 CFileName strFile(finder.GetFileName());
358 m_arstrBinDirs.SetAt(strFile.Left(strFile.Find(_T("-gcc"))),strDir);
363 // Look for GNUPro 00r1 first, since it's the latest and greatest user tools.
364 GetRepositoryRegistryClues(m_arstrUserToolPaths, _T("GNUPro 00r1"));
365 if (m_arstrUserToolPaths.GetSize() == 0)
367 GetRepositoryRegistryClues(m_arstrUserToolPaths, _T("Cygwin 00r1"));
369 if (m_arstrUserToolPaths.GetSize() > 0)
371 for(i=0;i<m_arstrUserToolPaths.GetSize();i++){
372 CFileName str(m_arstrUserToolPaths[i]);
373 str+="H-i686-pc-cygwin\\bin";
375 m_arstrUserToolPaths.SetAt(i,str);
377 m_arstrUserToolPaths.RemoveAt(i);
384 GetRepositoryRegistryClues(m_arstrUserToolPaths, _T("GNUPro unsupported"));
385 for(i=0;i<m_arstrUserToolPaths.GetSize();i++){
386 CFileName str(m_arstrUserToolPaths[i]);
387 str+="H-i686-cygwin32\\bin";
389 m_arstrUserToolPaths.SetAt(i,str);
391 m_arstrUserToolPaths.RemoveAt(i);
397 // Include the path in the set of potential user paths
400 int nSize=GetEnvironmentVariable(CUtils::LoadString(IDS_PATH), NULL, 0);
402 GetEnvironmentVariable(CUtils::LoadString(IDS_PATH), strPath.GetBuffer(nSize), nSize);
403 strPath.ReleaseBuffer();
404 CStringArray arstrPath;
405 CUtils::Chop(strPath,arstrPath,_TCHAR(';'));
406 for(int i=arstrPath.GetSize()-1;i>=0;--i){ // Reverse order is important to treat path correctly
407 const CFileName &strFolder=arstrPath[i];
408 CFileName strFile(strFolder);
409 strFile+=_T("ls.exe");
410 if(strFile.Exists()){
411 m_arstrUserToolPaths.Add(strFolder);
412 if(m_strUserToolsDir.IsEmpty()){
413 m_strUserToolsDir=strFolder;
421 BOOL CConfigToolApp::OnIdle(LONG lCount)
425 CMainFrame *pMain=CConfigTool::GetMain();
427 // During startup the main window will be the splash screen
428 CDC *pDC=pMain->GetDC();
429 CFont *pOldFont=pDC->SelectObject(pMain->m_wndStatusBar.GetFont());
430 pDC->SelectObject(pOldFont);
431 pMain->ReleaseDC(pDC);
435 return CWinApp::OnIdle(lCount);
438 BOOL CConfigToolApp::PreTranslateMessage(MSG* pMsg)
440 // CG: The following lines were added by the Splash Screen component.
441 if (CSplashWnd::PreTranslateAppMessage(pMsg))
444 return CWinApp::PreTranslateMessage(pMsg);
447 BOOL CAboutDlg::OnInitDialog()
450 strVersion.Format(_T("%s %s"),_T(__DATE__),_T(__TIME__));
451 SetDlgItemText(IDC_STATIC_DATETIME,strVersion);
452 CDialog::OnInitDialog();
453 return TRUE; // return TRUE unless you set the focus to a control
454 // EXCEPTION: OCX Property Pages should return FALSE
457 bool CConfigToolApp::Launch(const CString & strFileName,const CString &strViewer)
461 if(!strViewer.IsEmpty())//use custom editor
463 CString strCmdline(strViewer);
465 TCHAR *pszCmdLine=strCmdline.GetBuffer(strCmdline.GetLength());
466 GetShortPathName(pszCmdLine,pszCmdLine,strCmdline.GetLength());
467 strCmdline.ReleaseBuffer();
469 strCmdline+=_TCHAR(' ');
470 strCmdline+=strFileName;
471 PROCESS_INFORMATION pi;
474 si.cb = sizeof(STARTUPINFO);
475 si.lpReserved = NULL;
476 si.lpReserved2 = NULL;
484 //strCmdline.GetBuffer(strCmdline.GetLength()), // command line
485 strCmdline.GetBuffer(strCmdline.GetLength()), // command line
486 NULL, // process security
487 NULL, // thread security
488 TRUE, // inherit handles
494 CloseHandle(pi.hProcess);
495 CloseHandle(pi.hThread);
498 CUtils::MessageBoxF(_T("Failed to invoke %s.\n"),strCmdline);
500 strCmdline.ReleaseBuffer();
501 } else {// Use association
502 TCHAR szExe[MAX_PATH];
503 HINSTANCE h=FindExecutable(strFileName,_T("."),szExe);
507 case 0: str=_T("The system is out of memory or resources.");break;
508 case 31: str=_T("There is no association for the specified file type.");break;
509 case ERROR_FILE_NOT_FOUND: str=_T("The specified file was not found.");break;
510 case ERROR_PATH_NOT_FOUND: str=_T("The specified path was not found.");break;
511 case ERROR_BAD_FORMAT: str=_T("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).");break;
514 CUtils::MessageBoxF(_T("Failed to open document %s.\r\n%s"),strFileName,str);
517 SHELLEXECUTEINFO sei = {sizeof(sei), 0, AfxGetMainWnd()->GetSafeHwnd(), _T("open"),
518 strFileName, NULL, NULL, SW_SHOWNORMAL, AfxGetInstanceHandle( )};
521 HINSTANCE hInst=ShellExecute(AfxGetMainWnd()->GetSafeHwnd(),_T("open"), strFileName, NULL, _T("."), 0)/*ShellExecuteEx(&sei)*/;
522 if(int(hInst)<=32/*sei.hInstApp==0*/)
527 case 0 : str=_T("The operating system is out of memory or resources. ");break;
528 case ERROR_FILE_NOT_FOUND : str=_T("The specified file was not found. ");break;
529 case ERROR_PATH_NOT_FOUND : str=_T("The specified path was not found. ");break;
530 case ERROR_BAD_FORMAT : str=_T("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image). ");break;
531 case SE_ERR_ACCESSDENIED : str=_T("The operating system denied access to the specified file. ");break;
532 case SE_ERR_ASSOCINCOMPLETE : str=_T("The filename association is incomplete or invalid. ");break;
533 case SE_ERR_DDEBUSY : str=_T("The DDE transaction could not be completed because other DDE transactions were being processed. ");break;
534 case SE_ERR_DDEFAIL : str=_T("The DDE transaction failed. ");break;
535 case SE_ERR_DDETIMEOUT : str=_T("The DDE transaction could not be completed because the request timed out. ");break;
536 case SE_ERR_DLLNOTFOUND : str=_T("The specified dynamic-link library was not found. ");break;
537 //case SE_ERR_FNF : str=_T("The specified file was not found. ");break;
538 case SE_ERR_NOASSOC : str=_T("There is no application associated with the given filename extension. ");break;
539 case SE_ERR_OOM : str=_T("There was not enough memory to complete the operation. ");break;
540 //case SE_ERR_PNF : str=_T("The specified path was not found. ");break;
541 case SE_ERR_SHARE : str=_T("A sharing violation occurred. ");break;
542 default: str=_T("An unexpected error occurred");break;
544 CUtils::MessageBoxF(_T("Failed to open document %s using %s.\r\n%s"),strFileName,szExe,str);
554 void CConfigToolApp::AddToRecentFileList(LPCTSTR lpszPathName)
556 const CFileName strDir=CFileName(lpszPathName).Head();
558 CWinApp::AddToRecentFileList(strDir);
563 int CConfigToolApp::GetRepositoryRegistryClues(CStringArray &arstr,LPCTSTR pszPrefix)
565 // Go looking for potential candidates in SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
567 CRegKeyEx k1(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths"),KEY_READ);
569 for(int i=0;k1.QueryKey(i,strKey);i++){
570 if(0==strKey.Find(pszPrefix)){
571 CRegKeyEx k2((HKEY)k1,strKey,KEY_READ);
573 if(k2.QueryValue(_T("Path"),strDir) && strDir.IsDir()){
578 return arstr.GetSize();
582 void CAboutDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
584 UNUSED_ALWAYS(point);
585 UNUSED_ALWAYS(nFlags);
588 //const char CConfigToolApp::s_profileFlags[] = _T("flags");
589 LPCTSTR CConfigToolApp::s_profileMax = _T("max");
590 LPCTSTR CConfigToolApp::s_profileTool = _T("tool");
591 LPCTSTR CConfigToolApp::s_profileStatus = _T("status");
592 LPCTSTR CConfigToolApp::s_profileRect = _T("Rect");
594 void CConfigToolApp::SaveWindowPlacement(CWnd *pWnd, const CString &strKey)
599 WINDOWPLACEMENT wndpl;
600 wndpl.length = sizeof(WINDOWPLACEMENT);
601 // gets current window position and
602 // iconized/maximized status
603 pWnd->GetWindowPlacement(&wndpl);
604 strText.Format(_T("%04d %04d %04d %04d"),
605 wndpl.rcNormalPosition.left,
606 wndpl.rcNormalPosition.top,
607 wndpl.rcNormalPosition.right,
608 wndpl.rcNormalPosition.bottom);
609 if(!pWnd->IsWindowVisible()){
610 wndpl.showCmd=SW_HIDE;
612 WriteProfileInt (strKey,_T("Show"), wndpl.showCmd);
613 WriteProfileString(strKey,s_profileRect, strText);
616 BOOL CConfigToolApp::RestoreWindowPlacement(CWnd *pWnd,const CString &strKey,const CRect &rcDefault)
618 // Set the windows according to registry settings
620 WINDOWPLACEMENT wndpl;
623 strText = GetProfileString(strKey,s_profileRect);
624 if (!strText.IsEmpty()) {
625 rect.left = _ttoi((LPCTSTR ) strText);
626 rect.top = _ttoi((LPCTSTR ) strText + 5);
627 rect.right = _ttoi((LPCTSTR ) strText + 10);
628 rect.bottom = _ttoi((LPCTSTR ) strText + 15);
634 SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcMax, 0);
636 if(rect.Width()<100 || rect.Height()<100 || rect.Width()>rcMax.Width() || rect.Height()>rcMax.Height()){
640 wndpl.length = sizeof(WINDOWPLACEMENT);
641 wndpl.showCmd = GetProfileInt(strKey,_T("Show"),SW_SHOWNA);
644 wndpl.ptMinPosition = CPoint(0, 0);
645 wndpl.ptMaxPosition =CPoint(-::GetSystemMetrics(SM_CXBORDER),-::GetSystemMetrics(SM_CYBORDER));
646 wndpl.rcNormalPosition = rect;
648 // sets window's position and iconized/maximized status
649 return pWnd->SetWindowPlacement(&wndpl);
652 void CConfigToolApp::LoadFont(const CString & strKey, LOGFONT & lf)
654 lf.lfHeight =(LONG)GetProfileInt(strKey,_T("Height"),0);
657 font.Attach(HFONT(GetStockObject(DEFAULT_GUI_FONT)));
658 font.GetLogFont(&lf);
660 lf.lfWidth =(LONG)GetProfileInt(strKey,_T("Width"),0);
661 lf.lfEscapement =(LONG)GetProfileInt(strKey,_T("Escapement"),0);
662 lf.lfOrientation =(LONG)GetProfileInt(strKey,_T("Orientation"),0);
663 lf.lfWeight =(LONG)GetProfileInt(strKey,_T("Weight"),0);
664 lf.lfItalic =(BYTE)GetProfileInt(strKey,_T("Italic"),0);
665 lf.lfUnderline =(BYTE)GetProfileInt(strKey,_T("Underline"),0);
666 lf.lfStrikeOut =(BYTE)GetProfileInt(strKey,_T("StrikeOut"),0);
667 lf.lfCharSet =(BYTE)GetProfileInt(strKey,_T("CharSet"),0);
668 lf.lfOutPrecision =(BYTE)GetProfileInt(strKey,_T("OutPrecision"),0);
669 lf.lfClipPrecision =(BYTE)GetProfileInt(strKey,_T("ClipPrecision"),0);
670 lf.lfQuality =(BYTE)GetProfileInt(strKey,_T("Quality"),0);
671 lf.lfPitchAndFamily =(BYTE)GetProfileInt(strKey,_T("PitchAndFamily"),0);
672 CString strFaceName =GetProfileString(strKey,_T("FaceName"),_T(""));
673 if(strFaceName.GetLength()<=31){
674 _tcscpy(lf.lfFaceName,strFaceName);
676 lf.lfFaceName[0]=_TCHAR('\0');
681 void CConfigToolApp::SaveFont(const CString & strKey, const LOGFONT & lf)
683 WriteProfileInt(strKey,_T("Height"), (int)lf.lfHeight);
684 WriteProfileInt(strKey,_T("Width"), (int)lf.lfWidth);
685 WriteProfileInt(strKey,_T("Escapement"), (int)lf.lfEscapement);
686 WriteProfileInt(strKey,_T("Orientation"), (int)lf.lfOrientation);
687 WriteProfileInt(strKey,_T("Weight"), (int)lf.lfWeight);
688 WriteProfileInt(strKey,_T("Italic"), (int)lf.lfItalic);
689 WriteProfileInt(strKey,_T("Underline"), (int)lf.lfUnderline);
690 WriteProfileInt(strKey,_T("StrikeOut"), (int)lf.lfStrikeOut);
691 WriteProfileInt(strKey,_T("CharSet"), (int)lf.lfCharSet);
692 WriteProfileInt(strKey,_T("OutPrecision"), (int)lf.lfOutPrecision);
693 WriteProfileInt(strKey,_T("ClipPrecision"), (int)lf.lfClipPrecision);
694 WriteProfileInt(strKey,_T("Quality"), (int)lf.lfQuality);
695 WriteProfileInt(strKey,_T("PitchAndFamily"),(int)lf.lfPitchAndFamily);
696 WriteProfileString(strKey,_T("FaceName"), lf.lfFaceName);
699 CEditView *CConfigTool::m_pEditView=NULL;
700 COutputView *CConfigTool::m_pOutputView=NULL;
701 CControlView *CConfigTool::m_pControlView=NULL;
702 CCellView *CConfigTool::m_pCellView=NULL;
703 CDescView *CConfigTool::m_pDescView=NULL;
704 CPropertiesView *CConfigTool::m_pPropertiesView=NULL;
705 CRulesView *CConfigTool::m_pRulesView=NULL;
706 CConfigToolDoc *CConfigTool::m_pConfigToolDoc=NULL;
707 CMainFrame *CConfigTool::m_pMain=NULL;
708 CMLTView *CConfigTool::m_pMLTView=NULL;
710 CControlView *CConfigTool::GetControlView() { return m_pControlView; }
711 COutputView *CConfigTool::GetOutputView() { return m_pOutputView; }
712 CCellView *CConfigTool::GetCellView() { return m_pCellView; }
713 CDescView *CConfigTool::GetDescView() { return m_pDescView; }
714 CPropertiesView *CConfigTool::GetPropertiesView() { return m_pPropertiesView; }
715 CRulesView *CConfigTool::GetRulesView() { return m_pRulesView; }
716 CMLTView *CConfigTool::GetMLTView() { return m_pMLTView; }
718 void CConfigTool::SetDocument(CConfigToolDoc *pDoc) {m_pConfigToolDoc=pDoc; }
719 void CConfigTool::SetMain(CMainFrame * pMain) { m_pMain=pMain; }
720 void CConfigTool::SetControlView(CControlView *pControlView) {m_pControlView=pControlView; }
721 void CConfigTool::SetOutputView(COutputView *pOutputView) {m_pOutputView=pOutputView; }
722 void CConfigTool::SetCellView(CCellView *pCellView) {m_pCellView=pCellView; }
723 void CConfigTool::SetDescView(CDescView *pDescView) {m_pDescView=pDescView; }
724 void CConfigTool::SetMLTView(CMLTView *pMLTView) {m_pMLTView=pMLTView; }
725 void CConfigTool::SetPropertiesView(CPropertiesView *pPropertiesView) {m_pPropertiesView=pPropertiesView; }
726 void CConfigTool::SetRulesView(CRulesView *pRulesView) {m_pRulesView=pRulesView; }
727 CMainFrame *CConfigTool::GetMain()
729 CWnd *pWnd=AfxGetMainWnd();
730 return (pWnd && pWnd->IsKindOf(RUNTIME_CLASS(CMainFrame)))?(CMainFrame*)pWnd:NULL;
733 int CConfigTool::Log(LPCTSTR pszFormat, ...)
736 va_start (marker, pszFormat);
738 for(int nLength=100;nLength;) {
739 TCHAR *buf=new TCHAR[1+nLength];
740 int n=_vsntprintf(buf, nLength, pszFormat, marker );
742 nLength*=2; // NT behavior
743 } else if (n<nLength){
744 CWnd *pMain=CConfigTool::GetMain();
746 // During startup the main window will be the splash screen
747 COutputView *pView=CConfigTool::GetOutputView();
750 pView->AddText(_T("\r\n"));
753 ((CConfigToolApp *)AfxGetApp())->m_strBufferedLogMessages+=buf;
754 ((CConfigToolApp *)AfxGetApp())->m_strBufferedLogMessages+=_T("\r\n");
755 nLength=0; // trigger exit from loop
757 nLength=n+1; // UNIX behavior generally, or NT behavior when buffer size exactly matches required length
767 void CConfigTool::DismissSplash()
769 CSplashWnd::EnableSplashScreen(FALSE);
772 CString CConfigToolApp::GetInstallVersionKey ()
774 CString strKey = _T("SOFTWARE\\Red Hat\\eCos");
775 CString strVersionKey = _T("");
777 TCHAR pszBuffer [MAX_PATH + 1];
780 // get the greatest eCos version subkey
781 if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) {
783 while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) {
784 if (strVersionKey.Compare (pszBuffer) < 0) {
785 strVersionKey = pszBuffer;
790 return strKey + _T("\\") + strVersionKey;