📄 ctcommondoc.cpp
字号:
strNewRepository=pszRepository?pszRepository:m_strRepository; bPromptInitially=true; } IM.Set (_T("Opening repository ") + (CString) strNewRepository); CdlPackagesDatabase NewCdlPkgData = NULL; CdlInterpreter NewCdlInterp = NULL; CdlConfiguration NewCdlConfig = NULL; CFileName strNewPackagesDir; EnableCallbacks(false); // disable transaction callbacks until the config tree is regenerated if(OpenRepository(strNewRepository,NewCdlPkgData,NewCdlInterp,NewCdlConfig,strNewPackagesDir)){ // Success // select the "default" template if it exists // otherwise select the first available template std::string default_template = "default"; if (! NewCdlPkgData->is_known_template (default_template)) { const std::vector<std::string>& templates = NewCdlPkgData->get_templates (); if (templates.size () != 0) default_template = templates [0]; } m_template_version = ""; try { const std::vector<std::string>& template_versions = NewCdlPkgData->get_template_versions (default_template); NewCdlConfig->set_template (default_template, template_versions [0], &CdlParseErrorHandler, &CdlParseWarningHandler); m_template_version = template_versions [0]; } catch (CdlStringException exception) { CUtils::MessageBoxF(_T("Error loading package template '%s':\n\n%s"), CString (default_template.c_str ()), CString (exception.get_message ().c_str ())); } catch (...) { CUtils::MessageBoxF(_T("Error loading package template '%s'."), CString (default_template.c_str ())); } // check the configuration ASSERT (NewCdlConfig->check_this (cyg_extreme)); // use the new package database, interpreter and configuration deleteZ(m_CdlConfig); // delete the previous configuration deleteZ(m_CdlInterp); // delete the previous interpreter deleteZ(m_CdlPkgData); // delete the previous package database m_CdlPkgData = NewCdlPkgData; m_CdlInterp = NewCdlInterp; m_CdlConfig = NewCdlConfig; // save the repository location SetRepository(strNewRepository); m_strPackagesDir = strNewPackagesDir; #ifndef PLUGIN // clear the previously specified document file name (if any), // OnNewDocument() calls DeleteContents() so must be called // before AddAllItems() CDocument::OnNewDocument ();#endif // generate the CConfigItems from their CDL descriptions AddAllItems (); m_bRepositoryOpen=true; } else { // failure deleteZ(NewCdlConfig); deleteZ(NewCdlInterp); deleteZ(NewCdlPkgData); } // install a transaction handler callback function now that the tree exists EnableCallbacks(true); } } return m_bRepositoryOpen;}// Helper fn for namesake abovebool CConfigToolDoc::OpenRepository (const CFileName strNewRepository,CdlPackagesDatabase &NewCdlPkgData,CdlInterpreter &NewCdlInterp,CdlConfiguration &NewCdlConfig,CFileName &strNewPackagesDir){ bool rc=false; TRACE(_T("###Open repository %s\n"),strNewRepository); if(!strNewRepository.IsEmpty()){ // Now strNewRepository is guaranteed non-empty, but does it exist? if(!strNewRepository.IsDir()) { CUtils::MessageBoxF(_T("Cannot open repository - the folder %s does not exist"), strNewRepository); } else { // Ok so it exists, but does it look right? strNewPackagesDir=strNewRepository+_T("ecc"); if(!strNewPackagesDir.IsDir()){ strNewPackagesDir=strNewRepository+_T("packages"); } if(!strNewPackagesDir.IsDir()){ // Don't mention the ecc\ attempt CUtils::MessageBoxF(_T("%s does not seem to be a source repository: the folder %s does not exist"), strNewRepository,strNewPackagesDir); } else { const CFileName strDatabase = strNewPackagesDir + _T("ecos.db"); if(!strDatabase.Exists()) { CUtils::MessageBoxF(_T("%s does not seem to be a source repository: %s does not exist"), strNewRepository, strDatabase); } else { // create a CDL repository, interpreter and configuration try {// create a new package database, interpreter and configuration NewCdlPkgData = CdlPackagesDatabaseBody::make (CUtils::UnicodeToStdStr(strNewPackagesDir)); NewCdlInterp = CdlInterpreterBody::make (); NewCdlConfig = CdlConfigurationBody::make ("eCos", NewCdlPkgData, NewCdlInterp); } catch (CdlStringException exception) { CUtils::MessageBoxF(_T("Error opening eCos repository:\n\n%s"), CString (exception.get_message ().c_str ())); return false; } catch (...) { CUtils::MessageBoxF(_T("Error opening eCos repository.")); return false; } // select the default target if specified in the registry // otherwise select the first available target std::string default_hardware = CUtils::UnicodeToStdStr (GetDefaultHardware ()); if (! NewCdlPkgData->is_known_target (default_hardware)) { const std::vector<std::string>& targets = NewCdlPkgData->get_targets (); if (targets.size () == 0){ CUtils::MessageBoxF (_T("Error opening eCos repository:\n\nno hardware templates")); return false; } else { default_hardware = targets [0]; } } try { m_strCdlErrorMessage = _T(""); NewCdlConfig->set_hardware (default_hardware, &CdlParseErrorHandler, &CdlParseWarningHandler); } catch (CdlStringException exception) { if (m_strCdlErrorMessage.IsEmpty ()) { CUtils::MessageBoxF (_T("Error loading the default hardware template '%s':\n\n%s"), CString (default_hardware.c_str ()), CString (exception.get_message ().c_str ())); } else // report the most recent parser message in the message box since there may be no output pane in which to view it { CUtils::MessageBoxF (_T("Error loading the default hardware template '%s':\n\n%s\n\nParser message:\n\n%s"), CString (default_hardware.c_str ()), CString (exception.get_message ().c_str ()), m_strCdlErrorMessage); } return false; } catch (...) { CUtils::MessageBoxF (_T("Error loading the default hardware template '%s':\n\n%s"), CString (default_hardware.c_str ()), m_strCdlErrorMessage); return false; } rc=true; } } } } return rc;} void CConfigToolDoc::CloseRepository(){ if(m_bRepositoryOpen){ // delete the libCDL objects with the document EnableCallbacks(false); // first disable the transaction handler deleteZ(m_CdlConfig); deleteZ(m_CdlInterp); deleteZ(m_CdlPkgData); m_bRepositoryOpen=false; }}void CConfigToolDoc::SelectTemplate (std::string NewTemplate, std::string NewTemplateVersion){ if ((NewTemplate != m_CdlConfig->get_template()) || (NewTemplateVersion != m_template_version)){ CWaitCursor wait; // this may take a little while RemoveAllItems(); m_template_version = ""; try { m_CdlConfig->set_template (NewTemplate, NewTemplateVersion, CdlParseErrorHandler, CdlParseWarningHandler); m_template_version = NewTemplateVersion; } catch (CdlStringException exception) { CUtils::MessageBoxF(_T("Error loading package template '%s':\n\n%s"), CString (NewTemplate.c_str ()), CString (exception.get_message ().c_str ())); } catch (...) { CUtils::MessageBoxF(_T("Error loading package template '%s'."), CString (NewTemplate.c_str ())); } RegenerateData(); if (!GetPathName().IsEmpty()){ // not a new document CopyMLTFiles (); // copy new MLT files to the build tree as necessary } SetModifiedFlag(); }}void CConfigToolDoc::RegenerateData(){ CWaitCursor wait; // This may take a little while AddAllItems (); // regenerate all the config items since the topology may have changed if (m_strLinkerScriptFolder.IsEmpty ()) { CUtils::MessageBoxF(_T("The eCos linker script macro CYGBLD_LINKER_SCRIPT is not defined.")); } if (m_strMemoryLayoutFolder.IsEmpty ()) { CUtils::MessageBoxF(_T("The eCos memory layout macro CYGHWR_MEMORY_LAYOUT is not defined.")); } SwitchMemoryLayout (true); // the hardware template may have changed UpdateBuildInfo(); CConfigTool::GetControlView()->SelectItem(Item(0));}void CConfigToolDoc::SelectHardware (std::string NewTemplate){ const std::string OldTemplate=m_CdlConfig->get_hardware(); if (NewTemplate != OldTemplate){ RemoveAllItems(); try { m_CdlConfig->set_hardware (NewTemplate, CdlParseErrorHandler, CdlParseWarningHandler); } catch (CdlStringException exception) { CUtils::MessageBoxF(_T("Error loading hardware template '%s':\n\n%s"), CString (NewTemplate.c_str ()), CString (exception.get_message ().c_str ())); m_CdlConfig->set_hardware (OldTemplate, CdlParseErrorHandler, CdlParseWarningHandler); } catch (...) { CUtils::MessageBoxF(_T("Error loading hardware template '%s'."), CString (NewTemplate.c_str ())); m_CdlConfig->set_hardware (OldTemplate, CdlParseErrorHandler, CdlParseWarningHandler); } RegenerateData(); //EnableCallbacks(true); // re-enable the transaction handler if (!GetPathName().IsEmpty()){ CopyMLTFiles (); // copy new MLT files to the build tree as necessary } SetModifiedFlag(); }}bool CConfigToolDoc::SaveMemoryMap(){ const CString strSuffix(_T("mlt_") + CurrentMemoryLayout ()); const CFileName strMLTInstallPkgconfDir(InstallTree() + _T("include\\pkgconf")); bool rc=false; if(strMLTInstallPkgconfDir.CreateDirectory(true)){ const CString strMLTInstallBase(strMLTInstallPkgconfDir+CFileName(strSuffix)); const CFileName strMLTDir (MLTDir()); if(strMLTDir.CreateDirectory (true)){ const CString strMLTBase (strMLTDir + CFileName (strSuffix)); TRACE(_T("Saving memory layout to %s\n"), strMLTBase + _T(".mlt")); if(MemoryMap.save_memory_layout (strMLTBase + _T(".mlt"))){ TRACE(_T("Exporting memory layout to %s\n"), strMLTInstallPkgconfDir); rc=MemoryMap.export_files (strMLTInstallBase + _T(".ldi"), strMLTInstallBase + _T(".h")); } } } return rc;}bool CConfigToolDoc::CopyMLTFiles(){ // copy default MLT files for the selected target/platform from the repository if they do not already exist TRACE (_T("Looking for MLT files at %s\n"), PackagesDir() + m_strMemoryLayoutFolder + _T("include\\pkgconf\\mlt_*.*")); const CFileName strInstallDestination(InstallTree () + _T("include\\pkgconf")); const CFileName strMLTDestination (MLTDir ()); TRACE (_T("Copying .ldi and .h files to %s\n"), strInstallDestination); TRACE (_T("Copying .mlt files to %s\n"), strMLTDestination); bool rc=strInstallDestination.CreateDirectory (true) && strMLTDestination.CreateDirectory (true); if(rc){ CFileFind ffFileFind; BOOL bLastFile = ffFileFind.FindFile (PackagesDir() + m_strMemoryLayoutFolder + _T("\\include\\pkgconf\\mlt_*.*")); while (bLastFile) { bLastFile = ffFileFind.FindNextFile (); if (_T(".mlt") == ffFileFind.GetFileName ().Right (4)) // if a .mlt file { if (! CFileName (strMLTDestination, CFileName (ffFileFind.GetFileName ())).Exists ()) { if(!CUtils::CopyFile (ffFileFind.GetFilePath (), strMLTDestination + CFileName (ffFileFind.GetFileName ()))){ return false; // message already emitted } } } else // a .h or .ldi file { if (! CFileName (strInstallDestination, CFileName (ffFileFind.GetFileName ())).Exists () && !CUtils::CopyFile (ffFileFind.GetFilePath (), strInstallDestination + CFileName (ffFileFind.GetFileName ()))){ return false; // message already emitted } } } } return rc; //FIXME}CString CConfigToolDoc::GetDefaultHardware (){ CString strKey = _T("SOFTWARE\\Red Hat\\eCos"); CString strVersionKey = _T(""); CString rc = _T(""); TCHAR pszBuffer [MAX_PATH + 1]; HKEY hKey; LONG lStatus; // get the greatest eCos version subkey if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) { DWORD dwIndex = 0; while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) { if (strVersionKey.Compare (pszBuffer) < 0) strVersionKey = pszBuffer; } RegCloseKey (hKey); if (! strVersionKey.IsEmpty ()) { TRACE (_T("CConfigToolDoc::GetDefaultHardware(): version subkey = '%s'\n"), strVersionKey); // get the default hardware value strKey += _T("\\") + strVersionKey; if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) { DWORD dwBufferSize = sizeof (pszBuffer); lStatus = RegQueryValueEx (hKey, _T("Default Hardware"), NULL, NULL, (LPBYTE) pszBuffer, &dwBufferSize); RegCloseKey (hKey); if (ERROR_SUCCESS == lStatus) { TRACE (_T("CConfigToolDoc::GetDefaultHardware(): default hardware = '%s'\n"), pszBuffer); rc=pszBuffer; } } } } return rc;}CConfigItem * CConfigToolDoc::AddItem (const CdlUserVisible vitem, CConfigItem * pParent){ CConfigItem * pItem = new CConfigItem (pParent, vitem); m_arItem.Add(pItem); pItem->m_strDesc = CUtils::StripExtraWhitespace (CString (vitem->get_description ().c_str ()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -