|
@@ -51,17 +51,26 @@ void GetDirInfo()
|
|
BOOL ReplaceFileContent(LPCTSTR lpFile, std::vector<std::string> &vtOldContent, std::vector<std::string> &vtNewContent)
|
|
BOOL ReplaceFileContent(LPCTSTR lpFile, std::vector<std::string> &vtOldContent, std::vector<std::string> &vtNewContent)
|
|
{
|
|
{
|
|
if ( vtOldContent.size() != vtNewContent.size() )
|
|
if ( vtOldContent.size() != vtNewContent.size() )
|
|
|
|
+ {
|
|
|
|
+ printf(_T("错误:替换内容空!\n"));
|
|
return FALSE;
|
|
return FALSE;
|
|
|
|
+ }
|
|
|
|
|
|
if ( !PathFileExists(lpFile) )
|
|
if ( !PathFileExists(lpFile) )
|
|
|
|
+ {
|
|
|
|
+ printf(_T("错误:目标文件【%s】不存在!\n"), lpFile);
|
|
return FALSE;
|
|
return FALSE;
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
CFile myFile;
|
|
CFile myFile;
|
|
CFileException fileExp;
|
|
CFileException fileExp;
|
|
if ( !myFile.Open(lpFile, CFile::modeReadWrite, &fileExp) )
|
|
if ( !myFile.Open(lpFile, CFile::modeReadWrite, &fileExp) )
|
|
|
|
+ {
|
|
|
|
+ printf(_T("错误:打开目标文件【%s】失败!\n"), lpFile);
|
|
return FALSE;
|
|
return FALSE;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ printf(_T("替换开始[%s]!\n"),lpFile);
|
|
DWORD dwFileLength = myFile.GetLength();
|
|
DWORD dwFileLength = myFile.GetLength();
|
|
BYTE *pData = new BYTE[dwFileLength];
|
|
BYTE *pData = new BYTE[dwFileLength];
|
|
memset(pData, 0, dwFileLength);
|
|
memset(pData, 0, dwFileLength);
|
|
@@ -81,16 +90,19 @@ BOOL ReplaceFileContent(LPCTSTR lpFile, std::vector<std::string> &vtOldContent,
|
|
if ( nPos != std::string::npos )
|
|
if ( nPos != std::string::npos )
|
|
{
|
|
{
|
|
strContent.replace(nPos, it_old->size(), it_new->c_str());
|
|
strContent.replace(nPos, it_old->size(), it_new->c_str());
|
|
|
|
+ printf(_T("替换 %s - %s 成功\n"), it_old->c_str(), it_new->c_str());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if ( !myFile.Open(lpFile, CFile::modeCreate|CFile::modeWrite, &fileExp) )
|
|
if ( !myFile.Open(lpFile, CFile::modeCreate|CFile::modeWrite, &fileExp) )
|
|
|
|
+ {
|
|
|
|
+ printf(_T("错误:保存目标文件【%s】失败!\n"), lpFile);
|
|
return FALSE;
|
|
return FALSE;
|
|
|
|
+ }
|
|
|
|
|
|
myFile.Write(strContent.c_str(), strContent.size());
|
|
myFile.Write(strContent.c_str(), strContent.size());
|
|
myFile.Close();
|
|
myFile.Close();
|
|
|
|
|
|
-
|
|
|
|
return TRUE;
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
|