1 #include "StdAfx.h" 2 #include "CIMFile.h" 3 #include "Markup.h" 4 5 #ifdef UNICODE 6 #define _tcout(x) std::wcout << x; 7 #else 8 #define _tcout(x) std::cout << x; 9 #endif 10 11 char* Wide2Byte(const TCHAR* pWide) 12 { 13 char *pBytes = NULL; 14 int nLen = WideCharToMultiByte(CP_ACP,0,pWide,-1,NULL,0,NULL,NULL); 15 // get need convert length 16 int i = (int)wcslen(pWide)*sizeof(TCHAR); 17 // get need new memory size 18 pBytes = new char[i+1]; 19 if (!pBytes) // if fail then new again 20 { 21 pBytes = new char[i+1]; 22 } 23 WideCharToMultiByte(CP_ACP,0,pWide,-1,pBytes,nLen,NULL,NULL); 24 pBytes[nLen]='\0'; 25 26 return pBytes; 27 } 28 29 TCHAR* Byte2Wide(const char* pBytes) 30 { 31 TCHAR *pWide = NULL; 32 33 int nLen = MultiByteToWideChar(CP_ACP,0,pBytes,strlen(pBytes),NULL,0); 34 pWide = new wchar_t[nLen+1]; 35 if (!pWide) // if fail then new again 36 { 37 pWide = new TCHAR[nLen+1]; 38 } 39 MultiByteToWideChar(CP_ACP,0,pBytes,strlen(pBytes),pWide,nLen); 40 pWide[nLen]='\0'; 41 42 return pWide; 43 } 44 45 void _FindDirFiles(tstring dirPath, tstring suffix, vector&files) 46 { 47 TCHAR *_dirPath = new TCHAR[MAX_PATH]; 48 int len = dirPath.length() + 4; 49 _tcscpy_s(_dirPath, len, dirPath.c_str()); 50 _tcscat_s(_dirPath, len, _T("*.*")); 51 52 _finddata_t file; 53 54 char *pdirPath = Wide2Byte(_dirPath); 55 56 long lf; 57 if((lf = _findfirst(pdirPath, &file))==-1l) 58 cout<<"文件没有找到!\n"; 59 else 60 { 61 files.clear(); 62 while( _findnext( lf, &file ) == 0 ) 63 { 64 TCHAR *pName = Byte2Wide(file.name); 65 tstring str(pName); 66 int te = str.find(suffix); 67 if(te != -1){ 68 //cout< < &files) 91 { 92 char *pchar = new char[MAX_PATH]; 93 int len = dirPath.length() + 4; 94 strcpy_s(pchar, len, dirPath.c_str()); 95 strcat_s(pchar, len, "*.*"); 96 97 _finddata_t file; 98 99 long lf;100 if((lf = _findfirst(pchar, &file))==-1l)101 cout<<"文件没有找到!\n";102 else103 {104 files.clear();105 while( _findnext( lf, &file ) == 0 )106 {107 108 string str(file.name);109 int te = str.find(suffix.c_str());110 if(te != -1){111 //cout< < files;173 _FindDirFiles(strDir, suffix, files);174 int num = files.size();175 cout << " 文件总数:" << num << endl << endl;176 177 for (int i = 0; i < (int)files.size(); i++)178 {179 tstring filePath = strDir + files[i];180 int nLen = files[i].length();181 TCHAR *strTemp = new TCHAR[nLen + 1];182 _tcscpy_s(strTemp, nLen + 1, files[i].c_str());183 wcstok(strTemp, _T("_"));184 CIM_NODE::nParseTblId = _ttoi(wcstok(NULL, _T("_")));185 DELETE_POINTER(strTemp);186 187 wcout << " ["<< i << "/" << num << "] 正在解析:" << files[i].c_str();188 ParseFile(filePath.c_str());189 }190 191 wcout << " 解析完毕!" << endl;192 193 return TRUE;194 }195 196 BOOL CCIMFile::ParseFile(LPCTSTR strFilePath)197 {198 //string path = "D:\\iStudio\\svn\\SZ_REVA\\PowerES\\prog\\data\\GISCIM\\";199 200 int numsOfPSR = 0;201 202 if(!m_pXML->Load((MCD_CSTR)strFilePath))203 return FALSE;204 205 switch (CIM_NODE::nParseTblId)206 {207 case 76: // CIM_DIST_LOADSWITCHDET208 {209 m_pXML->ResetMainPos();210 CIM_NODE::strParseTblName = CIM_DIST_LOADSWITCHDET::strTblName;211 while (m_pXML->FindChildElem(MCD_CSTR(_T("cim:") + CIM_DIST_LOADSWITCHDET::strTblName)))212 {213 CIM_DIST_LOADSWITCHDET *pNode = m_arPDLoadSWDet.AddItem();214 pNode->Parse(m_pXML);215 216 mpNode.insert(pair (pNode->nID, pNode));217 mpTbl.insert(pair (CIM_NODE::nParseTblId, pNode));218 219 numsOfPSR++;220 }221 222 }223 break;224 }225 226 wcout << "\t 新增解析对象个数:" << numsOfPSR << " ,共 " << mpNode.size() << "个" << endl << endl;227 228 return TRUE;229 }