⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcprojprocess.cpp

📁 能够把VC7.0-8.0的工程转换到VC6.0的工程
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				m_outputFile.Write(s);

				// manage all files inside
				//
				writeDspGroup(pElem);

				// finish group of files
				s = "# End Group\r\n";
				m_outputFile.Write(s);
			}
				
		} // end if pNode

	} // end for
}


void vcprojprocess::writeDspFileConfigurations(COString &szFilename, ConfigurationArray &arrFileConfigs, ConfigurationArray &projectConfigs)
{

	// make sure we have anything to output here
	long nConfigNb = arrFileConfigs.GetSize();
	if (nConfigNb==0) return;

	COString s;

	for (long i=0; i<nConfigNb; i++)
	{
		if (i==0)
			s = "\r\n!IF  \"$(CFG)\" == \"";
		else
			s = "!ELSEIF  \"$(CFG)\" == \"";

		vcprojconfiguration *pConfig = arrFileConfigs.GetAt(i);

		COString szConfigName = pConfig->getConfigName();

		s += TranslateConfigurationName( szConfigName ) + "\"\r\n\r\n";

		m_outputFile.Write(s);


		// do we have an intermediate directory
		// 
		COString szIntermediateDirectory;
		szIntermediateDirectory = pConfig->VCCLCompilerTool.GetValue("ObjectFile");
		if (!szIntermediateDirectory.IsEmpty())
		{
			s = "# PROP Intermediate_Dir \"" + szIntermediateDirectory + "\"\r\n";
			m_outputFile.Write(s);
		}


		// do we exclude this file from the build ?
		//
		if ( pConfig->General.GetValue("ExcludedFromBuild").CompareNoCase("TRUE") )
		{
			s = "# PROP Exclude_From_Build 1\r\n\r\n";
			m_outputFile.Write(s);
		}
		else // do we have a custom build, or any standard build tool ?
		{

			// find the equivalent project configuration
			// (debug project configuration, if this file configuration is debug)
			long nbProjConfigs = projectConfigs.GetSize();
			BOOL bFound = FALSE;
			vcprojconfiguration *pProjConfig = NULL;
			for (long iP=0; iP<projectConfigs.GetSize() && !bFound; iP++)
			{
				pProjConfig = projectConfigs.GetAt(iP);
				if (pProjConfig)
				{
					s = pProjConfig->getConfigName();;
					bFound = ( s.CompareNoCase(szConfigName) );
				}
			}
			pConfig->setMasterProjConfigurations( bFound ? pProjConfig : NULL );


			if (pConfig->VCCustomBuildTool.GetValue("Name").IsEmpty()) // standard build
			{

				if ( !pConfig->VCCLCompilerTool.GetValue("Name").IsEmpty() )
				{
					// build compiling symbols line
					//
					COString szCPPSymbols = pConfig->serializeCPPSymbols(TRUE);
					int nPrcmpHeadersTag;
					if ( (nPrcmpHeadersTag=szCPPSymbols.Find(0,"PRECOMP_VC7_TOBEREMOVED"))>-1 )
					{
						szCPPSymbols = szCPPSymbols.Left(nPrcmpHeadersTag) + szCPPSymbols.ExcludeLeft(nPrcmpHeadersTag+strlen("PRECOMP_VC7_TOBEREMOVED")+1);

						s = "# ADD CPP " + szCPPSymbols + "\r\n";
						s += "# SUBTRACT CPP /YX /Yc /Yu\r\n";
					}
					else
						s = "# ADD CPP " + szCPPSymbols + "\r\n";

					m_outputFile.Write(s);
				}
				else if ( !pConfig->VCResourceCompilerTool.GetValue("Name").IsEmpty() )
				{
					// build ResourceCompiler symbol line
					//
					COString szResourceSymbols = pConfig->serializeResourceSymbols(TRUE);
					s = "# ADD RSC " + szResourceSymbols + "\r\n";
					m_outputFile.Write(s);
				}
				else if ( !pConfig->VCMidlTool.GetValue("Name").IsEmpty() )
				{
					// build Midl symbol line
					//
					COString szMidlSymbols = pConfig->serializeMidlSymbols(TRUE);
					s = "# ADD MTL " + szMidlSymbols + "\r\n";
					m_outputFile.Write(s);
				}

			}
			else // custom build
			{
				s = "# PROP Ignore_Default_Tool 1\r\n";
				m_outputFile.Write(s);


				// build CustomBuild cmd line
				//
				COString szCustomBuildDescription;
				ArrayCString arrCustomBuildCommands;
				ArrayCString arrCustomOutputFiles;
				ArrayCString arrAdditionalDeps;
				pConfig->serializeCustomBuildCommands(	szCustomBuildDescription, 
														arrCustomBuildCommands,
														arrCustomOutputFiles,
														arrAdditionalDeps,
														TRUE);


				// custom build (optional)
				if ( arrCustomBuildCommands.GetSize()>0 )
				{
					long j;

					// write user deps
					if (arrAdditionalDeps.GetSize()>0)
					{
						s = "USERDEP_FILE=";

						for (j=0; j<arrAdditionalDeps.GetSize(); j++)
						{
							s += "\"";
							s += arrAdditionalDeps.GetAt(j);
							s += "\"\t";
						}
						s += "\r\n";
						m_outputFile.Write(s);
					}

					s = "# Begin Custom Build - " + szCustomBuildDescription + "\r\n";
					m_outputFile.Write(s);
					s = "SOURCE=\"$(InputPath)\"\r\n"; // don't know why VC++ 6.0 needs this
					m_outputFile.Write(s);
					s = "\r\nBuildCmds= \\\r\n";
					m_outputFile.Write(s);

					for (j=0; j<arrCustomBuildCommands.GetSize(); j++)
					{
						s = "\t";
						s += arrCustomBuildCommands.GetAt(j);
						s += " \\\r\n";
						m_outputFile.Write(s);
					}
					s = "\r\n";
					m_outputFile.Write(s);

					for (j=0; j<arrCustomOutputFiles.GetSize(); j++)
					{
						s = "\r\n\"";
						s += arrCustomOutputFiles.GetAt(j);
						s += "\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n";
						s += "   $(BuildCmds)\r\n";
						m_outputFile.Write(s);
					}

					s = "# End Custom Build\r\n";
					m_outputFile.Write(s);

					s = "\r\n";
					m_outputFile.Write(s);
				}



			}

		}

	}

	s = "!ENDIF\r\n\r\n";
	m_outputFile.Write(s);

}

