#include <iostream>
#include <fstream>
#include <afx.h>
#include <string>
using namespace std;
int WCharToChar(UINT PageCode, std::wstring strWChar, std::string &strChar);
int findKey(const string key);
int main()
{
CFileFind finder;
// build a string with wildcards
CString propertiesdir("class\\*.properties");
// start working for files
BOOL bWorking = finder.FindFile(propertiesdir);
cout<< bWorking <<endl;
while (bWorking)
{
bWorking = finder.FindNextFile();
CString str = finder.GetFilePath();
CString strName = finder.GetFileName();
cout << str << endl;
string propertiesfile;
string fileName;
WCharToChar( CP_ACP, str.GetBuffer(), propertiesfile);
WCharToChar( CP_ACP, strName.GetBuffer(), fileName);
// cout << propertiesfile << endl;
ifstream infile(propertiesfile.c_str(), ios::in);
if( !infile)
{
cerr<< "oops! unable to open file " <<propertiesfile<<endl;
exit(0);
}
ofstream outfile(("new\\"+fileName).c_str(),ios::out);
if( !outfile)
{
cerr<< "oops! unable to open file" <<"new\\"+propertiesfile<<endl;
}
string textline;
while( getline(infile, textline, '\n'))
{
if(textline=="" || textline.find_first_of("#")==0)
outfile << textline <<endl;
else
{
string::size_type pos = textline.find_first_of("=");
string key = textline.substr(0,pos);
cout<<"key:"<<key<<" find:"<<findKey(key)<<endl;
if(findKey(key) !=0)
{
outfile << textline <<endl;
}
else
{
outfile <<"###"<< textline <<"###"<<endl;
}
}
}
}
finder.Close();
}
int findKey(const string key)
{
CFileFind finder;
// build a string with wildcards
CString jspdir("jsp\\*.jsp");
// start working for files
BOOL bWorking = finder.FindFile(jspdir);
while (bWorking)
{
bWorking = finder.FindNextFile();
CString str = finder.GetFilePath();
string jspfile;
WCharToChar( CP_ACP, str.GetBuffer(), jspfile);
cout << jspfile << endl;
ifstream infile(jspfile.c_str(), ios::in);
if( !infile)
{
cerr<< "oops! unable to open file " <<jspfile<<endl;
exit(0);
}
string textline;
while( getline(infile, textline, '\n'))
{
string::size_type pos = textline.find("\""+key+"\"");
if(pos != string::npos)
{
finder.Close();
return 1;
}
}
}
finder.Close();
return 0;
}
int WCharToChar(UINT PageCode, std::wstring strWChar, std::string &strChar)
{
strChar.clear();
int ret = 0;
int nSize = (int)strWChar.length()*2;
static char pszDest[1024*10];
if( pszDest )
{
memset( pszDest, 0, nSize+1 );
ret = WideCharToMultiByte(PageCode,NULL,strWChar.c_str(),-1,pszDest,nSize,NULL,FALSE);
pszDest[nSize] = '\0';
strChar = pszDest;
}
return ret;
}