Mercurial > ecos
comparison host/tools/configtool/standalone/win32/Configtool.cpp @ 76:435cced73e2f ecos-v1_3_1-release
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
| author | jlarmour |
|---|---|
| date | Tue, 28 Mar 2000 14:10:45 +0000 |
| parents | |
| children | 6736c52df507 |
comparison
equal
deleted
inserted
replaced
| 75:41bf073c0c32 | 76:435cced73e2f |
|---|---|
| 1 //####COPYRIGHTBEGIN#### | |
| 2 // | |
| 3 // ---------------------------------------------------------------------------- | |
| 4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 5 // | |
| 6 // This program is part of the eCos host tools. | |
| 7 // | |
| 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) | |
| 11 // any later version. | |
| 12 // | |
| 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 | |
| 16 // more details. | |
| 17 // | |
| 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. | |
| 21 // | |
| 22 // ---------------------------------------------------------------------------- | |
| 23 // | |
| 24 //####COPYRIGHTEND#### | |
| 25 // ConfigTool.cpp : Defines the class behaviors for the application. | |
| 26 // | |
| 27 // | |
| 28 //=========================================================================== | |
| 29 //#####DESCRIPTIONBEGIN#### | |
| 30 // | |
| 31 // Author(s): sdf | |
| 32 // Contact(s): sdf | |
| 33 // Date: 1998/08/11 | |
| 34 // Version: 0.01 | |
| 35 // Purpose: | |
| 36 // Description: This is the implementation of the application class | |
| 37 // Requires: | |
| 38 // Provides: | |
| 39 // See also: | |
| 40 // Known bugs: | |
| 41 // Usage: | |
| 42 // | |
| 43 //####DESCRIPTIONEND#### | |
| 44 // | |
| 45 //=========================================================================== | |
| 46 | |
| 47 #include "stdafx.h" | |
| 48 | |
| 49 #include "ConfigTool.h" | |
| 50 #include "ConfigToolDoc.h" | |
| 51 #include "ControlView.h" | |
| 52 #include "CSHDialog.h" | |
| 53 #include "CTUtils.h" | |
| 54 #include "eCosDialog.h" | |
| 55 #include "eCosTest.h" | |
| 56 #include "FileName.h" | |
| 57 #include "MainFrm.h" | |
| 58 #include "OutputView.h" | |
| 59 #include "RegKeyEx.h" | |
| 60 #include "Splash.h" | |
| 61 | |
| 62 #include <afxadv.h> | |
| 63 #include <afxdisp.h> // for AfxEnableControlContainer() | |
| 64 #ifdef _DEBUG | |
| 65 #define new DEBUG_NEW | |
| 66 #undef THIS_FILE | |
| 67 static char THIS_FILE[] = __FILE__; | |
| 68 #endif | |
| 69 | |
| 70 CString CConfigTool::strHelpFile; | |
| 71 | |
| 72 ///////////////////////////////////////////////////////////////////////////// | |
| 73 // CConfigToolApp | |
| 74 | |
| 75 BEGIN_MESSAGE_MAP(CConfigToolApp, CWinApp) | |
| 76 //{{AFX_MSG_MAP(CConfigToolApp) | |
| 77 ON_COMMAND(ID_APP_ABOUT, OnAppAbout) | |
| 78 //}}AFX_MSG_MAP | |
| 79 // Standard file based document commands | |
| 80 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) | |
| 81 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) | |
| 82 // Standard print setup command | |
| 83 ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) | |
| 84 END_MESSAGE_MAP() | |
| 85 | |
| 86 | |
| 87 | |
| 88 ///////////////////////////////////////////////////////////////////////////// | |
| 89 // CConfigToolApp construction | |
| 90 CConfigToolApp::CConfigToolApp() | |
| 91 { | |
| 92 m_GrayPen.CreatePen(PS_SOLID,1,RGB(192,192,192)); | |
| 93 m_VersionInfo.dwOSVersionInfoSize=sizeof OSVERSIONINFO; | |
| 94 ::GetVersionEx(&m_VersionInfo); | |
| 95 } | |
| 96 | |
| 97 ///////////////////////////////////////////////////////////////////////////// | |
| 98 // The one and only CConfigToolApp object | |
| 99 | |
| 100 CConfigToolApp theApp; | |
| 101 | |
| 102 ///////////////////////////////////////////////////////////////////////////// | |
| 103 // CConfigToolApp initialization | |
| 104 | |
| 105 BOOL CConfigToolApp::InitInstance() | |
| 106 { | |
| 107 CeCosTest::Init(); | |
| 108 CFileName strCSHFile; | |
| 109 ::GetModuleFileName(::GetModuleHandle(NULL),strCSHFile.GetBuffer(1+MAX_PATH),MAX_PATH); | |
| 110 strCSHFile.ReleaseBuffer(); | |
| 111 strCSHFile.ReplaceExtension(_T(".chm")); | |
| 112 CConfigTool::strHelpFile=strCSHFile; | |
| 113 CCSHDialog::SetCSHFilePath(strCSHFile); | |
| 114 | |
| 115 extern UINT arCommonDialogMap[]; | |
| 116 CeCosDialog::AddDialogMap(arCommonDialogMap); | |
| 117 | |
| 118 extern UINT arStandaloneDialogMap[]; | |
| 119 CeCosDialog::AddDialogMap(arStandaloneDialogMap); | |
| 120 | |
| 121 extern UINT arPkgAdminDialogMap[]; | |
| 122 CeCosDialog::AddDialogMap(arPkgAdminDialogMap); | |
| 123 | |
| 124 extern UINT arTestToolDialogMap[]; | |
| 125 CeCosDialog::AddDialogMap(arTestToolDialogMap); | |
| 126 | |
| 127 // CG: The following block was added by the Splash Screen component. | |
| 128 \ | |
| 129 { | |
| 130 \ | |
| 131 CCommandLineInfo cmdInfo; | |
| 132 \ | |
| 133 ParseCommandLine(cmdInfo); | |
| 134 \ | |
| 135 | |
| 136 \ | |
| 137 CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash); | |
| 138 \ | |
| 139 } | |
| 140 AfxEnableControlContainer(); | |
| 141 // Standard initialization | |
| 142 // If you are not using these features and wish to reduce the size | |
| 143 // of your final executable, you should remove from the following | |
| 144 // the specific initialization routines you do not need. | |
| 145 | |
| 146 int nSize=GetEnvironmentVariable(_T("PATH"), NULL, 0); | |
| 147 if(nSize>0){ | |
| 148 GetEnvironmentVariable(_T("PATH"),m_strOriginalPath.GetBuffer(1+nSize),nSize); | |
| 149 m_strOriginalPath.ReleaseBuffer(); | |
| 150 } | |
| 151 | |
| 152 #ifdef _AFXDLL | |
| 153 Enable3dControls(); // Call this when using MFC in a shared DLL | |
| 154 #else | |
| 155 Enable3dControlsStatic(); // Call this when linking to MFC statically | |
| 156 #endif | |
| 157 SetRegistryKey(IDS_REGKEY); | |
| 158 LoadStdProfileSettings(); // Load standard INI file options (including MRU) | |
| 159 | |
| 160 // Register the application's document templates. Document templates | |
| 161 // serve as the connection between documents, frame windows and views. | |
| 162 | |
| 163 CSingleDocTemplate* pDocTemplate; | |
| 164 pDocTemplate = new CSingleDocTemplate( | |
| 165 IDR_MAINFRAME, | |
| 166 RUNTIME_CLASS(CConfigToolDoc), | |
| 167 RUNTIME_CLASS(CMainFrame), // main SDI frame window | |
| 168 RUNTIME_CLASS(CControlView)); | |
| 169 AddDocTemplate(pDocTemplate); | |
| 170 | |
| 171 // Parse command line for standard shell commands, DDE, file open | |
| 172 CCommandLineInfo cmdInfo; | |
| 173 //ParseCommandLine(cmdInfo); | |
| 174 | |
| 175 CString strCmdLine(GetCommandLine()); | |
| 176 CStringArray arArgs; | |
| 177 int nWords=CUtils::Chop(strCmdLine,arArgs,_TCHAR(' '),/*bObserveStrings=*/true,/*bBackslashQuotes=*/false); | |
| 178 bool bBuild=false; | |
| 179 bool bRun=false; | |
| 180 CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); | |
| 181 for(int i=1;i<nWords;i++) | |
| 182 { | |
| 183 CString &str=arArgs[i]; | |
| 184 if(0==str.Compare(_T("-R")) && i<nWords-1){ | |
| 185 pDoc->SetRepository(arArgs[++i]); | |
| 186 } else if (0==str.CompareNoCase(_T("-S")) && i<nWords-1){ | |
| 187 // Load settings file | |
| 188 } else if (0==str.CompareNoCase(_T("-B"))){ | |
| 189 // Build | |
| 190 bBuild=true; | |
| 191 } else if (0==str.CompareNoCase(_T("-R"))){ | |
| 192 // run | |
| 193 bRun=true; | |
| 194 } else { | |
| 195 cmdInfo.m_nShellCommand=CCommandLineInfo::FileOpen; | |
| 196 cmdInfo.m_strFileName=str; | |
| 197 } | |
| 198 } | |
| 199 | |
| 200 // Dispatch commands specified on the command line | |
| 201 if (!ProcessShellCommand(cmdInfo)) | |
| 202 return FALSE; | |
| 203 | |
| 204 CMenu* pMenu = m_pMainWnd->GetMenu(); | |
| 205 if (pMenu)pMenu->DestroyMenu(); | |
| 206 HMENU hMenu = ((CMainFrame*) m_pMainWnd)->NewMenu(); | |
| 207 pMenu = CMenu::FromHandle( hMenu ); | |
| 208 m_pMainWnd->SetMenu(pMenu); | |
| 209 ((CMainFrame*)m_pMainWnd)->m_hMenuDefault = hMenu; | |
| 210 | |
| 211 | |
| 212 // The one and only window has been initialized, so show and update it. | |
| 213 m_pMainWnd->ShowWindow(SW_SHOW); | |
| 214 m_pMainWnd->UpdateWindow(); | |
| 215 | |
| 216 return TRUE; | |
| 217 } | |
| 218 | |
| 219 ///////////////////////////////////////////////////////////////////////////// | |
| 220 // CAboutDlg dialog used for App About | |
| 221 | |
| 222 class CAboutDlg : public CDialog | |
| 223 { | |
| 224 public: | |
| 225 CAboutDlg(); | |
| 226 | |
| 227 // Dialog Data | |
| 228 //{{AFX_DATA(CAboutDlg) | |
| 229 enum { IDD = IDD_ABOUTBOX }; | |
| 230 CStatic m_static; | |
| 231 //}}AFX_DATA | |
| 232 | |
| 233 // ClassWizard generated virtual function overrides | |
| 234 //{{AFX_VIRTUAL(CAboutDlg) | |
| 235 protected: | |
| 236 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support | |
| 237 //}}AFX_VIRTUAL | |
| 238 | |
| 239 // Implementation | |
| 240 protected: | |
| 241 //{{AFX_MSG(CAboutDlg) | |
| 242 virtual BOOL OnInitDialog(); | |
| 243 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); | |
| 244 //}}AFX_MSG | |
| 245 DECLARE_MESSAGE_MAP() | |
| 246 }; | |
| 247 | |
| 248 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) | |
| 249 { | |
| 250 //{{AFX_DATA_INIT(CAboutDlg) | |
| 251 //}}AFX_DATA_INIT | |
| 252 } | |
| 253 | |
| 254 void CAboutDlg::DoDataExchange(CDataExchange* pDX) | |
| 255 { | |
| 256 CDialog::DoDataExchange(pDX); | |
| 257 //{{AFX_DATA_MAP(CAboutDlg) | |
| 258 DDX_Control(pDX, IDC_STATIC_ABOUT, m_static); | |
| 259 //}}AFX_DATA_MAP | |
| 260 } | |
| 261 | |
| 262 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) | |
| 263 //{{AFX_MSG_MAP(CAboutDlg) | |
| 264 ON_WM_LBUTTONDBLCLK() | |
| 265 //}}AFX_MSG_MAP | |
| 266 END_MESSAGE_MAP() | |
| 267 | |
| 268 // App command to run the dialog | |
| 269 void CConfigToolApp::OnAppAbout() | |
| 270 { | |
| 271 CAboutDlg aboutDlg; | |
| 272 aboutDlg.DoModal(); | |
| 273 } | |
| 274 | |
| 275 ///////////////////////////////////////////////////////////////////////////// | |
| 276 // CConfigToolApp commands | |
| 277 | |
| 278 | |
| 279 int CConfigToolApp::ExitInstance() | |
| 280 { | |
| 281 // Save persistence info | |
| 282 WriteProfileString(_T("Build"), _T("MakeOptions"),m_strMakeOptions); | |
| 283 WriteProfileString(CUtils::LoadString(IDS_KEY_USER_DIR), _T("Folder"), m_strUserToolsDir); | |
| 284 // Write any target bindirs to the registry | |
| 285 for(POSITION pos = m_arstrBinDirs.GetStartPosition(); pos != NULL; ){ | |
| 286 CString strPrefix,strBinDir; | |
| 287 m_arstrBinDirs.GetNextAssoc(pos, strPrefix, strBinDir); | |
| 288 WriteProfileString(CUtils::LoadString(IDS_KEY_TOOLS_DIR),strPrefix,strBinDir); | |
| 289 } | |
| 290 ::DeleteFile(CConfigToolDoc::HTMLHelpLinkFileName()); | |
| 291 CeCosTest::Term(); | |
| 292 return CWinApp::ExitInstance(); | |
| 293 } | |
| 294 | |
| 295 void CConfigToolApp::LoadStdProfileSettings() | |
| 296 { | |
| 297 CWinApp::LoadStdProfileSettings(4); | |
| 298 | |
| 299 CString strNotepad; | |
| 300 FindExecutable(_T("Notepad.exe"),_T(""),strNotepad.GetBuffer(MAX_PATH)); | |
| 301 strNotepad.ReleaseBuffer(); | |
| 302 | |
| 303 m_strMakeOptions= GetProfileString(_T("Build"), _T("MakeOptions"),_T("")); | |
| 304 if(m_strMakeOptions.IsEmpty()){ | |
| 305 SYSTEM_INFO SystemInfo; | |
| 306 GetSystemInfo(&SystemInfo); | |
| 307 m_strMakeOptions.Format(_T("-j%d"),SystemInfo.dwNumberOfProcessors); | |
| 308 } | |
| 309 | |
| 310 CRegKeyEx InstallKey (HKEY_LOCAL_MACHINE, GetInstallVersionKey (), KEY_READ); | |
| 311 | |
| 312 m_strUserToolsDir= GetProfileString(CUtils::LoadString(IDS_KEY_USER_DIR), _T("Folder"), _T("")); | |
| 313 if(!m_strUserToolsDir.IsDir()){ // if the user specified user tools dir does not exist | |
| 314 InstallKey.QueryValue (_T("Default User Tools Path"), m_strUserToolsDir); // use the installer default | |
| 315 if (!m_strUserToolsDir.IsDir()) { // if the default user tools dir does not exist | |
| 316 m_strUserToolsDir=_T(""); // force prompting for the user tools dir | |
| 317 } | |
| 318 } | |
| 319 | |
| 320 // set default build tools binary directories as specified by the installer | |
| 321 CFileName strDefaultBuildToolsPath; | |
| 322 if (InstallKey.QueryValue (_T("Default Build Tools Path"), strDefaultBuildToolsPath)) { | |
| 323 // look for *-gcc.exe in the default build tools directory | |
| 324 CFileFind finder; | |
| 325 BOOL bMore=finder.FindFile (strDefaultBuildToolsPath + _T("*-gcc.exe")); | |
| 326 while (bMore) { // for each file matching the globbing pattern | |
| 327 bMore = finder.FindNextFile (); | |
| 328 CFileName strFile (finder.GetFileName ()); | |
| 329 m_arstrBinDirs.SetAt (strFile.Left (strFile.Find (_T("-gcc"))), strDefaultBuildToolsPath); | |
| 330 } | |
| 331 } | |
| 332 | |
| 333 CRegKeyEx k; | |
| 334 k.Attach(GetSectionKey(CUtils::LoadString(IDS_KEY_TOOLS_DIR))); | |
| 335 CFileName strDir; | |
| 336 CString strPrefix; | |
| 337 for(int i=0;k.QueryValue(i,strPrefix,strDir);i++){ | |
| 338 if(strDir.IsDir()){ | |
| 339 m_arstrBinDirs.SetAt(strPrefix,strDir); | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 CStringArray arstrToolChainPaths; | |
| 344 GetRepositoryRegistryClues(arstrToolChainPaths,_T("GNUPro eCos")); | |
| 345 for(i=0;i<arstrToolChainPaths.GetSize();i++){ | |
| 346 CFileName strDir(arstrToolChainPaths[i]); | |
| 347 strDir+="H-i686-cygwin32\\bin"; | |
| 348 if(strDir.IsDir()){ | |
| 349 // This is a potential toolchain location. Look for *-gcc.exe | |
| 350 CFileFind finder; | |
| 351 BOOL bMore=finder.FindFile(strDir+"*-gcc.exe"); | |
| 352 while (bMore) { | |
| 353 bMore = finder.FindNextFile(); | |
| 354 CFileName strFile(finder.GetFileName()); | |
| 355 m_arstrBinDirs.SetAt(strFile.Left(strFile.Find(_T("-gcc"))),strDir); | |
| 356 } | |
| 357 } | |
| 358 } | |
| 359 | |
| 360 GetRepositoryRegistryClues(m_arstrUserToolPaths, _T("GNUPro unsupported")); | |
| 361 for(i=0;i<m_arstrUserToolPaths.GetSize();i++){ | |
| 362 CFileName str(m_arstrUserToolPaths[i]); | |
| 363 str+="H-i686-cygwin32\\bin"; | |
| 364 if(str.IsDir()){ | |
| 365 m_arstrUserToolPaths.SetAt(i,str); | |
| 366 } else { | |
| 367 m_arstrUserToolPaths.RemoveAt(i); | |
| 368 i--; | |
| 369 } | |
| 370 } | |
| 371 | |
| 372 // Include the path in the set of potential user paths | |
| 373 { | |
| 374 CString strPath; | |
| 375 int nSize=GetEnvironmentVariable(CUtils::LoadString(IDS_PATH), NULL, 0); | |
| 376 if(nSize>0){ | |
| 377 GetEnvironmentVariable(CUtils::LoadString(IDS_PATH), strPath.GetBuffer(nSize), nSize); | |
| 378 strPath.ReleaseBuffer(); | |
| 379 CStringArray arstrPath; | |
| 380 CUtils::Chop(strPath,arstrPath,_TCHAR(';')); | |
| 381 for(int i=arstrPath.GetSize()-1;i>=0;--i){ // Reverse order is important to treat path correctly | |
| 382 const CFileName &strFolder=arstrPath[i]; | |
| 383 CFileName strFile(strFolder); | |
| 384 strFile+=_T("ls.exe"); | |
| 385 if(strFile.Exists()){ | |
| 386 m_arstrUserToolPaths.Add(strFolder); | |
| 387 if(m_strUserToolsDir.IsEmpty()){ | |
| 388 m_strUserToolsDir=strFolder; | |
| 389 } | |
| 390 } | |
| 391 } | |
| 392 } | |
| 393 } | |
| 394 } | |
| 395 | |
| 396 BOOL CConfigToolApp::OnIdle(LONG lCount) | |
| 397 { | |
| 398 if(lCount==0) | |
| 399 { | |
| 400 CMainFrame *pMain=CConfigTool::GetMain(); | |
| 401 if(pMain){ | |
| 402 // During startup the main window will be the splash screen | |
| 403 CDC *pDC=pMain->GetDC(); | |
| 404 CFont *pOldFont=pDC->SelectObject(pMain->m_wndStatusBar.GetFont()); | |
| 405 pDC->SelectObject(pOldFont); | |
| 406 pMain->ReleaseDC(pDC); | |
| 407 | |
| 408 } | |
| 409 } | |
| 410 return CWinApp::OnIdle(lCount); | |
| 411 } | |
| 412 | |
| 413 BOOL CConfigToolApp::PreTranslateMessage(MSG* pMsg) | |
| 414 { | |
| 415 // CG: The following lines were added by the Splash Screen component. | |
| 416 if (CSplashWnd::PreTranslateAppMessage(pMsg)) | |
| 417 return TRUE; | |
| 418 | |
| 419 return CWinApp::PreTranslateMessage(pMsg); | |
| 420 } | |
| 421 | |
| 422 BOOL CAboutDlg::OnInitDialog() | |
| 423 { | |
| 424 CString strVersion; | |
| 425 strVersion.Format(_T("%s %s"),_T(__DATE__),_T(__TIME__)); | |
| 426 SetDlgItemText(IDC_STATIC_DATETIME,strVersion); | |
| 427 CDialog::OnInitDialog(); | |
| 428 return TRUE; // return TRUE unless you set the focus to a control | |
| 429 // EXCEPTION: OCX Property Pages should return FALSE | |
| 430 } | |
| 431 | |
| 432 bool CConfigToolApp::Launch(const CString & strFileName,const CString &strViewer) | |
| 433 { | |
| 434 bool rc=false; | |
| 435 | |
| 436 if(!strViewer.IsEmpty())//use custom editor | |
| 437 { | |
| 438 CString strCmdline(strViewer); | |
| 439 | |
| 440 TCHAR *pszCmdLine=strCmdline.GetBuffer(strCmdline.GetLength()); | |
| 441 GetShortPathName(pszCmdLine,pszCmdLine,strCmdline.GetLength()); | |
| 442 strCmdline.ReleaseBuffer(); | |
| 443 | |
| 444 strCmdline+=_TCHAR(' '); | |
| 445 strCmdline+=strFileName; | |
| 446 PROCESS_INFORMATION pi; | |
| 447 STARTUPINFO si; | |
| 448 | |
| 449 si.cb = sizeof(STARTUPINFO); | |
| 450 si.lpReserved = NULL; | |
| 451 si.lpReserved2 = NULL; | |
| 452 si.cbReserved2 = 0; | |
| 453 si.lpDesktop = NULL; | |
| 454 si.dwFlags = 0; | |
| 455 si.lpTitle=NULL; | |
| 456 | |
| 457 if(CreateProcess( | |
| 458 NULL, // app name | |
| 459 //strCmdline.GetBuffer(strCmdline.GetLength()), // command line | |
| 460 strCmdline.GetBuffer(strCmdline.GetLength()), // command line | |
| 461 NULL, // process security | |
| 462 NULL, // thread security | |
| 463 TRUE, // inherit handles | |
| 464 0, | |
| 465 NULL, // environment | |
| 466 NULL, // current dir | |
| 467 &si, // startup info | |
| 468 &pi)){ | |
| 469 CloseHandle(pi.hProcess); | |
| 470 CloseHandle(pi.hThread); | |
| 471 rc=true; | |
| 472 } else { | |
| 473 CUtils::MessageBoxF(_T("Failed to invoke %s.\n"),strCmdline); | |
| 474 } | |
| 475 strCmdline.ReleaseBuffer(); | |
| 476 } else {// Use association | |
| 477 TCHAR szExe[MAX_PATH]; | |
| 478 HINSTANCE h=FindExecutable(strFileName,_T("."),szExe); | |
| 479 if(int(h)<=32){ | |
| 480 CString str; | |
| 481 switch(int(h)){ | |
| 482 case 0: str=_T("The system is out of memory or resources.");break; | |
| 483 case 31: str=_T("There is no association for the specified file type.");break; | |
| 484 case ERROR_FILE_NOT_FOUND: str=_T("The specified file was not found.");break; | |
| 485 case ERROR_PATH_NOT_FOUND: str=_T("The specified path was not found.");break; | |
| 486 case ERROR_BAD_FORMAT: str=_T("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).");break; | |
| 487 default: break; | |
| 488 } | |
| 489 CUtils::MessageBoxF(_T("Failed to open document %s.\r\n%s"),strFileName,str); | |
| 490 } else { | |
| 491 | |
| 492 SHELLEXECUTEINFO sei = {sizeof(sei), 0, AfxGetMainWnd()->GetSafeHwnd(), _T("open"), | |
| 493 strFileName, NULL, NULL, SW_SHOWNORMAL, AfxGetInstanceHandle( )}; | |
| 494 | |
| 495 sei.hInstApp=0; | |
| 496 HINSTANCE hInst=ShellExecute(AfxGetMainWnd()->GetSafeHwnd(),_T("open"), strFileName, NULL, _T("."), 0)/*ShellExecuteEx(&sei)*/; | |
| 497 if(int(hInst)<=32/*sei.hInstApp==0*/) | |
| 498 { | |
| 499 CString str; | |
| 500 switch(int(hInst)) | |
| 501 { | |
| 502 case 0 : str=_T("The operating system is out of memory or resources. ");break; | |
| 503 case ERROR_FILE_NOT_FOUND : str=_T("The specified file was not found. ");break; | |
| 504 case ERROR_PATH_NOT_FOUND : str=_T("The specified path was not found. ");break; | |
| 505 case ERROR_BAD_FORMAT : str=_T("The .EXE file is invalid (non-Win32 .EXE or error in .EXE image). ");break; | |
| 506 case SE_ERR_ACCESSDENIED : str=_T("The operating system denied access to the specified file. ");break; | |
| 507 case SE_ERR_ASSOCINCOMPLETE : str=_T("The filename association is incomplete or invalid. ");break; | |
| 508 case SE_ERR_DDEBUSY : str=_T("The DDE transaction could not be completed because other DDE transactions were being processed. ");break; | |
| 509 case SE_ERR_DDEFAIL : str=_T("The DDE transaction failed. ");break; | |
| 510 case SE_ERR_DDETIMEOUT : str=_T("The DDE transaction could not be completed because the request timed out. ");break; | |
| 511 case SE_ERR_DLLNOTFOUND : str=_T("The specified dynamic-link library was not found. ");break; | |
| 512 //case SE_ERR_FNF : str=_T("The specified file was not found. ");break; | |
| 513 case SE_ERR_NOASSOC : str=_T("There is no application associated with the given filename extension. ");break; | |
| 514 case SE_ERR_OOM : str=_T("There was not enough memory to complete the operation. ");break; | |
| 515 //case SE_ERR_PNF : str=_T("The specified path was not found. ");break; | |
| 516 case SE_ERR_SHARE : str=_T("A sharing violation occurred. ");break; | |
| 517 default: str=_T("An unexpected error occurred");break; | |
| 518 } | |
| 519 CUtils::MessageBoxF(_T("Failed to open document %s using %s.\r\n%s"),strFileName,szExe,str); | |
| 520 } else { | |
| 521 rc=true; | |
| 522 } | |
| 523 } | |
| 524 } | |
| 525 return rc; | |
| 526 } | |
| 527 | |
| 528 /* | |
| 529 void CConfigToolApp::AddToRecentFileList(LPCTSTR lpszPathName) | |
| 530 { | |
| 531 const CFileName strDir=CFileName(lpszPathName).Head(); | |
| 532 if(strDir.IsDir()){ | |
| 533 CWinApp::AddToRecentFileList(strDir); | |
| 534 } | |
| 535 } | |
| 536 */ | |
| 537 | |
| 538 int CConfigToolApp::GetRepositoryRegistryClues(CStringArray &arstr,LPCTSTR pszPrefix) | |
| 539 { | |
| 540 // Go looking for potential candidates in SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths | |
| 541 arstr.RemoveAll(); | |
| 542 CRegKeyEx k1(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths"),KEY_READ); | |
| 543 CString strKey; | |
| 544 for(int i=0;k1.QueryKey(i,strKey);i++){ | |
| 545 if(0==strKey.Find(pszPrefix)){ | |
| 546 CRegKeyEx k2((HKEY)k1,strKey,KEY_READ); | |
| 547 CFileName strDir; | |
| 548 if(k2.QueryValue(_T("Path"),strDir) && strDir.IsDir()){ | |
| 549 arstr.Add(strDir); | |
| 550 } | |
| 551 } | |
| 552 } | |
| 553 return arstr.GetSize(); | |
| 554 } | |
| 555 | |
| 556 | |
| 557 void CAboutDlg::OnLButtonDblClk(UINT nFlags, CPoint point) | |
| 558 { | |
| 559 UNUSED_ALWAYS(point); | |
| 560 UNUSED_ALWAYS(nFlags); | |
| 561 } | |
| 562 | |
| 563 //const char CConfigToolApp::s_profileFlags[] = _T("flags"); | |
| 564 LPCTSTR CConfigToolApp::s_profileMax = _T("max"); | |
| 565 LPCTSTR CConfigToolApp::s_profileTool = _T("tool"); | |
| 566 LPCTSTR CConfigToolApp::s_profileStatus = _T("status"); | |
| 567 LPCTSTR CConfigToolApp::s_profileRect = _T("Rect"); | |
| 568 | |
| 569 void CConfigToolApp::SaveWindowPlacement(CWnd *pWnd, const CString &strKey) | |
| 570 { | |
| 571 // Our position | |
| 572 CString strText; | |
| 573 | |
| 574 WINDOWPLACEMENT wndpl; | |
| 575 wndpl.length = sizeof(WINDOWPLACEMENT); | |
| 576 // gets current window position and | |
| 577 // iconized/maximized status | |
| 578 pWnd->GetWindowPlacement(&wndpl); | |
| 579 strText.Format(_T("%04d %04d %04d %04d"), | |
| 580 wndpl.rcNormalPosition.left, | |
| 581 wndpl.rcNormalPosition.top, | |
| 582 wndpl.rcNormalPosition.right, | |
| 583 wndpl.rcNormalPosition.bottom); | |
| 584 if(!pWnd->IsWindowVisible()){ | |
| 585 wndpl.showCmd=SW_HIDE; | |
| 586 } | |
| 587 WriteProfileInt (strKey,_T("Show"), wndpl.showCmd); | |
| 588 WriteProfileString(strKey,s_profileRect, strText); | |
| 589 } | |
| 590 | |
| 591 BOOL CConfigToolApp::RestoreWindowPlacement(CWnd *pWnd,const CString &strKey,const CRect &rcDefault) | |
| 592 { | |
| 593 // Set the windows according to registry settings | |
| 594 CString strText; | |
| 595 WINDOWPLACEMENT wndpl; | |
| 596 CRect rect; | |
| 597 | |
| 598 strText = GetProfileString(strKey,s_profileRect); | |
| 599 if (!strText.IsEmpty()) { | |
| 600 rect.left = _ttoi((LPCTSTR ) strText); | |
| 601 rect.top = _ttoi((LPCTSTR ) strText + 5); | |
| 602 rect.right = _ttoi((LPCTSTR ) strText + 10); | |
| 603 rect.bottom = _ttoi((LPCTSTR ) strText + 15); | |
| 604 } else { | |
| 605 rect = rcDefault; | |
| 606 } | |
| 607 | |
| 608 CRect rcMax; | |
| 609 SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcMax, 0); | |
| 610 | |
| 611 if(rect.Width()<100 || rect.Height()<100 || rect.Width()>rcMax.Width() || rect.Height()>rcMax.Height()){ | |
| 612 rect=rcDefault; | |
| 613 } | |
| 614 | |
| 615 wndpl.length = sizeof(WINDOWPLACEMENT); | |
| 616 wndpl.showCmd = GetProfileInt(strKey,_T("Show"),SW_SHOWNA); | |
| 617 wndpl.flags = 0; | |
| 618 | |
| 619 wndpl.ptMinPosition = CPoint(0, 0); | |
| 620 wndpl.ptMaxPosition =CPoint(-::GetSystemMetrics(SM_CXBORDER),-::GetSystemMetrics(SM_CYBORDER)); | |
| 621 wndpl.rcNormalPosition = rect; | |
| 622 | |
| 623 // sets window's position and iconized/maximized status | |
| 624 return pWnd->SetWindowPlacement(&wndpl); | |
| 625 } | |
| 626 | |
| 627 void CConfigToolApp::LoadFont(const CString & strKey, LOGFONT & lf) | |
| 628 { | |
| 629 lf.lfHeight =(LONG)GetProfileInt(strKey,_T("Height"),0); | |
| 630 if(0==lf.lfHeight){ | |
| 631 CFont font; | |
| 632 font.Attach(HFONT(GetStockObject(DEFAULT_GUI_FONT))); | |
| 633 font.GetLogFont(&lf); | |
| 634 } else { | |
| 635 lf.lfWidth =(LONG)GetProfileInt(strKey,_T("Width"),0); | |
| 636 lf.lfEscapement =(LONG)GetProfileInt(strKey,_T("Escapement"),0); | |
| 637 lf.lfOrientation =(LONG)GetProfileInt(strKey,_T("Orientation"),0); | |
| 638 lf.lfWeight =(LONG)GetProfileInt(strKey,_T("Weight"),0); | |
| 639 lf.lfItalic =(BYTE)GetProfileInt(strKey,_T("Italic"),0); | |
| 640 lf.lfUnderline =(BYTE)GetProfileInt(strKey,_T("Underline"),0); | |
| 641 lf.lfStrikeOut =(BYTE)GetProfileInt(strKey,_T("StrikeOut"),0); | |
| 642 lf.lfCharSet =(BYTE)GetProfileInt(strKey,_T("CharSet"),0); | |
| 643 lf.lfOutPrecision =(BYTE)GetProfileInt(strKey,_T("OutPrecision"),0); | |
| 644 lf.lfClipPrecision =(BYTE)GetProfileInt(strKey,_T("ClipPrecision"),0); | |
| 645 lf.lfQuality =(BYTE)GetProfileInt(strKey,_T("Quality"),0); | |
| 646 lf.lfPitchAndFamily =(BYTE)GetProfileInt(strKey,_T("PitchAndFamily"),0); | |
| 647 CString strFaceName =GetProfileString(strKey,_T("FaceName"),_T("")); | |
| 648 if(strFaceName.GetLength()<=31){ | |
| 649 _tcscpy(lf.lfFaceName,strFaceName); | |
| 650 } else { | |
| 651 lf.lfFaceName[0]=_TCHAR('\0'); | |
| 652 } | |
| 653 } | |
| 654 } | |
| 655 | |
| 656 void CConfigToolApp::SaveFont(const CString & strKey, const LOGFONT & lf) | |
| 657 { | |
| 658 WriteProfileInt(strKey,_T("Height"), (int)lf.lfHeight); | |
| 659 WriteProfileInt(strKey,_T("Width"), (int)lf.lfWidth); | |
| 660 WriteProfileInt(strKey,_T("Escapement"), (int)lf.lfEscapement); | |
| 661 WriteProfileInt(strKey,_T("Orientation"), (int)lf.lfOrientation); | |
| 662 WriteProfileInt(strKey,_T("Weight"), (int)lf.lfWeight); | |
| 663 WriteProfileInt(strKey,_T("Italic"), (int)lf.lfItalic); | |
| 664 WriteProfileInt(strKey,_T("Underline"), (int)lf.lfUnderline); | |
| 665 WriteProfileInt(strKey,_T("StrikeOut"), (int)lf.lfStrikeOut); | |
| 666 WriteProfileInt(strKey,_T("CharSet"), (int)lf.lfCharSet); | |
| 667 WriteProfileInt(strKey,_T("OutPrecision"), (int)lf.lfOutPrecision); | |
| 668 WriteProfileInt(strKey,_T("ClipPrecision"), (int)lf.lfClipPrecision); | |
| 669 WriteProfileInt(strKey,_T("Quality"), (int)lf.lfQuality); | |
| 670 WriteProfileInt(strKey,_T("PitchAndFamily"),(int)lf.lfPitchAndFamily); | |
| 671 WriteProfileString(strKey,_T("FaceName"), lf.lfFaceName); | |
| 672 } | |
| 673 | |
| 674 CEditView *CConfigTool::m_pEditView=NULL; | |
| 675 COutputView *CConfigTool::m_pOutputView=NULL; | |
| 676 CControlView *CConfigTool::m_pControlView=NULL; | |
| 677 CCellView *CConfigTool::m_pCellView=NULL; | |
| 678 CDescView *CConfigTool::m_pDescView=NULL; | |
| 679 CPropertiesView *CConfigTool::m_pPropertiesView=NULL; | |
| 680 CRulesView *CConfigTool::m_pRulesView=NULL; | |
| 681 CConfigToolDoc *CConfigTool::m_pConfigToolDoc=NULL; | |
| 682 CMainFrame *CConfigTool::m_pMain=NULL; | |
| 683 CMLTView *CConfigTool::m_pMLTView=NULL; | |
| 684 | |
| 685 CControlView *CConfigTool::GetControlView() { return m_pControlView; } | |
| 686 COutputView *CConfigTool::GetOutputView() { return m_pOutputView; } | |
| 687 CCellView *CConfigTool::GetCellView() { return m_pCellView; } | |
| 688 CDescView *CConfigTool::GetDescView() { return m_pDescView; } | |
| 689 CPropertiesView *CConfigTool::GetPropertiesView() { return m_pPropertiesView; } | |
| 690 CRulesView *CConfigTool::GetRulesView() { return m_pRulesView; } | |
| 691 CMLTView *CConfigTool::GetMLTView() { return m_pMLTView; } | |
| 692 | |
| 693 void CConfigTool::SetDocument(CConfigToolDoc *pDoc) {m_pConfigToolDoc=pDoc; } | |
| 694 void CConfigTool::SetMain(CMainFrame * pMain) { m_pMain=pMain; } | |
| 695 void CConfigTool::SetControlView(CControlView *pControlView) {m_pControlView=pControlView; } | |
| 696 void CConfigTool::SetOutputView(COutputView *pOutputView) {m_pOutputView=pOutputView; } | |
| 697 void CConfigTool::SetCellView(CCellView *pCellView) {m_pCellView=pCellView; } | |
| 698 void CConfigTool::SetDescView(CDescView *pDescView) {m_pDescView=pDescView; } | |
| 699 void CConfigTool::SetMLTView(CMLTView *pMLTView) {m_pMLTView=pMLTView; } | |
| 700 void CConfigTool::SetPropertiesView(CPropertiesView *pPropertiesView) {m_pPropertiesView=pPropertiesView; } | |
| 701 void CConfigTool::SetRulesView(CRulesView *pRulesView) {m_pRulesView=pRulesView; } | |
| 702 CMainFrame *CConfigTool::GetMain() | |
| 703 { | |
| 704 CWnd *pWnd=AfxGetMainWnd(); | |
| 705 return (pWnd && pWnd->IsKindOf(RUNTIME_CLASS(CMainFrame)))?(CMainFrame*)pWnd:NULL; | |
| 706 } | |
| 707 | |
| 708 int CConfigTool::Log(LPCTSTR pszFormat, ...) | |
| 709 { | |
| 710 va_list marker; | |
| 711 va_start (marker, pszFormat); | |
| 712 | |
| 713 for(int nLength=100;nLength;) { | |
| 714 TCHAR *buf=new TCHAR[1+nLength]; | |
| 715 int n=_vsntprintf(buf, nLength, pszFormat, marker ); | |
| 716 if(-1==n){ | |
| 717 nLength*=2; // NT behavior | |
| 718 } else if (n<nLength){ | |
| 719 CWnd *pMain=CConfigTool::GetMain(); | |
| 720 if(pMain){ | |
| 721 // During startup the main window will be the splash screen | |
| 722 COutputView *pView=CConfigTool::GetOutputView(); | |
| 723 if(pView){ | |
| 724 pView->AddText(buf); | |
| 725 pView->AddText(_T("\r\n")); | |
| 726 } | |
| 727 } | |
| 728 ((CConfigToolApp *)AfxGetApp())->m_strBufferedLogMessages+=buf; | |
| 729 ((CConfigToolApp *)AfxGetApp())->m_strBufferedLogMessages+=_T("\r\n"); | |
| 730 nLength=0; // trigger exit from loop | |
| 731 } else { | |
| 732 nLength=n+1; // UNIX behavior generally, or NT behavior when buffer size exactly matches required length | |
| 733 } | |
| 734 delete [] buf; | |
| 735 } | |
| 736 | |
| 737 va_end (marker); | |
| 738 | |
| 739 return 0; | |
| 740 } | |
| 741 | |
| 742 void CConfigTool::DismissSplash() | |
| 743 { | |
| 744 CSplashWnd::EnableSplashScreen(FALSE); | |
| 745 } | |
| 746 | |
| 747 CString CConfigToolApp::GetInstallVersionKey () | |
| 748 { | |
| 749 CString strKey = _T("SOFTWARE\\Red Hat\\eCos"); | |
| 750 CString strVersionKey = _T(""); | |
| 751 CString rc = _T(""); | |
| 752 TCHAR pszBuffer [MAX_PATH + 1]; | |
| 753 HKEY hKey; | |
| 754 | |
| 755 // get the greatest eCos version subkey | |
| 756 if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) { | |
| 757 DWORD dwIndex = 0; | |
| 758 while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) { | |
| 759 if (strVersionKey.Compare (pszBuffer) < 0) { | |
| 760 strVersionKey = pszBuffer; | |
| 761 } | |
| 762 } | |
| 763 RegCloseKey (hKey); | |
| 764 } | |
| 765 return strKey + _T("\\") + strVersionKey; | |
| 766 } |
