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

📄 vcprojprocess.cpp

📁 将VC7.0和VC.NET的工程转换到VC6.0的工程,内有详细的介绍做法(自己试验后写的)
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	s = "MTL=midl.exe\r\n";
	m_outputFile.Write(s);
	s = "RSC=rc.exe\r\n\r\n";
	m_outputFile.Write(s);
}	


void vcprojprocess::writeDspConfigurations(IXMLDOMDocument *pDoc)
{
	if (!pDoc) return;

	// all configs
	long nConfigNb = m_arrConfigs.GetSize();
	if (nConfigNb==0) return;

	CString s;

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

		vcprojconfiguration *pConfig = m_arrConfigs.GetAt(i);

		CString szConfigName = pConfig->getConfigName();

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

		m_outputFile.Write(s);

		if ( m_szTargetType.Compare("0") && pConfig->hasVCConfigTool(CString(VCNMAKETOOL)) )
		{
			// that's a makefile project, no need of muscles here
			writeDspMakefile(i);
		}
		else
		{

			CString szUseMFC = "0";
			CString szTemp = pConfig->General.GetValue("UseOfMFC");
			if (szTemp.CompareNoCase("1"))
				szUseMFC = "5"; // MFC statically linked
			else if (szTemp.CompareNoCase("2"))
				szUseMFC = "6"; // MFC as shared DLL

			s = "# PROP BASE Use_MFC " + szUseMFC + "\r\n";
			m_outputFile.Write(s);
			s = "# PROP BASE Use_Debug_Libraries ";
			s += (szConfigName.FindNoCase(0,"debug")>-1) ? "1" : "0";
			s += "\r\n";
			m_outputFile.Write(s);
			s = "# PROP BASE Output_Dir \"";
			s += pConfig->General.GetValue("OutputDirectory");
			s += "\"\r\n";
			m_outputFile.Write(s);
			s = "# PROP BASE Intermediate_Dir \"";
			s += pConfig->General.GetValue("IntermediateDirectory");
			s += "\"\r\n";
			m_outputFile.Write(s);
			s = "# PROP BASE Target_Dir \"\"\r\n";
			m_outputFile.Write(s);

			s = "# PROP Use_MFC " + szUseMFC + "\r\n";
			m_outputFile.Write(s);
			s = "# PROP Use_Debug_Libraries ";
			s += (szConfigName.FindNoCase(0,"debug")>-1) ? "1" : "0";
			s += "\r\n";
			m_outputFile.Write(s);
			s = "# PROP Output_Dir \"";
			s += pConfig->General.GetValue("OutputDirectory");
			s += "\"\r\n";
			m_outputFile.Write(s);
			s = "# PROP Intermediate_Dir \"";
			s += pConfig->General.GetValue("IntermediateDirectory");
			s += "\"\r\n";
			m_outputFile.Write(s);
			s = "# PROP Target_Dir \"\"\r\n";
			m_outputFile.Write(s);

				
			// build compiling symbols line
			//
			CString szCPPSymbols = pConfig->serializeCPPSymbols();

			// build Linker symbol line
			//
			CString szLinkerSymbols = pConfig->serializeLinkerSymbols();

			// build Librarian symbol line
			//
			CString szLibSymbols = pConfig->serializeLibrarianSymbols();

			// build ResourceCompiler symbol line
			//
			CString szResourceSymbols = pConfig->serializeResourceSymbols();

			// build BrowseInformation symbol line
			//
			CString szBscMakeSymbols = pConfig->serializeBscMakeSymbols();

			// build Midl symbol line
			//
			CString szMidlSymbols = pConfig->serializeMidlSymbols();

			// build PreBuild cmd line
			//
			ArrayCString arrPreBuildCommands;
			pConfig->serializePreBuildCommands(arrPreBuildCommands);

			// build PreLink cmd line
			//
			ArrayCString arrPreLinkCommands;
			pConfig->serializePreLinkCommands(arrPreLinkCommands);

			// build PostBuild cmd line
			//
			ArrayCString arrPostBuildCommands;
			pConfig->serializePostBuildCommands(arrPostBuildCommands);

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

			
			// compiler line (mandatory)
			s = "# ADD BASE CPP " + szCPPSymbols + "\r\n";
			m_outputFile.Write(s);
			s = "# ADD CPP " + szCPPSymbols + "\r\n";
			m_outputFile.Write(s);

			// midl line (optional)
			if (!szMidlSymbols.IsEmpty())
			{
				s = "# ADD BASE MTL " + szMidlSymbols + "\r\n";
				m_outputFile.Write(s);
				s = "# ADD MTL " + szMidlSymbols + "\r\n";
				m_outputFile.Write(s);
			}

			// resource compiler (optional)
			if (!szResourceSymbols.IsEmpty())
			{
				s = "# ADD BASE RSC " + szResourceSymbols + "\r\n";
				m_outputFile.Write(s);
				s = "# ADD RSC " + szResourceSymbols + "\r\n";
				m_outputFile.Write(s);
			}

			// browseinformation (mandatory)
			s = "BSC32=bscmake.exe\r\n";
			s += "# ADD BASE BSC32 " + szBscMakeSymbols + "\r\n";
			m_outputFile.Write(s);
			s = "# ADD BSC32 " + szBscMakeSymbols + "\r\n";
			m_outputFile.Write(s);

			// linker line (mandatory)
			BOOL bIsStaticLibrary = m_szTargetType.Compare("4");
			CString szLinkTool = bIsStaticLibrary ? "LIB32" : "LINK32";
			s = szLinkTool + "=link.exe";
			if (bIsStaticLibrary)
				s += " -lib";
			s += "\r\n";
			s += "# ADD BASE " + szLinkTool + " ";
			s += bIsStaticLibrary ? szLibSymbols : szLinkerSymbols;
			s += "\r\n";
			m_outputFile.Write(s);
			s = "# ADD " + szLinkTool + " ";
			s += bIsStaticLibrary ? szLibSymbols : szLinkerSymbols;
			s += "\r\n";
			m_outputFile.Write(s);

			// custom build (optional)
			if ( arrCustomBuildCommands.GetSize()>0 )
			{
				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);
				long j;
				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);
			}

			// prelink or postbuild tool (both are optional)
			BOOL bHasPrelink = ( arrPreLinkCommands.GetSize()>0 );
			BOOL bHasPostBuild = ( arrPostBuildCommands.GetSize()>0 );
			if (bHasPrelink || bHasPostBuild)
			{
				s = "# Begin Special Build Tool\r\n";
				m_outputFile.Write(s);
				s = "SOURCE=\"$(InputPath)\"\r\n"; // don't know why VC++ 6.0 needs this
				m_outputFile.Write(s);

				if (bHasPrelink)
				{
					if (arrPreLinkCommands.GetAt(0).GetLength()>0)
					{
						s = "PreLink_Desc=" + arrPreLinkCommands.GetAt(0) + "\r\n";
						m_outputFile.Write(s);
					}
					s = "PreLink_Cmds=" + arrPreLinkCommands.GetAt(1) + "\r\n";
					m_outputFile.Write(s);
				} // end if (bHasPrelink)

				if (bHasPostBuild)
				{
					if (arrPostBuildCommands.GetAt(0).GetLength()>0)
					{
						s = "PostBuild_Desc=" + arrPostBuildCommands.GetAt(0) + "\r\n";
						m_outputFile.Write(s);
					}
					s = "PostBuild_Cmds=" + arrPostBuildCommands.GetAt(1) + "\r\n";
					m_outputFile.Write(s);
				} // end if (bHasPostBuild)

				s = "# End Special Build Tool\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::getSourceControlInfo(CString &szSccName, CString &szSccPath)
{
	szSccName = m_szSccProjectName;
	szSccPath = m_szSccLocalPath;
}





void vcprojprocess::writeDspMakefile(long i)
{
	long nConfigNb = m_arrConfigurationNames.GetSize();
	if (nConfigNb==0 || i<0 || i>=nConfigNb) return;

	vcprojconfiguration *pConfig = m_arrConfigs.GetAt(i);
	if (!pConfig) return;

	CString szConfigName = pConfig->getConfigName();

	CString s = "# PROP BASE Use_MFC\r\n";
	m_outputFile.Write(s);
	s = "# PROP BASE Use_Debug_Libraries ";
	s += (szConfigName.FindNoCase(0,"debug")>-1) ? "1" : "0";
	s += "\r\n";
	m_outputFile.Write(s);
	s = "# PROP BASE Output_Dir \"";
	s += pConfig->General.GetValue("OutputDirectory");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP BASE Intermediate_Dir \"";
	s += pConfig->General.GetValue("IntermediateDirectory");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP BASE Cmd_Line \"";
	s += pConfig->VCNMakeTool.GetValue("BuildCommandLine");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP BASE Rebuild_Opt \"";
	s += pConfig->VCNMakeTool.GetValue("ReBuildCommandLine");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP BASE Target_File \"";
	s += pConfig->VCNMakeTool.GetValue("Output");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP BASE Bsc_Name \"" + m_szProjname + ".bsc" + "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP BASE Target_Dir \"\"\r\n";
	m_outputFile.Write(s);

	s = "# PROP Use_MFC\r\n";
	m_outputFile.Write(s);
	s = "# PROP Use_Debug_Libraries ";
	s += (szConfigName.FindNoCase(0,"debug")>-1) ? "1" : "0";
	s += "\r\n";
	m_outputFile.Write(s);
	s = "# PROP Output_Dir \"";
	s += pConfig->General.GetValue("OutputDirectory");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP Intermediate_Dir \"";
	s += pConfig->General.GetValue("IntermediateDirectory");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP Cmd_Line \"";
	s += pConfig->VCNMakeTool.GetValue("BuildCommandLine");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP Rebuild_Opt \"";
	s += pConfig->VCNMakeTool.GetValue("ReBuildCommandLine");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP Target_File \"";
	s += pConfig->VCNMakeTool.GetValue("Output");
	s += "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP Bsc_Name \"" + m_szProjname + ".bsc" + "\"\r\n";
	m_outputFile.Write(s);
	s = "# PROP Target_Dir \"\"\r\n\r\n";
	m_outputFile.Write(s);
}

void vcprojprocess::writeDspFiles(IXMLDOMDocument *pDoc)
{
	if (!pDoc) return;

	long nConfigNb = m_arrConfigurationNames.GetSize();
	if (nConfigNb==0) return;


	CString s = "# Begin Target\r\n\r\n";
	m_outputFile.Write(s);

	for (long i=0; i<nConfigNb; i++)
	{
		s = "# Name \"" + TranslateConfigurationName( m_arrConfigurationNames.GetAt(i) ) + "\"\r\n";
		m_outputFile.Write(s);
	}


	CComPtr<IXMLDOMNodeList> pFilesNodelist;
	pDoc->getElementsByTagName( _bstr_t(XMLNODE_FILES), &pFilesNodelist);
    if (pFilesNodelist)
	{

		long nb = 0;
		pFilesNodelist->get_length(&nb);

		if (nb!=1) return;
		
		CComPtr<IXMLDOMNode> pNode;
		pFilesNodelist->get_item(0,&pNode);
		if (pNode)
		{
			CComQIPtr<IXMLDOMElement> pFiles( pNode );
			if (pFiles)
			{
				writeDspGroup(pFiles); // recurse call
			}
		}

	} // end if (pFilesList)


}

void vcprojprocess::writeDspGroup(IXMLDOMElement *pGroupFilter)
{
	CString s;

	if (!pGroupFilter) return;

	// now go through all children

	CComPtr<IXMLDOMNodeList> pChildren;
	pGroupFilter->get_childNodes( &pChildren);	
	if (!pChildren) return;

	long nb = 0;
	pChildren->get_length(&nb);
	
	for (long i=0; i<nb; i++)
	{

		CComPtr<IXMLDOMNode> pNode;
		pChildren->get_item(i,&pNode);
		if (pNode)
		{
			CComQIPtr<IXMLDOMElement> pElem( pNode );

			CString szNodename;
			getNodeName(pElem, szNodename);

			// is it a file or a filter ?
			//
			if ( szNodename.CompareNoCase(XMLNODE_FILE) )
			{
				CString szFilename;

⌨️ 快捷键说明

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