您的位置:首页 > 其它

Change the content of the file

2012-08-17 16:20 477 查看
LOG_INFO(L"更改RC版本信息...");
	CopyRCtoTxt();
	CoutAndReturnRC(0);
	int j=i;
	for(int k=0;k<j;k++)
	{i=0;
	string p=CoutAndReturnRC(k);
	LPWSTR sourcefile = new WCHAR[MAX_PATH];
	LPWSTR objfile = new WCHAR[MAX_PATH];
	ZeroMemory(sourcefile,MAX_PATH);      /////////// 对申请空间清除
	ZeroMemory(objfile,MAX_PATH);
	_TCHAR*arg1=L"Info.txt";
    // _TCHAR* arg2=p;
	wcscat( sourcefile, arg1);
	//wcscat( objfile, arg2);
	CString ABC;
	ABC+=p.c_str();
	CString wsSourceNum;
	CString wsSourceName;
    CString wsSourcecompanyname;
	CString wsStr;
	CStdioFileEx fileSource,fileDes,fileTemp;
    
	if (!fileSource.Open(sourcefile,CFile::modeRead))
	{
		printf("%s","Open SourceFile is  failed !");
		LOG_ERROR(L"Open SourceFile is  failed !");
		return 1;
	}
    //LOG_INFO(L"开始读取资源信息");
	
	while(fileSource.ReadString(wsStr))
	{
		
		wsSourcecompanyname=wsStr;
        LOG_INFO(L"成功读取资源信息为:wsSourcecompanyname=%s",wsSourcecompanyname);
		break;
	}
	string tp= RenewInfo();
	wsSourceNum =  tp.c_str();
	wsSourceName =  tp.c_str();
		
	fileSource.Flush();
	fileSource.Close();
	if (!fileDes.Open(ABC,CFile::modeReadWrite|CFile::typeText))
	{
		printf("%s","Open DesFile is error!");
		LOG_ERROR(L"Open DesFile is  failed !");
		return 1;
	}
	//CString DesNum;
	CString DesStr;
	CString DesFILEVERSION;
	CString DesFileVersion;
	CString DesPathName;
	CString DesPRODUCTVERSION;
	CString DesProductName;
	CString DesLegalCopyright;
	CString DesFileDescription;
	CString DesProductVersion;
	CString DesComlist0,DesComlist1,DesComlist2,DesComlist3;
	DesPathName = ABC;
	DesPathName+=".rc";
	if (!fileTemp.Open(DesPathName,CFile::modeCreate|CFile::modeWrite))
	{
		printf("%s","Creat New DesFile is Error");
		LOG_ERROR(L"Creat New DesFile is  failed !");
		return 1;
	}
	while (fileDes.ReadString(DesStr))
	{
		DesFILEVERSION = DesStr.Mid(0,13);//FILEVERSION,文件版本
		DesFileVersion = DesStr.Mid(0,33);//VALUE "FileVersion",文件版本
		DesPRODUCTVERSION = DesStr.Mid(0,16);//PRODUCTVERSION ,产品版本
        DesProductVersion = DesStr.Mid(0,36);//VALUE "ProductVersion",  产品版本
		DesProductName = DesStr.Mid(0,33);//VALUE "ProductName", 产品名称,<产品名>
		DesLegalCopyright = DesStr.Mid(0,36);//VALUE "LegalCopyright",  版权,<公司名称>
		//DesFileDescription= DesStr.Mid(0,37);//VALUE "FileDescription", 文件描述
		
		DesComlist0 = "            ";
		DesComlist0+="VALUE ";
		DesComlist0+='"';
		DesComlist0+="ProductName";
		DesComlist0+='"';
		DesComlist0+=", ";
		
		DesComlist1 = "            ";
		DesComlist1+="VALUE ";
		DesComlist1+='"';
		DesComlist1+="ProductVersion";
		DesComlist1+='"';
		DesComlist1+=", ";
		
		DesComlist2 = "            ";
		DesComlist2+="VALUE ";
		DesComlist2+='"';
		DesComlist2+="FileVersion";
		DesComlist2+='"';
		DesComlist2+=", ";
		
		DesComlist3 = "            ";
		DesComlist3+="VALUE ";
		DesComlist3+='"';
		DesComlist3+="LegalCopyright";
		DesComlist3+='"';
		DesComlist3+=", ";
		
		if (DesFILEVERSION==L" FILEVERSION " )            
		{

			DesFILEVERSION+=wsSourceNum;
			DesFILEVERSION+="\r\n";
			fileTemp.WriteString(DesFILEVERSION);
			LOG_INFO(L"查找到替换字符串:FILEVERSION,替换成功");

		}else if (DesPRODUCTVERSION==" PRODUCTVERSION ")   
		{

			DesPRODUCTVERSION+=wsSourceName;
			DesPRODUCTVERSION+="\r\n";
			fileTemp.WriteString(DesPRODUCTVERSION);
			LOG_INFO(L"查找到替换字符串:PRODUCTVERSION,替换成功");
		}else if (DesProductName==DesComlist0)            
		{
			DesProductName+='"';
			DesProductName+="<";
			DesProductName+=wsSourcecompanyname;
			DesProductName+=">";
			DesProductName+='"';
			DesProductName+="\r\n";
			fileTemp.WriteString(DesProductName);
			LOG_INFO(L"查找到替换字符串:ProductName,产品名称替换成功");
		}else if (DesProductVersion==DesComlist1)         
		{
			DesProductVersion+='"';
			DesProductVersion+=wsSourceName;
			DesProductVersion+='"';
			DesProductVersion+="\r\n";
			fileTemp.WriteString(DesProductVersion);
			LOG_INFO(L"查找到替换字符串:DesProductVersion,产品版本替换成功");
		}else if (DesFileVersion==DesComlist2)          
		{
			DesFileVersion+='"';
			DesFileVersion+=wsSourceNum;
			DesFileVersion+='"';
			DesFileVersion+="\r\n";
			fileTemp.WriteString(DesFileVersion);
			LOG_INFO(L"查找到替换字符串:FileVersion,替换成功");
		}else if (DesLegalCopyright==DesComlist3)         
		{
			DesLegalCopyright+='"';
			DesLegalCopyright+="(C) <";
			DesLegalCopyright+=wsSourcecompanyname;
			DesLegalCopyright+=">。保留所有权利。";
			DesLegalCopyright+='"';
			DesLegalCopyright+="\r\n";
			fileTemp.WriteString(DesLegalCopyright);
			LOG_INFO(L"查找到替换字符串:LegalCopyright,版权替换成功");
		}else
		{
			DesStr+="\r\n";
			fileTemp.WriteString(DesStr);
			//LOG_INFO(L"没有查找到需要替换字符串");
		}
	}
	fileDes.Flush();
	fileDes.Close();
	DeleteFile(ABC);
	fileTemp.Flush();
	fileTemp.Close();
	CFile::Rename(DesPathName,ABC);}
    wcout<<"版本RC修改成功..."<<endl;
	LOG_INFO(L"***********更改RC版本信息成功*****************");
	//return 1;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