📄 configtool.cpp
字号:
//####COPYRIGHTBEGIN####// // ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.//// This program is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------// //####COPYRIGHTEND####// ConfigTool.cpp : Defines the class behaviors for the application.//////===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s): sdf// Contact(s): sdf// Date: 1998/08/11// Version: 0.01// Purpose: // Description: This is the implementation of the application class// Requires: // Provides: // See also: // Known bugs: // Usage: ////####DESCRIPTIONEND####////===========================================================================#include "stdafx.h"#include "ConfigTool.h"#include "ConfigToolDoc.h"#include "ControlView.h"#include "CSHDialog.h"#include "CTUtils.h"#include "eCosDialog.h"#include "eCosTest.h"#include "FileName.h"#include "MainFrm.h"#include "OutputView.h"#include "RegKeyEx.h"#include "Splash.h"#include <afxadv.h>#include <afxdisp.h> // for AfxEnableControlContainer()#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifCString CConfigTool::strHelpFile;/////////////////////////////////////////////////////////////////////////////// CConfigToolApp BEGIN_MESSAGE_MAP(CConfigToolApp, CWinApp)//{{AFX_MSG_MAP(CConfigToolApp)ON_COMMAND(ID_APP_ABOUT, OnAppAbout)//}}AFX_MSG_MAP// Standard file based document commandsON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)// Standard print setup commandON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CConfigToolApp constructionCConfigToolApp::CConfigToolApp(){ m_GrayPen.CreatePen(PS_SOLID,1,RGB(192,192,192)); m_VersionInfo.dwOSVersionInfoSize=sizeof OSVERSIONINFO; ::GetVersionEx(&m_VersionInfo);}/////////////////////////////////////////////////////////////////////////////// The one and only CConfigToolApp objectCConfigToolApp theApp;/////////////////////////////////////////////////////////////////////////////// CConfigToolApp initializationBOOL CConfigToolApp::InitInstance(){ CeCosTest::Init(); CFileName strCSHFile; ::GetModuleFileName(::GetModuleHandle(NULL),strCSHFile.GetBuffer(1+MAX_PATH),MAX_PATH); strCSHFile.ReleaseBuffer(); strCSHFile.ReplaceExtension(_T(".chm")); CConfigTool::strHelpFile=strCSHFile; CCSHDialog::SetCSHFilePath(strCSHFile); extern UINT arCommonDialogMap[]; CeCosDialog::AddDialogMap(arCommonDialogMap); extern UINT arStandaloneDialogMap[]; CeCosDialog::AddDialogMap(arStandaloneDialogMap); extern UINT arPkgAdminDialogMap[]; CeCosDialog::AddDialogMap(arPkgAdminDialogMap); extern UINT arTestToolDialogMap[]; CeCosDialog::AddDialogMap(arTestToolDialogMap); // CG: The following block was added by the Splash Screen component. \ { \ CCommandLineInfo cmdInfo; \ ParseCommandLine(cmdInfo); \ \ CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash); \ } AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. int nSize=GetEnvironmentVariable(_T("PATH"), NULL, 0); if(nSize>0){ GetEnvironmentVariable(_T("PATH"),m_strOriginalPath.GetBuffer(1+nSize),nSize); m_strOriginalPath.ReleaseBuffer(); }#ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL#else Enable3dControlsStatic(); // Call this when linking to MFC statically#endif SetRegistryKey(IDS_REGKEY); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CConfigToolDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CControlView)); AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; //ParseCommandLine(cmdInfo); CString strCmdLine(GetCommandLine()); CStringArray arArgs; int nWords=CUtils::Chop(strCmdLine,arArgs,_TCHAR(' '),/*bObserveStrings=*/true,/*bBackslashQuotes=*/false); bool bBuild=false; bool bRun=false; CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); for(int i=1;i<nWords;i++) { CString &str=arArgs[i]; if(0==str.Compare(_T("-R")) && i<nWords-1){ pDoc->SetRepository(arArgs[++i]); } else if (0==str.CompareNoCase(_T("-S")) && i<nWords-1){ // Load settings file } else if (0==str.CompareNoCase(_T("-B"))){ // Build bBuild=true; } else if (0==str.CompareNoCase(_T("-R"))){ // run bRun=true; } else { cmdInfo.m_nShellCommand=CCommandLineInfo::FileOpen; cmdInfo.m_strFileName=str; } } // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; CMenu* pMenu = m_pMainWnd->GetMenu(); if (pMenu)pMenu->DestroyMenu(); HMENU hMenu = ((CMainFrame*) m_pMainWnd)->NewMenu(); pMenu = CMenu::FromHandle( hMenu ); m_pMainWnd->SetMenu(pMenu); ((CMainFrame*)m_pMainWnd)->m_hMenuDefault = hMenu; // The one and only window has been initialized, so show and update it. m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); return TRUE;}/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog{public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; CStatic m_static; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg)protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementationprotected: //{{AFX_MSG(CAboutDlg) virtual BOOL OnInitDialog(); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); //}}AFX_MSG DECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){ //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT}void CAboutDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) DDX_Control(pDX, IDC_STATIC_ABOUT, m_static); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)//{{AFX_MSG_MAP(CAboutDlg)ON_WM_LBUTTONDBLCLK()//}}AFX_MSG_MAPEND_MESSAGE_MAP()// App command to run the dialogvoid CConfigToolApp::OnAppAbout(){ CAboutDlg aboutDlg; aboutDlg.DoModal();}/////////////////////////////////////////////////////////////////////////////// CConfigToolApp commandsint CConfigToolApp::ExitInstance() { // Save persistence info WriteProfileString(_T("Build"), _T("MakeOptions"),m_strMakeOptions); WriteProfileString(CUtils::LoadString(IDS_KEY_USER_DIR), _T("Folder"), m_strUserToolsDir); // Write any target bindirs to the registry for(POSITION pos = m_arstrBinDirs.GetStartPosition(); pos != NULL; ){ CString strPrefix,strBinDir; m_arstrBinDirs.GetNextAssoc(pos, strPrefix, strBinDir); WriteProfileString(CUtils::LoadString(IDS_KEY_TOOLS_DIR),strPrefix,strBinDir); } ::DeleteFile(CConfigToolDoc::HTMLHelpLinkFileName()); CeCosTest::Term(); return CWinApp::ExitInstance();}void CConfigToolApp::LoadStdProfileSettings(){ CWinApp::LoadStdProfileSettings(4); CString strNotepad; FindExecutable(_T("Notepad.exe"),_T(""),strNotepad.GetBuffer(MAX_PATH)); strNotepad.ReleaseBuffer(); m_strMakeOptions= GetProfileString(_T("Build"), _T("MakeOptions"),_T("")); if(m_strMakeOptions.IsEmpty()){ SYSTEM_INFO SystemInfo; GetSystemInfo(&SystemInfo); m_strMakeOptions.Format(_T("-j%d"),SystemInfo.dwNumberOfProcessors); } CRegKeyEx InstallKey (HKEY_LOCAL_MACHINE, GetInstallVersionKey (), KEY_READ); m_strUserToolsDir= GetProfileString(CUtils::LoadString(IDS_KEY_USER_DIR), _T("Folder"), _T("")); if(!m_strUserToolsDir.IsDir()){ // if the user specified user tools dir does not exist InstallKey.QueryValue (_T("Default User Tools Path"), m_strUserToolsDir); // use the installer default if (!m_strUserToolsDir.IsDir()) { // if the default user tools dir does not exist m_strUserToolsDir=_T(""); // force prompting for the user tools dir } } // set default build tools binary directories as specified by the installer CFileName strDefaultBuildToolsPath; if (InstallKey.QueryValue (_T("Default Build Tools Path"), strDefaultBuildToolsPath)) { // look for *-gcc.exe in the default build tools directory CFileFind finder; BOOL bMore=finder.FindFile (strDefaultBuildToolsPath + _T("*-gcc.exe")); while (bMore) { // for each file matching the globbing pattern bMore = finder.FindNextFile (); CFileName strFile (finder.GetFileName ()); m_arstrBinDirs.SetAt (strFile.Left (strFile.Find (_T("-gcc"))), strDefaultBuildToolsPath); } } CRegKeyEx k; k.Attach(GetSectionKey(CUtils::LoadString(IDS_KEY_TOOLS_DIR))); CFileName strDir; CString strPrefix; for(int i=0;k.QueryValue(i,strPrefix,strDir);i++){ if(strDir.IsDir()){ m_arstrBinDirs.SetAt(strPrefix,strDir); } } CStringArray arstrToolChainPaths; GetRepositoryRegistryClues(arstrToolChainPaths,_T("GNUPro eCos")); for(i=0;i<arstrToolChainPaths.GetSize();i++){ CFileName strDir(arstrToolChainPaths[i]); strDir+="H-i686-cygwin32\\bin"; if(strDir.IsDir()){ // This is a potential toolchain location. Look for *-gcc.exe CFileFind finder; BOOL bMore=finder.FindFile(strDir+"*-gcc.exe"); while (bMore) { bMore = finder.FindNextFile(); CFileName strFile(finder.GetFileName()); m_arstrBinDirs.SetAt(strFile.Left(strFile.Find(_T("-gcc"))),strDir); } } } GetRepositoryRegistryClues(m_arstrUserToolPaths, _T("GNUPro unsupported")); for(i=0;i<m_arstrUserToolPaths.GetSize();i++){ CFileName str(m_arstrUserToolPaths[i]); str+="H-i686-cygwin32\\bin"; if(str.IsDir()){ m_arstrUserToolPaths.SetAt(i,str); } else { m_arstrUserToolPaths.RemoveAt(i); i--; } } // Include the path in the set of potential user paths { CString strPath; int nSize=GetEnvironmentVariable(CUtils::LoadString(IDS_PATH), NULL, 0); if(nSize>0){ GetEnvironmentVariable(CUtils::LoadString(IDS_PATH), strPath.GetBuffer(nSize), nSize); strPath.ReleaseBuffer(); CStringArray arstrPath; CUtils::Chop(strPath,arstrPath,_TCHAR(';')); for(int i=arstrPath.GetSize()-1;i>=0;--i){ // Reverse order is important to treat path correctly const CFileName &strFolder=arstrPath[i]; CFileName strFile(strFolder); strFile+=_T("ls.exe");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -