本文主要是介绍程序修改文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
第一步:头文件,包含相应的类、函数、变量
///对于文件内容的修改,这种方法虽然效率不高(对超多文件同时修改)但是这种方法比较简单
///也比较容易后期修改,因此备份一份,以供下次遇到相同问题时修改一下即可使用 zp 20170313 15:44:40#pragma once
#include <vector>
#include <map>
#include <string>
#include <fstream>
#include <algorithm>
#include "afxcmn.h"
using namespace std;#define WM_FUNCTION_MSG (WM_USER + 0x468)// CSrcToolDlg dialog
class CSrcToolDlg : public CDialog
{
// Construction
public:int m_iTotalFiles;CProgressCtrl m_progress;void ResetAllData();void AppendMsgShow(CString strMsg, UINT uIdCtrl);CSrcToolDlg(CWnd* pParent = NULL); // standard constructor// Dialog Dataenum { IDD = IDD_SRCTOOL_DIALOG };protected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support// Implementation
protected:HICON m_hIcon;// Generated message map functionsvirtual BOOL OnInitDialog();virtual BOOL PreTranslateMessage(MSG* pMsg);afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();DECLARE_MESSAGE_MAP()
public:afx_msg void OnLButtonDown(UINT nFlags, CPoint point);afx_msg void OnBnClickedButtonFuncStart();afx_msg void OnBnClickedButtonSearch();afx_msg LRESULT OnFunctionMsg(WPARAM wParam,LPARAM lParam);
};
在这里我是直接把我工程里面的内容复制过来,所以有好多ID和ID对应的事件函数,如果网友在采用此代码时,只需要把对应的ID修改和自己项目中的ID一样即可。后续我会添加一些注释,使代码更容易看懂。
- 本程序在修改文件采用的方式是,先定义好需要替换的内容,这里是以map
// SrcToolDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SrcTool.h"
#include "SrcToolDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endifCString g_strMsg = _T("");#ifdef ZP_CHANGE
map<string, string> m_mapStringChange; ///add zp 20170313 一些字符串修改
#endifmap<string, string> m_mapClassChange;//类名
map<string, string> m_mapFuncChange;//函数接口名
map<string, string> m_mapFileChange;//文件名
map<string, string> m_mapOtherChange;//其他变更
vector<string> m_vctKeyWords;//关键字
vector<string> m_vctDeleted;//已不再使用的文件和类名vector<CString> m_vctKeyWordsFound;// CSrcToolDlg dialogCSrcToolDlg::CSrcToolDlg(CWnd* pParent /*=NULL*/): CDialog(CSrcToolDlg::IDD, pParent)
{m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CSrcToolDlg::DoDataExchange(CDataExchange* pDX)
{CDialog::DoDataExchange(pDX);DDX_Control(pDX, IDC_PROGRESS_FUNC, m_progress);
}BEGIN_MESSAGE_MAP(CSrcToolDlg, CDialog)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()//}}AFX_MSG_MAPON_WM_LBUTTONDOWN()ON_BN_CLICKED(IDC_BUTTON_FUNC_START, &CSrcToolDlg::OnBnClickedButtonFuncStart)ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CSrcToolDlg::OnBnClickedButtonSearch)ON_MESSAGE(WM_FUNCTION_MSG,OnFunctionMsg)
END_MESSAGE_MAP()// CSrcToolDlg message handlers
CString string2CString(string strSrc)
{if(strSrc.length() <= 0)return _T("");CString strTarge = _T("");wchar_t* buff;const char* ac = strSrc.c_str();if(ac == NULL || strlen(ac) <= 0)buff = NULL;int n = MultiByteToWideChar(0,0,ac,-1,NULL,0);buff = new wchar_t[n];wmemset(buff,0,n);MultiByteToWideChar(0,0,ac,-1,buff,n);strTarge = buff;if(buff){delete[] buff;buff = NULL;}return strTarge;
}string CString2string(CString strSrc)
{string strTarge = "";int nLength = strSrc.GetLength();int nBytes = WideCharToMultiByte(0,0,strSrc,nLength,NULL,0,NULL,NULL);char* VoicePath = new char[ nBytes + 1];memset(VoicePath,0,nLength + 1);WideCharToMultiByte(0, 0, strSrc, nLength, VoicePath, nBytes, NULL, NULL); VoicePath[nBytes] = 0;strTarge = VoicePath;if(VoicePath){delete[] VoicePath;VoicePath = NULL;}return strTarge;
}bool FileIsDeleted(string strFile)
{for (unsigned int i = 0 ; i < m_vctDeleted.size() ; i ++){if(m_vctDeleted[i] == strFile)return true;}return false;
}string ChangeFunction(string strSrc, string strFlag)
{int iPos = 0;while(1){iPos = strSrc.find(strFlag, iPos);if(iPos == -1)break;int iPosStart = iPos + strFlag.length();while(1){if((iPosStart < strSrc.length()) && ((strSrc[iPosStart] == 0x20) || (strSrc[iPosStart] == '\t')))iPosStart ++;elsebreak;}int iPosEnd = strSrc.find("(",iPosStart);if(iPosEnd != -1){while(1){if((iPosEnd > iPosStart) && ((strSrc[iPosEnd - 1] == 0x20) || (strSrc[iPosEnd - 1] == '\t')))iPosEnd --;elsebreak;}string strCurFunc = strSrc.substr(iPosStart, iPosEnd - iPosStart);string strNew = m_mapFuncChange[strCurFunc];if(strNew.length())strSrc.replace(iPosStart, strCurFunc.length(), strNew);iPos = iPosStart;}else{if((strSrc.find("using") != -1) && (strFlag == "::"))//using CNetLayerBase::Init;{iPosEnd = strSrc.find(";",iPosStart);if(iPosEnd != -1){while(1){if((iPosEnd > iPosStart) && ((strSrc[iPosEnd - 1] == 0x20) || (strSrc[iPosEnd - 1] == '\t')))iPosEnd --;elsebreak;}string strCurFunc = strSrc.substr(iPosStart, iPosEnd - iPosStart);string strNew = m_mapFuncChange[strCurFunc];if(strNew.length())strSrc.replace(iPosStart, strCurFunc.length(), strNew);iPos = iPosStart;}elsebreak;}elsebreak;}}return strSrc;
}string ChangeFunction_CodeFile(string strSrc)
{int iPos = 0;while(1){iPos = strSrc.find("(", iPos);if(iPos == -1)break;int iPosEnd = iPos;while(1){if((iPosEnd > 0) && ((strSrc[iPosEnd - 1] == 0x20) || (strSrc[iPosEnd - 1] == '\t')))iPosEnd --;elsebreak;}if(iPosEnd < 1){iPos ++;continue;}int iPosStart = iPosEnd;while(1){if((iPosStart > 0) && ((strSrc[iPosStart - 1] == 0x20) || (strSrc[iPosStart - 1] == '\t') || (strSrc[iPosStart - 1] == '(') || (strSrc[iPosStart - 1] == '=') || (strSrc[iPosStart - 1] == ',')))break;else if(iPosStart == 0)break;elseiPosStart --;}string strCurFunc = strSrc.substr(iPosStart, iPosEnd - iPosStart);string strNew = m_mapFuncChange[strCurFunc];if(strNew.length())strSrc.replace(iPosStart, strCurFunc.length(), strNew);iPos ++;}return strSrc;
}//((ucInitSize1=clsEcu.p_srtCommand.bgInitSysCmd.GetSize()) == (ucInitSize2=clsEcuCurr->p_srtCommand.bgInitSysCmd.GetSize())) &&
//CProFile clsProFile, clsProFileMask;
//strGetData = m_clsDataSheet.GetText(binIndex);
string ChangeFunctions(string strSrc, bool bCodeFile)
{//////////////////////////////////////////////////////////////////////////先修改函数接口int iPosDot = strSrc.find("."), iPosArrow = strSrc.find("->"), iPosAreaSymbol = strSrc.find("::");if(iPosDot != -1)strSrc = ChangeFunction(strSrc, ".");if(iPosArrow != -1)strSrc = ChangeFunction(strSrc, "->");if(iPosAreaSymbol != -1)strSrc = ChangeFunction(strSrc, "::");if(bCodeFile)strSrc = ChangeFunction_CodeFile(strSrc);//////////////////////////////////////////////////////////////////////////再修改类名,类名要反复修改,一行中可能出现多次,比如 EcuInterface.SetCommPort(CEcuInterface::OBD2_PIN7,MAKE_UINT16(CEcuInterface::OBD2_PIN15,CEcuInterface::OBD2_PIN7));for(map<string, string>::iterator itClass = m_mapClassChange.begin() ; itClass != m_mapClassChange.end() ; itClass ++){string strOld = itClass->first, strNew = itClass->second;int iFindPos = 0;while(1){int iFind = strSrc.find(strOld, iFindPos);if(iFind != -1){if((strNew.length()) && ((strSrc[iFind + strOld.length()] == 0x20) || (strSrc[iFind + strOld.length()] == '\t') || (strSrc[iFind + strOld.length()] == ':') || (strSrc[iFind + strOld.length()] == '(') || (strSrc[iFind + strOld.length()] == '*')))//空格,Tab,::,构造函数,定义指针对象strSrc.replace(iFind,strOld.length(),strNew);elseiFindPos = iFind + 1;}elsebreak;}}//////////////////////////////////////////////////////////////////////////再修改其他变更,要反复修改,一行中可能出现多次,比如 CSysInterface::CSysKeyboard::KEY_F1 要替换成 KEY_PRESS_F1for(map<string, string>::iterator itOthers = m_mapOtherChange.begin() ; itOthers != m_mapOtherChange.end() ; itOthers ++){string strOld = itOthers->first, strNew = itOthers->second;while(1){int iFind = strSrc.find(strOld);if(iFind != -1){if(strNew.length())strSrc.replace(iFind,strOld.length(),strNew);}elsebreak;}}return strSrc;
}///用来搜索文件,这里会搜索所有文件,然后保存你想要的文件类型,这里会保存.EWP .BAT .H .CPP ///.VCPROJ 等文件,如果你有新的文件类型需要保存,则需要手动添加返回vector和判断命令
///比如要保存.txt文件,vector<CString> &vctTxtFile
///添加判断 if(strExt == _T(".TXT")) vctTxtFile.push_back(strFile);
void SearchDir(CString szFilePath, vector<CString> &vctSourceFile, vector<CString> &vctProjectFile, vector<CString> &vctIarProjectFile, vector<CString> &vctBatFile)
{CFileFind finder;BOOL bWorking = FALSE;if(szFilePath.GetLength()){szFilePath.TrimRight('\\');bWorking = finder.FindFile(szFilePath+_T("\\*.*"));}while(bWorking){bWorking = finder.FindNextFile();if (finder.IsDots()){if((finder.GetFileName() == _T("..")) && (bWorking == FALSE))break;continue;}if (finder.IsDirectory()){CString str = finder.GetFilePath();SearchDir(str,vctSourceFile,vctProjectFile,vctIarProjectFile, vctBatFile);}else{CString strFile = finder.GetFilePath(), strExt = finder.GetFileName();strExt = strExt.Right(strExt.GetLength() - strExt.ReverseFind('.'));strExt.MakeUpper();
#ifdef ZP_CHANGEif( _T(".EWP") == strExt )///需要保存的文件类型vctIarProjectFile.push_back(strFile);else if ( _T(".BAT") == strExt )vctBatFile.push_back(strFile);
#elseif((strExt == _T(".H")) || (strExt == _T(".CPP")))vctSourceFile.push_back(strFile);else if(strExt == _T(".VCPROJ"))vctProjectFile.push_back(strFile);else if((strExt == _T(".DEP")) || (strExt == _T(".EWP")))vctIarProjectFile.push_back(strFile);
#endif}}
}UINT FunctionProc(LPVOID pParam)
{CSrcToolDlg* pDlg = (CSrcToolDlg*)pParam;TCHAR chCurPath[260] = {0};::GetModuleFileName(NULL, chCurPath, MAX_PATH);CString strSrcPath = chCurPath;strSrcPath = strSrcPath.Left(strSrcPath.ReverseFind('\\')+1);
#ifdef ZP_CHANGE
#elsestrSrcPath += _T("SRC");if(GetFileAttributes(strSrcPath) == -1){AfxMessageBox(_T("SRC目录不存在!"),MB_ICONERROR);pDlg->PostMessage(WM_FUNCTION_MSG,0,0);return 0;}
#endifvector<CString> vctSourceFile, vctProjectFile, vctIarProjectFile, vctBatFile;SearchDir(strSrcPath,vctSourceFile,vctProjectFile,vctIarProjectFile, vctBatFile);int iProgressMax = vctSourceFile.size() + vctProjectFile.size() + vctIarProjectFile.size() + vctBatFile.size();int iProcessCnt = 0;pDlg->PostMessage(WM_FUNCTION_MSG, iProgressMax, 2);///下面就是对文件进行真正的修改,这里也是最耗时的地方,在这里我使用的单线程,有兴趣的朋友可以///尝试修改为多线程//////////////////////////////////////////////////////////////////////////Iar Project filesfor (unsigned int iIar = 0 ; iIar < vctIarProjectFile.size() ; iIar ++){iProcessCnt ++;CString strFileName = vctIarProjectFile[iIar], strFileNameTmp = strFileName + _T(".Tmp"), strFileTitle = strFileName.Right(strFileName.GetLength() - strFileName.ReverseFind('\\') - 1);g_strMsg = strFileTitle;pDlg->PostMessage(WM_FUNCTION_MSG,iProcessCnt,3);ifstream fin;ofstream fout;fin.open(strFileName);if(!fin.is_open()){g_strMsg = _T("文件打开失败 :") + strFileName;pDlg->PostMessage(WM_FUNCTION_MSG,1,1);continue;}fout.open(strFileNameTmp);if(!fout.is_open()){g_strMsg = _T("文件写入失败 :") + strFileName;pDlg->PostMessage(WM_FUNCTION_MSG,1,1);continue;}while(!fin.eof()){string strTemp = "";getline(fin,strTemp,'\n');if(strTemp.length() < 2){fout<<strTemp<<endl;continue;}
#ifdef ZP_CHANGEint nReverse = strTemp.find("NT600_Elite");if( nReverse != -1 )//改工程配置{string strPre = strTemp.substr(0, nReverse);string strCurFile = "NT600_Elite";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp=strPre+strFileChange+strPost;}nReverse = strTemp.find("Std_NT500");if (nReverse != -1){string strPre = strTemp.substr(0, nReverse);string strCurFile = "Std_NT500";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp = strPre+strFileChange+strPost;}nReverse = strTemp.find("Std500.a");if (nReverse != -1){string strPre = strTemp.substr(0, nReverse);string strCurFile = "Std500.a";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp = strPre+strFileChange+strPost;}nReverse = strTemp.find("ecu.bin");if (nReverse != -1){string strPre = strTemp.substr(0, nReverse);string strCurFile = "ecu.bin";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp = strPre+strFileChange+strPost;}nReverse = strTemp.find("car.bmp");if( nReverse != -1 )//改工程配置{string strPre = strTemp.substr(0, nReverse);string strCurFile = "car.bmp";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp=strPre+strFileChange+strPost;}fout<<strTemp<<endl;
#elseint nFileFind = strTemp.find("<file>$PROJ_DIR$");int nNameFind = strTemp.find("<name>$PROJ_DIR$");int nStateFind = strTemp.find("<state>$PROJ_DIR$");if((nFileFind != -1) || (nNameFind != -1) || (nStateFind != -1) )//改工程配置{int iReverse = strTemp.find_last_of('\\');if(iReverse != -1){string strPre = strTemp.substr(0, iReverse + 1);string strCurFile = strTemp.substr(iReverse + 1, strTemp.length() - iReverse - 8);string strPost = strTemp.substr(iReverse + 1 + strCurFile.length());transform(strCurFile.begin(), strCurFile.end(), strCurFile.begin(), ::tolower);{string strFileChange = m_mapFileChange[strCurFile];if(strFileChange.length())fout<<strPre<<strFileChange<<strPost<<endl;elsefout<<strTemp<<endl;}}}elsefout<<strTemp<<endl;
#endif }fin.close();fout.close();CFile::Remove(strFileName);CFile::Rename(strFileNameTmp, strFileName);}
#ifdef ZP_CHANGE ///add zp 20170313 14:32:10for (unsigned int iBat = 0 ; iBat < vctBatFile.size() ; iBat ++){iProcessCnt ++;CString strFileName = vctBatFile[iBat], strFileNameTmp = strFileName + _T(".Tmp"), strFileTitle = strFileName.Right(strFileName.GetLength() - strFileName.ReverseFind('\\') - 1);g_strMsg = strFileTitle;pDlg->PostMessage(WM_FUNCTION_MSG,iProcessCnt,3);ifstream fin;ofstream fout;fin.open(strFileName);if(!fin.is_open()){g_strMsg = _T("文件打开失败 :") + strFileName;pDlg->PostMessage(WM_FUNCTION_MSG,1,1);continue;}fout.open(strFileNameTmp);if(!fout.is_open()){g_strMsg = _T("文件写入失败 :") + strFileName;pDlg->PostMessage(WM_FUNCTION_MSG,1,1);continue;}while(!fin.eof()){string strTemp = "";getline(fin,strTemp,'\n');if(strTemp.length() < 2){fout<<strTemp<<endl;continue;}int nReverse = strTemp.find("NT600_Elite");if( nReverse != -1 )//改工程配置{string strPre = strTemp.substr(0, nReverse);string strCurFile = "NT600_Elite";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp=strPre+strFileChange+strPost;}nReverse = strTemp.find("Std_NT500");if (nReverse != -1){string strPre = strTemp.substr(0, nReverse);string strCurFile = "Std_NT500";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp = strPre+strFileChange+strPost;}nReverse = strTemp.find("Std500.a");if (nReverse != -1){string strPre = strTemp.substr(0, nReverse);string strCurFile = "Std500.a";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp = strPre+strFileChange+strPost;}nReverse = strTemp.find("ecu.bin");if (nReverse != -1){string strPre = strTemp.substr(0, nReverse);string strCurFile = "ecu.bin";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp = strPre+strFileChange+strPost;}nReverse = strTemp.find("car.bmp");if( nReverse != -1 )//改工程配置{string strPre = strTemp.substr(0, nReverse);string strCurFile = "car.bmp";string strPost = strTemp.substr(nReverse + strCurFile.length());string strFileChange = m_mapStringChange[strCurFile];if(strFileChange.length())strTemp=strPre+strFileChange+strPost;} fout<<strTemp<<endl; }fin.close();fout.close();CFile::Remove(strFileName);CFile::Rename(strFileNameTmp, strFileName);}
#endif //////////////////////////////////////////////////////////////////////////.vcprojfor (unsigned int iProj = 0 ; iProj < vctProjectFile.size() ; iProj ++){iProcessCnt ++;CString strFileName = vctProjectFile[iProj], strFileNameTmp = strFileName + _T(".Tmp"), strFileTitle = strFileName.Right(strFileName.GetLength() - strFileName.ReverseFind('\\') - 1);g_strMsg = strFileTitle;pDlg->PostMessage(WM_FUNCTION_MSG,iProcessCnt,3);ifstream fin;ofstream fout;fin.open(strFileName);if(!fin.is_open()){g_strMsg = _T("文件打开失败 :") + strFileName;pDlg->PostMessage(WM_FUNCTION_MSG,1,1);continue;}fout.open(strFileNameTmp);if(!fout.is_open()){g_strMsg = _T("文件写入失败 :") + strFileName;pDlg->PostMessage(WM_FUNCTION_MSG,1,1);continue;}int iLineNum = 0, iSkipFlag = 0;bool bSkip = false;while(!fin.eof()){iLineNum ++;string strTemp = "";getline(fin,strTemp,'\n');if(iSkipFlag == 4){bSkip = false;iSkipFlag = 0;}if(bSkip){iSkipFlag ++;continue;}if(strTemp.length() < 2){fout<<strTemp<<endl;continue;}
/* if(strTemp.substr(0,2) == "//"){fout<<strTemp<<endl;continue;}*/int iRelativePath = strTemp.find("RelativePath");if(iRelativePath == -1)//查关键字{fout<<strTemp<<endl;if(strTemp.find("PreprocessorDefinitions") != -1){transform(strTemp.begin(), strTemp.end(), strTemp.begin(), ::tolower);for (unsigned int iKw = 0 ; iKw < m_vctKeyWords.size() ; iKw ++){if(strTemp.find(m_vctKeyWords[iKw]) != -1)m_vctKeyWordsFound.push_back(_T("工程属性中检测到含有宏定义:") + string2CString(m_vctKeyWords[iKw]));}}}else//改工程配置{int iReverse = strTemp.find_last_of('\\');if(iReverse != -1){string strPre = strTemp.substr(0, iReverse + 1);string strCurFile = strTemp.substr(iReverse + 1, strTemp.length() - iReverse - 2);transform(strCurFile.begin(), strCurFile.end(), strCurFile.begin(), ::tolower);if(FileIsDeleted(strCurFile))//此处处理有点取巧,因为已不再使用的文件在工程配置中刚好都不是最后一个,如果是最后一个则不好处理了{bSkip = true;iSkipFlag = 1;continue;}else{string strFileChange = m_mapFileChange[strCurFile];if(strFileChange.length()){
// if(strTemp.find("STD_NT800") != -1)//因某些车型下会有STD中的文件,比如Profile,故此去掉此判断,强制改名fout<<strPre<<strFileChange<<"\""<<endl;
// else
// fout<<strTemp<<endl;}elsefout<<strTemp<<endl;}}}}fin.close();fout.close();CFile::Remove(strFileName);CFile::Rename(strFileNameTmp, strFileName);}//////////////////////////////////////////////////////////////////////////.h .cppfor (unsigned int iSource = 0 ; iSource < vctSourceFile.size() ; iSource ++){iProcessCnt ++;CString strFileName = vctSourceFile[iSource], strFileNameTmp = strFileName + _T(".Tmp");CString strFileTitle = strFileName.Right(strFileName.GetLength() - strFileName.ReverseFind('\\') - 1), strExt = strFileTitle.Right(strFileTitle.GetLength() - strFileTitle.ReverseFind('.') - 1);g_strMsg = strFileTitle;pDlg->PostMessage(WM_FUNCTION_MSG,iProcessCnt,3);ifstream fin;ofstream fout;fin.open(strFileName);if(!fin.is_open()){g_strMsg = _T("文件打开失败 :") + strFileName;pDlg->PostMessage(WM_FUNCTION_MSG,1,1);continue;}fout.open(strFileNameTmp);if(!fout.is_open()){g_strMsg = _T("文件写入失败 :") + strFileName;pDlg->PostMessage(WM_FUNCTION_MSG,1,1);continue;}int iLineNum = 0;while(!fin.eof()){iLineNum ++;string strTemp = "", strNew = "";getline(fin,strTemp,'\n');if(strTemp.length() < 2){fout<<strTemp<<endl;continue;}
/* if(strTemp.substr(0,2) == "//"){fout<<strTemp<<endl;continue;}*/int iInclude = strTemp.find("#include");if(iInclude != -1)//include{int iLeft = strTemp.find("\"",iInclude);int iRight = strTemp.find("\"",iLeft + 1);string strPre = strTemp.substr(0,iLeft + 1), strIncludeFile = strTemp.substr(iLeft + 1, iRight - iLeft - 1);int iIncludeFileLen = strIncludeFile.length();while(1){if((strIncludeFile[iIncludeFileLen-1] == ' ') || (strIncludeFile[iIncludeFileLen-1] == '\t'))iIncludeFileLen --;elsebreak;}strIncludeFile = strIncludeFile.substr(0,iIncludeFileLen);transform(strIncludeFile.begin(), strIncludeFile.end(), strIncludeFile.begin(), ::tolower);if(FileIsDeleted(strIncludeFile)){iLineNum --;continue;}else{string strIncludeChange = m_mapFileChange[strIncludeFile];if(strIncludeChange.length()){fout<<strPre<<strIncludeChange<<"\""<<endl;strNew = strPre + strIncludeChange;}else{fout<<strTemp<<endl;strNew = strTemp;}}}else//functions{bool bCodeFile = false;strExt.MakeUpper();if((strExt == _T("H")) || (strExt == _T("CPP")))bCodeFile = true;strNew = ChangeFunctions(strTemp, bCodeFile);fout<<strNew<<endl;}transform(strNew.begin(), strNew.end(), strNew.begin(), ::tolower);for (unsigned int iKw = 0 ; iKw < m_vctKeyWords.size() ; iKw ++){if(strNew.find(m_vctKeyWords[iKw]) != -1){CString strLineNum = _T("");strLineNum.Format(_T(" %d : "), iLineNum);m_vctKeyWordsFound.push_back(strFileTitle + strLineNum + string2CString(m_vctKeyWords[iKw]));}}}fin.close();fout.close();CFile::Remove(strFileName);CFile::Rename(strFileNameTmp, strFileName);/////////////////////////////////////////////////修改文件名,兼容修改STD时使用strFileTitle.MakeLower();string stringOldFile = CString2string(strFileTitle);string stringNewFile = m_mapFileChange[stringOldFile];if(stringNewFile.length()){CString strNewFileTitle = string2CString(stringNewFile);CString strLeftFile = strFileName.Left(strFileName.GetLength() - strFileTitle.GetLength());CFile::Rename(strFileName,strLeftFile + strNewFileTitle);}}//////////////////////////////////////////////////////////////////////////结束pDlg->PostMessage(WM_FUNCTION_MSG,0,0);return 0;
}BOOL CSrcToolDlg::OnInitDialog()
{CDialog::OnInitDialog();// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);}}// Set the icon for this dialog. The framework does this automatically// when the application's main window is not a dialogSetIcon(m_hIcon, TRUE); // Set big iconSetIcon(m_hIcon, FALSE); // Set small icon// TODO: Add extra initialization hereSetWindowText(_T("SRC Tool V1.20_20160303_新增IAR工程的支持"));GetDlgItem(IDC_STATIC_GROUP_FUNC)->SetWindowText(_T("SRC 处理"));GetDlgItem(IDC_STATIC_FUNC_INFO)->SetWindowText(_T("使用说明:\n\n请先将此程序放到要处理的车型根目录中,和车型代码SRC文件夹平级即可。\n处理之前最好先把SRC备份,程序将自动修改代码中的函数接口、类名和工程配置,并查找预设的一些关键字"));GetDlgItem(IDC_BUTTON_FUNC_START)->SetWindowText(_T("开始处理"));GetDlgItem(IDC_STATIC_GROUP_SEARCH)->SetWindowText(_T("类名或函数名查询"));GetDlgItem(IDC_STATIC_SEARCH_INFO)->SetWindowText(_T("使用说明:\n\n此处输入原类名或者原函数接口名,可以查询修改后的结果,支持不完全查询,不分大小写"));GetDlgItem(IDC_BUTTON_SEARCH)->SetWindowText(_T("查询"));GetDlgItem(IDC_STATIC_SEARCH_REPORT)->SetWindowText(_T("查询结果:"));ResetAllData();return TRUE; // return TRUE unless you set the focus to a control
}void CSrcToolDlg::OnSysCommand(UINT nID, LPARAM lParam)
{if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID, lParam);}
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CSrcToolDlg::OnPaint()
{if (IsIconic()){CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);// Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icondc.DrawIcon(x, y, m_hIcon);}else{CDialog::OnPaint();}
}// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSrcToolDlg::OnQueryDragIcon()
{return static_cast<HCURSOR>(m_hIcon);
}
///键盘事件处理
BOOL CSrcToolDlg::PreTranslateMessage(MSG* pMsg)
{if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)return TRUE;if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)return TRUE;return CDialog::PreTranslateMessage(pMsg);
}void CSrcToolDlg::OnLButtonDown(UINT nFlags, CPoint point)
{// TODO: Add your message handler code here and/or call defaultSendMessage(WM_NCLBUTTONDOWN,HTCAPTION,0);CDialog::OnLButtonDown(nFlags, point);
}void CSrcToolDlg::ResetAllData()
{SetDlgItemText(IDC_STATIC_CURPOS,_T(""));m_iTotalFiles = 0;
#ifdef ZP_CHANGE ///add zp 20170313m_mapStringChange.clear();m_mapStringChange["NT600_Elite"] = "i400";m_mapStringChange["Std_NT500"] = "Std_i300";m_mapStringChange["Std500.a"] = "Stdi300.a";m_mapStringChange["ecu.bin"] = "comm.bin";m_mapStringChange["car.bmp"] = "vehicle.bmp";
#else m_mapClassChange.clear();m_mapFuncChange.clear();m_mapFileChange.clear();m_mapOtherChange.clear();m_vctKeyWords.clear();m_vctDeleted.clear();m_vctKeyWordsFound.clear();//////////////////////////////////////////////////////////////////////////要修改的接口类名对应关系添加到此m_mapClassChange["CUIBase"] = "CBaseCtrl";m_mapClassChange["CUIActTest"] = "CActTestCtrl";m_mapClassChange["CUIDataStreamBase"] = "CDataStreamBaseCtrl";m_mapClassChange["CUIDataStream"] = "CDataStreamCtrl";m_mapClassChange["CUIEcuInfo"] = "CEcuInfoCtrl";m_mapClassChange["CUIFreezeFrame"] = "CFreezeFrameCtrl";m_mapClassChange["CUIInput"] = "CInputCtrl";m_mapClassChange["CUIMenu"] = "CMenuCtrl";m_mapClassChange["CUIMessageBox"] = "CMessageBoxCtrl";m_mapClassChange["CUIMultiSelected"] = "CMultiSelectCtrl";m_mapClassChange["CUIPicture"] = "CPictureCtrl";m_mapClassChange["CUIPowerBalance"] = "CPowerBalanceCtrl";m_mapClassChange["CUIScanSelect"] = "CDtcScanCtrl";m_mapClassChange["CUITimeProgress"] = "CTimeProgressCtrl";m_mapClassChange["CUITroubleCode"] = "CTroubleCodeCtrl";m_mapClassChange["CDataSheet"] = "CTextLibrary";m_mapClassChange["CProFile"] = "CFileManager";m_mapClassChange["CEcuInterface"] = "CVehicleComm";m_mapClassChange["CViewUIActTest"] = "CActTestCtrlView";m_mapClassChange["CViewUIDataStream"] = "CDataStreamCtrlView";m_mapClassChange["CViewUIEcuInfo"] = "CEcuInfoCtrlView";m_mapClassChange["CViewUIFreezeFrame"] = "CFreezeFrameCtrlView";m_mapClassChange["CViewUIInput"] = "CInputCtrlView";m_mapClassChange["CViewUIMenu"] = "CMenuCtrlView";m_mapClassChange["CViewUIMenuPath"] = "CMenuPathCtrlView";m_mapClassChange["CViewUIMessageBox"] = "CMessageBoxCtrlView";m_mapClassChange["CViewUIMultiSelected"] = "CMultiSelectCtrlView";m_mapClassChange["CViewUIPicture"] = "CPictureCtrlView";m_mapClassChange["CViewUIPowerBalance"] = "CPowerBalanceCtrlView";m_mapClassChange["CViewUIScanSelect"] = "CDtcScanCtrlView";m_mapClassChange["CViewUITimeProgress"] = "CTimeProgressCtrlView";m_mapClassChange["CViewUITroubleCode"] = "CTroubleCodeCtrlView";//////////////////////////////////////////////////////////////////////////要修改的接口函数对应关系添加到此m_mapFuncChange["Init"] = "InitCtrl";m_mapFuncChange["Add"] = "AddOneItem";m_mapFuncChange["Show"] = "ShowCtrl";m_mapFuncChange["SetLockFirstRow"] = "SetFirstRowFixed";m_mapFuncChange["AddButton"] = "AddOneBtn";m_mapFuncChange["SetButtonFocus"] = "SetBtnFocus";m_mapFuncChange["SetButtonStatus"] = "SetBtnStatus";m_mapFuncChange["SetButtonText"] = "SetBtnText";m_mapFuncChange["SetItem"] = "SetItemValue";m_mapFuncChange["SetItemThenSetUnit"] = "SetItemAndUnit";m_mapFuncChange["GetSelectionItem"] = "GetCurSelItem";m_mapFuncChange["SetUnit"] = "SetItemUnit";m_mapFuncChange["SetName"] = "SetItemName";m_mapFuncChange["DelItem"] = "DeleteOneItem";m_mapFuncChange["EnableEsc"] = "SetBackBtnStatus";m_mapFuncChange["SetTitle"] = "SetCaption";m_mapFuncChange["SetColWidth"] = "SetColumnWid";m_mapFuncChange["GetCurSelected"] = "GetCurSelectItem";m_mapFuncChange["FromUIDataStream"] = "ByDataStreamCtrl";m_mapFuncChange["EnableReferenceColumn"] = "SetReferenceCol";m_mapFuncChange["SetHelp"] = "SetHelpBtn";m_mapFuncChange["SetButtonCaption"] = "SetBtnCaption";m_mapFuncChange["EnableMenu"] = "SetMenuMode";m_mapFuncChange["SetSoftKeyboard"] = "SetKeyboardShow";m_mapFuncChange["ShowManyCombo"] = "ShowMultiInput";m_mapFuncChange["ShowManyEdit"] = "ShowMultiEdit";m_mapFuncChange["SetNullInput"] = "SetInputEmpty";m_mapFuncChange["GetStringManyCombo"] = "GetMultiInputVctStr";m_mapFuncChange["SetSplitStringSeparator"] = "SetSeparatorString";m_mapFuncChange["GetCurrenSelManyCombo"] = "GetMultiInputCurSel";m_mapFuncChange["SetComboPromptFormat"] = "SetInputPromptFmt";m_mapFuncChange["SetSaveToFile"] = "SetSaveHistory";m_mapFuncChange["GetInterger"] = "GetIntValue";m_mapFuncChange["GetString"] = "GetStringValue";m_mapFuncChange["adsShowMenu"] = "FxShowMenu";m_mapFuncChange["adsMulShowMenu"] = "FxShowMultiMenu";m_mapFuncChange["adsSpecTitleShowMenu"] = "FxShowUniqueMenu";m_mapFuncChange["AddCString"] = "AddOneItem";m_mapFuncChange["SetDisplayIndex"] = "SetShowIndex";m_mapFuncChange["ShowSpecialButton"] = "ShowCustomButton";m_mapFuncChange["adsProgressBar"] = "FxProgressBar";m_mapFuncChange["adsMessageBox"] = "FxShowMessageBox";m_mapFuncChange["SetBusy"] = "SetBusyStatus";m_mapFuncChange["AddButtonFree"] = "AddCustomButton";m_mapFuncChange["SetMaxItemSelect"] = "SetSelectMaxNum";m_mapFuncChange["SetPicture"] = "SetPictureInfo";m_mapFuncChange["AddText"] = "AddPictureText";m_mapFuncChange["AddPower"] = "AddOnePower";m_mapFuncChange["ModifyPower"] = "ModifyOnePower";m_mapFuncChange["SetPower"] = "SetOnePower";m_mapFuncChange["Reset"] = "ResetCtrl";m_mapFuncChange["SetValue"] = "SetItemValue";m_mapFuncChange["SetDTC"] = "SetHaveDtc";m_mapFuncChange["FinishedScan"] = "FinishScan";m_mapFuncChange["BeginErase"] = "StartClearDtc";m_mapFuncChange["EndErase"] = "FinishClearDtc";m_mapFuncChange["IsErasing"] = "IsClearingDtc";m_mapFuncChange["SetESCBtnEnable"] = "EnableBackButton";m_mapFuncChange["SetUpText"] = "SetTextAbove";m_mapFuncChange["SetDownText"] = "SetTextBelow";m_mapFuncChange["SetFreezeFrame"] = "SetItemFreezeFrame";m_mapFuncChange["SetOnlyCodeColumHelp"] = "SetShowCodeHelpOnly";m_mapFuncChange["adsGetTextFromDsHelpLib"] = "FxGetDsHelpString";m_mapFuncChange["adsGetTextFromTextLibEx"] = "FxGetStdStringEx";m_mapFuncChange["adsGetTextFromTextLib"] = "FxGetStdString";m_mapFuncChange["adsGetStdText_CString"] = "FxGetStdCString";m_mapFuncChange["adsGetStdText"] = "FxGetStdStringBase";m_mapFuncChange["ClearVectorText"] = "ResetMemoryBuffer";m_mapFuncChange["SearchId"] = "SearchBinary";m_mapFuncChange["SearchIdEx"] = "SearchBinaryEx";m_mapFuncChange["GetText"] = "GetStringByBinary";m_mapFuncChange["SelectWhile"] = "SearchWithCondition";m_mapFuncChange["SetReadFileToMemery"] = "SetMemoryBufferMode";m_mapFuncChange["GetLanguage"] = "GetLanguageCode";m_mapFuncChange["DecrypText"] = "DecodeString";m_mapFuncChange["Encryption"] = "EncodeString";m_mapFuncChange["OnAuthorizationFile"] = "EncodeFileName";m_mapFuncChange["Reset"] = "ResetCtrl";m_mapFuncChange["Set"] = "InitManager";m_mapFuncChange["GetValue"] = "GetItemValue";m_mapFuncChange["SetValue"] = "SetItemValue";m_mapFuncChange["GetLine"] = "GetOneLine";m_mapFuncChange["SetBps"] = "SetBaudRate";m_mapFuncChange["SetCommTime"] = "SetTimeParameter";m_mapFuncChange["SetIoPort"] = "SetCommPort";m_mapFuncChange["SetIoStatu"] = "SetPortStatus";m_mapFuncChange["GetStatus"] = "GetPortStatus";m_mapFuncChange["SetProtocol"] = "SetCommProtocol";m_mapFuncChange["Delete"] = "DeleteByte";m_mapFuncChange["SetAt"] = "SetByteAt";m_mapFuncChange["GetAt"] = "GetByteAt";m_mapFuncChange["GetSize"] = "GetByteCount";m_mapFuncChange["SetSize"] = "SetByteCount";//////////////////////////////////////////////////////////////////////////要修改的代码文件名对应关系添加到此,只需添加.h即可,.cpp后续会自动处理添加m_mapFileChange["UIBase.h"] = "BaseCtrl.h";m_mapFileChange["UIActTest.h"] = "ActTestCtrl.h";m_mapFileChange["UIDataStream.h"] = "DataStreamCtrl.h";m_mapFileChange["UIDataStreamBase.h"] = "DataStreamBaseCtrl.h";m_mapFileChange["UIEcuInfo.h"] = "EcuInfoCtrl.h";m_mapFileChange["UIFreezeFrame.h"] = "FreezeFrameCtrl.h";m_mapFileChange["UIInput.h"] = "InputCtrl.h";m_mapFileChange["UIMenu.h"] = "MenuCtrl.h";m_mapFileChange["UIMessageBox.h"] = "MessageBoxCtrl.h";m_mapFileChange["UIMultiSelected.h"] = "MultiSelectCtrl.h";m_mapFileChange["UIPicture.h"] = "PictureCtrl.h";m_mapFileChange["UIPowerBalance.h"] = "PowerBalanceCtrl.h";m_mapFileChange["UIScanSelect.h"] = "DtcScanCtrl.h";m_mapFileChange["UITimeProgress.h"] = "TimeProgressCtrl.h";m_mapFileChange["UITroubleCode.h"] = "TroubleCodeCtrl.h";m_mapFileChange["DataSheet.h"] = "TextLibrary.h";m_mapFileChange["ProFile.h"] = "FileManager.h";m_mapFileChange["EcuInterface.h"] = "VehicleComm.h";m_mapFileChange["ViewUIActTest.h"] = "ActTestCtrlView.h";m_mapFileChange["ViewUIDataStream.h"] = "DataStreamCtrlView.h";m_mapFileChange["ViewUIEcuInfo.h"] = "EcuInfoCtrlView.h";m_mapFileChange["ViewUIFreezeFrame.h"] = "FreezeFrameCtrlView.h";m_mapFileChange["ViewUIInput.h"] = "InputCtrlView.h";m_mapFileChange["ViewUIMenu.h"] = "MenuCtrlView.h";m_mapFileChange["ViewUIMenuPath.h"] = "MenuPathCtrlView.h";m_mapFileChange["ViewUIMessageBox.h"] = "MessageBoxCtrlView.h";m_mapFileChange["ViewUIMultiSelected.h"] = "MultiSelectCtrlView.h";m_mapFileChange["ViewUIPicture.h"] = "PictureCtrlView.h";m_mapFileChange["ViewUIPowerBalance.h"] = "PowerBalanceCtrlView.h";m_mapFileChange["ViewUIScanSelect.h"] = "DtcScanCtrlView.h";m_mapFileChange["ViewUITimeProgress.h"] = "TimeProgressCtrlView.h";m_mapFileChange["ViewUITroubleCode.h"] = "TroubleCodeCtrlView.h";//////////////////////////////////////////////////////////////////////////其他变更(既不是类名也不是函数名)的对应关系添加到此m_mapOtherChange["CSysInterface::CSysKeyboard::KEY_UP"] = "KEY_PRESS_UP";m_mapOtherChange["CSysInterface::CSysKeyboard::KEY_DOWN"] = "KEY_PRESS_DOWN";m_mapOtherChange["CSysInterface::CSysKeyboard::KEY_LEFT"] = "KEY_PRESS_LEFT";m_mapOtherChange["CSysInterface::CSysKeyboard::KEY_RIGHT"] = "KEY_PRESS_RIGHT";m_mapOtherChange["CSysInterface::CSysKeyboard::KEY_F1"] = "KEY_PRESS_F1";m_mapOtherChange["CSysInterface::CSysKeyboard::KEY_F2"] = "KEY_PRESS_F2";m_mapOtherChange["CSysInterface::CSysKeyboard::KEY_F3"] = "KEY_PRESS_F3";m_mapOtherChange["CSysInterface::CSysKeyboard::KEY_HELP"] = "KEY_PRESS_HELP";//////////////////////////////////////////////////////////////////////////要查找的关键字对应关系添加到此m_vctKeyWords.push_back("DAS_HOST_PROG");m_vctKeyWords.push_back("MAXI_DAS_PROG");m_vctKeyWords.push_back("WIN32_608PC");m_vctKeyWords.push_back("MAXIDAS");m_vctKeyWords.push_back("MAXICHECK");m_vctKeyWords.push_back("MAXIDIAGELITE");m_vctKeyWords.push_back("MaxiCHK");m_vctKeyWords.push_back("autel");m_vctKeyWords.push_back("hyy");m_vctKeyWords.push_back("jar");m_vctKeyWords.push_back("wcx");m_vctKeyWords.push_back("pxx");m_vctKeyWords.push_back("panxiangxi");m_vctKeyWords.push_back("DJM");m_vctKeyWords.push_back("zyc");m_vctKeyWords.push_back("drx");//////////////////////////////////////////////////////////////////////////有可能会遇到的已不再使用的文件名添加到此,以便程序删除工程配置,删除#includem_vctDeleted.push_back("Beep.h");m_vctDeleted.push_back("Beep.cpp");m_vctDeleted.push_back("DasCtrl.h");m_vctDeleted.push_back("DasCtrl.cpp");m_vctDeleted.push_back("BCMenu.h");m_vctDeleted.push_back("BCMenu.cpp");m_vctDeleted.push_back("BtnST.h");m_vctDeleted.push_back("BtnST.cpp");m_vctDeleted.push_back("CeBtnST.h");m_vctDeleted.push_back("CeBtnST.cpp");m_vctDeleted.push_back("CeXDib.h");m_vctDeleted.push_back("CeXDib.cpp");m_vctDeleted.push_back("chatsocket.h");m_vctDeleted.push_back("chatsocket.cpp");m_vctDeleted.push_back("ComboBoxCustom.h");m_vctDeleted.push_back("ComboBoxCustom.cpp");m_vctDeleted.push_back("CommonMessage.h");m_vctDeleted.push_back("CommonMessage.cpp");m_vctDeleted.push_back("Explorer.h");m_vctDeleted.push_back("Explorer.cpp");m_vctDeleted.push_back("HeaderCtrlExt.h");m_vctDeleted.push_back("HeaderCtrlExt.cpp");m_vctDeleted.push_back("Msg.h");m_vctDeleted.push_back("Msg.cpp");m_vctDeleted.push_back("newres.h");m_vctDeleted.push_back("newres.cpp");m_vctDeleted.push_back("Printer.h");m_vctDeleted.push_back("Printer.cpp");m_vctDeleted.push_back("ShadeButtonST.h");m_vctDeleted.push_back("ShadeButtonST.cpp");m_vctDeleted.push_back("MenuEx.h");m_vctDeleted.push_back("MenuEx.cpp");m_vctDeleted.push_back("NetLog.h");m_vctDeleted.push_back("NetLog.cpp");m_vctDeleted.push_back("SipEdit.h");m_vctDeleted.push_back("SipEdit.cpp");m_vctDeleted.push_back("StaticEx.h");m_vctDeleted.push_back("StaticEx.cpp");m_vctDeleted.push_back("SysInterface.h");m_vctDeleted.push_back("SysInterface.cpp");m_vctDeleted.push_back("LinkBaseCan.h");m_vctDeleted.push_back("LinkBaseCan.cpp");m_vctDeleted.push_back("LinkLayerBase.h");m_vctDeleted.push_back("LinkLayerBase.cpp");//////////////////////////////////////////////////////////////////////////其他处理map<string, string> mpTmp;for (map<string, string>::iterator itMap = m_mapFileChange.begin() ; itMap != m_mapFileChange.end() ; itMap ++){string strOld = itMap->first, strNew = itMap->second;transform(strOld.begin(), strOld.end(), strOld.begin(), ::tolower);mpTmp[strOld] = strNew;int iOldExt = strOld.find("."), iNewExt = strNew.find(".");strOld = strOld.substr(0,iOldExt) + ".cpp", strNew = strNew.substr(0,iNewExt) + ".cpp";mpTmp[strOld] = strNew;}m_mapFileChange.clear();m_mapFileChange = mpTmp;for (unsigned int iVct = 0 ; iVct < m_vctKeyWords.size() ; iVct ++){string strOld = m_vctKeyWords[iVct];transform(strOld.begin(), strOld.end(), strOld.begin(), ::tolower);m_vctKeyWords[iVct] = strOld;}for (unsigned int iVct = 0 ; iVct < m_vctDeleted.size() ; iVct ++){string strOld = m_vctDeleted[iVct];transform(strOld.begin(), strOld.end(), strOld.begin(), ::tolower);m_vctDeleted[iVct] = strOld;}
#endif
}void CSrcToolDlg::OnBnClickedButtonFuncStart()
{// TODO: Add your control notification handler code hereGetDlgItem(IDC_BUTTON_FUNC_START)->EnableWindow(FALSE);AfxBeginThread(FunctionProc,this,THREAD_PRIORITY_NORMAL);
}void CSrcToolDlg::OnBnClickedButtonSearch()
{// TODO: Add your control notification handler code hereSetDlgItemText(IDC_EDIT_SEARCH_OUTPUT,_T(""));CString strKey = _T("");GetDlgItemText(IDC_EDIT_SEARCH_INPUT,strKey);if(strKey.GetLength() < 2){SetDlgItemText(IDC_EDIT_SEARCH_OUTPUT,_T("请输入最少2个长度进行查询!"));return;}vector<string> vctRet;string strSearch = CString2string(strKey);transform(strSearch.begin(), strSearch.end(), strSearch.begin(), ::tolower);for (map<string, string>::iterator itMap = m_mapClassChange.begin() ; itMap != m_mapClassChange.end() ; itMap ++){string strOld = itMap->first, strNew = itMap->second;string strCmp = strOld;transform(strCmp.begin(), strCmp.end(), strCmp.begin(), ::tolower);if((strCmp.find(strSearch) != -1) && (strNew.length() > 0))vctRet.push_back(strOld + " --> " + strNew);}for (map<string, string>::iterator itMap = m_mapFuncChange.begin() ; itMap != m_mapFuncChange.end() ; itMap ++){string strOld = itMap->first, strNew = itMap->second;string strCmp = strOld;transform(strCmp.begin(), strCmp.end(), strCmp.begin(), ::tolower);if((strCmp.find(strSearch) != -1) && (strNew.length() > 0))vctRet.push_back(strOld + " --> " + strNew);}if(vctRet.size() == 0){SetDlgItemText(IDC_EDIT_SEARCH_OUTPUT,_T("没有查询到符合条件的项!"));return;}for (unsigned int iRet = 0 ; iRet < vctRet.size() ; iRet ++){CString strMsg = string2CString(vctRet[iRet]);AppendMsgShow(strMsg, IDC_EDIT_SEARCH_OUTPUT);}GetDlgItem(IDC_EDIT_SEARCH_OUTPUT)->PostMessage(WM_VSCROLL, SB_BOTTOM,0);
}LRESULT CSrcToolDlg::OnFunctionMsg(WPARAM wParam,LPARAM lParam)
{int iMsgType = (int)lParam, iValue = (int)wParam;if(iMsgType == 0)//Finish{GetDlgItem(IDC_BUTTON_FUNC_START)->EnableWindow(TRUE);AppendMsgShow(_T(""), IDC_EDIT_FUNC_OUTPUT);if(m_vctKeyWordsFound.size())AppendMsgShow(_T("检测到含有关键字的文件信息如下:"), IDC_EDIT_FUNC_OUTPUT);for (unsigned int iFound = 0 ; iFound < m_vctKeyWordsFound.size() ; iFound ++)AppendMsgShow(m_vctKeyWordsFound[iFound], IDC_EDIT_FUNC_OUTPUT);AppendMsgShow(_T("操作完成"), IDC_EDIT_FUNC_OUTPUT);GetDlgItem(IDC_EDIT_FUNC_OUTPUT)->PostMessage(WM_VSCROLL, SB_BOTTOM,0);ResetAllData();}else if(iMsgType == 1)//Show stringAppendMsgShow(g_strMsg, IDC_EDIT_FUNC_OUTPUT);else if(iMsgType == 2)//Set Progress Range{m_iTotalFiles = iValue;m_progress.SetRange(0,iValue);CString strTotal = _T("");strTotal.Format(_T("检测到共有 %d 个文件需要处理"),iValue);AppendMsgShow(strTotal,IDC_EDIT_FUNC_OUTPUT);}else if(iMsgType == 3)//Set Progress Pos{m_progress.SetPos(iValue);CString strCurPos = _T("");strCurPos.Format(_T("%d / %d : "),iValue,m_iTotalFiles);SetDlgItemText(IDC_STATIC_CURPOS,strCurPos + g_strMsg);}return 0;
}void CSrcToolDlg::AppendMsgShow(CString strMsg, UINT uIdCtrl)
{CString strHave = _T("");GetDlgItemText(uIdCtrl,strHave);if(strHave.GetLength())strHave += _T("\r\n");strHave += strMsg;SetDlgItemText(uIdCtrl,strHave);
}
这篇关于程序修改文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!