void vcprojprocess::writeDspFooter()
{
	COString s ="# End Target\r\n";
	m_outputFile.Write(s);
	s = "# End Project\r\n\r\n";
	m_outputFile.Write(s);
}

// isFullPath -------------------------------
//
// purpose : tells if 'szFilepath' is a fully qualified filepath, or a relative path
BOOL vcprojprocess::isFullPath(COString &szFilepath)
{
	BOOL bResult = TRUE;

	// extract directory
	long i = m_szSolutionName.ReverseFind(0, '\\');
	if (i==-1) return TRUE;

	COString szDirectory = m_szSolutionName.Left(i+1);

	// try to find the file made whose full filepath is "directory"+"finalpath"
	COString szFullfilepath = szDirectory + szFilepath;

	HANDLE hFind;
	WIN32_FIND_DATA fd;

	if ((hFind=::FindFirstFile(szFullfilepath,&fd))==INVALID_HANDLE_VALUE)
	{
		return TRUE;
	}

	::FindClose(hFind);

	return FALSE;
}


void vcprojprocess::getAttribValue(/*in*/IXMLDOMElement *p, /*in*/char *szAttribName, /*out*/COString &szValue)
{
	szValue.Empty();
	if (!p) return;

	VARIANT vtValue;
	p->getAttribute( _bstr_t(szAttribName), &vtValue);
	VARIANT_to_CString( vtValue, szValue);
}

void vcprojprocess::getNodeName(/*in*/IXMLDOMElement *p, /*out*/COString &szName)
{
	szName.Empty();
	if (!p) return;

	BSTR bstrName;
	p->get_nodeName(&bstrName);
	BSTR_to_CString(bstrName,szName);
}


void vcprojprocess::VARIANT_to_CString(/*in*/VARIANT &vt, /*out*/COString &s)
{
	s.Empty();

	if (vt.vt!=VT_BSTR) return;

	_bstr_t bstrTag(vt);

	UINT uLen = bstrTag.length();
	if (uLen==0) return;

	TCHAR *szTemp= new TCHAR[uLen+1];
	memset (szTemp, 0, uLen+1);

	LPOLESTR wszTag = bstrTag; // get ptr to Unicode

	int iBytes = ::WideCharToMultiByte(CP_ACP, 0,
			wszTag, uLen,
			szTemp, uLen, NULL, NULL);

	s = szTemp;

	delete [] szTemp;

	::SysFreeString(vt.bstrVal);
}


void vcprojprocess::BSTR_to_CString(/*in*/BSTR bstr, /*out*/COString &s)
{
	s.Empty();

	_bstr_t bstrTag(bstr);

	UINT uLen = bstrTag.length();
	if (uLen==0) return;

	TCHAR *szTemp= new TCHAR[uLen+1];
	memset (szTemp, 0, uLen+1);

	LPOLESTR wszTag = bstrTag; // get ptr to Unicode

	int iBytes = ::WideCharToMultiByte(CP_ACP, 0,
			wszTag, uLen,
			szTemp, uLen, NULL, NULL);

	s = szTemp;

	delete [] szTemp;

	::SysFreeString(bstr);
}

COString vcprojprocess::TranslateConfigurationName(COString &sInputConfigName)
{
	COString s;
	s = m_szProjname + " - ";

	long i = sInputConfigName.Find(0,'|');
	if (i>-1)
	{
		COString sConfig = sInputConfigName.Left(i);
		COString sPlatform = sInputConfigName.ExcludeLeft(i+1);
		s += sPlatform + " " + sConfig;
	}
	else
		s += sInputConfigName;

	return s;
}

COString vcprojprocess::ExtractPlatform(COString &sInputConfigName)
{
	COString s;
	long i = sInputConfigName.Find(0,'|');
	if (i>-1)
		s= sInputConfigName.ExcludeLeft(i+1);

	return s;
}


void vcprojprocess::TokenizeString(/*in*/COString &szInput, char cToken, /*out*/ArrayCString &arrStrings)
{
	long i;

	COString s = szInput;

	arrStrings.RemoveAll();

	while ( (i=s.Find(0,cToken))>-1 )
	{
		arrStrings.Add( s.Left(i) );
		s = s.ExcludeLeft(i+1);
	}
	if (!s.IsEmpty())
		arrStrings.Add ( s );
}


void vcprojprocess::UntokenizeString(/*in*/ArrayCString &arrStrings, char cToken, /*out*/COString &szOutput)
{
	szOutput.Empty();

	for (long i=0;i<arrStrings.GetSize(); i++)
	{
		if (!szOutput.IsEmpty()) szOutput += cToken;

		szOutput += arrStrings.GetAt(i);
	}
}

void __stdcall _com_issue_error(HRESULT)
{
}

int vcprojprocess::ConvertToVS7(COString &strPrjFileName)
{
	HRESULT hr;
	IXMLDOMDocument *pXMLDoc=NULL,*pMainRoot=NULL;

	hr = ::CoCreateInstance(CLSID_DOMDocument, 
							NULL, 
							CLSCTX_INPROC_SERVER, 
							IID_IXMLDOMDocument, 
							(void**)&pXMLDoc);

	if (FAILED(hr))
	{
		if (AfxMessageBox("无法加载msxml2.dll\n"
					 "你需要下载MSXML 2.0运行库后执行转换工作\n"
					 "地址是:\nhttp://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/766/msdncompositedoc.xml\n\n"
					 "是否自动转到该页面下载?"
					 ,MB_OKCANCEL)
					 == IDOK)
		{
			ShellExecute(0, NULL, "http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/766/msdncompositedoc.xml", NULL,NULL, SW_NORMAL);
		}
		return -1;
	}

	VARIANT_BOOL vtbool;
	_variant_t bstrFilepath(strPrjFileName.GetData());

	pXMLDoc->put_async( VARIANT_BOOL(FALSE) );

	hr = pXMLDoc->load(bstrFilepath,&vtbool);

	if (FAILED(hr) || vtbool==VARIANT_FALSE)
	{
		CString strErr;
		strErr.Format("无法加载:%s\n文件被其他程序占用了?",strPrjFileName);
		AfxMessageBox(strErr);
		pXMLDoc->Release();
		return -1;
	} 

	
	pXMLDoc->selectSingleNode(_variant_t("//VisualStudioProject").bstrVal,(IXMLDOMNode **)&pMainRoot);
	if (pMainRoot)
	{
		IXMLDOMNamedNodeMap *pAttriMap=NULL;
		pMainRoot->get_attributes(&pAttriMap);
		if (pAttriMap)
		{
			IXMLDOMDocument *pVerNode=NULL;
			pAttriMap->getNamedItem(_variant_t("Version").bstrVal,(IXMLDOMNode **)&pVerNode);
			if (pVerNode)
			{
				pVerNode->put_text(_variant_t("7.10").bstrVal);
			
				pXMLDoc->save(bstrFilepath);
			}
		}
	}

	pXMLDoc->Release();
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -