bool JPGDecoder::CanDecode(const std::string &filename) { CFile *fp = new CFile(); bool ret = false; unsigned char magic[2]; if (fp->Open(filename)) { //JPEG image files begin with FF D8 and end with FF D9. // check for FF D8 big + little endian on start uint64_t readbytes = fp->Read(magic, 2); if (readbytes == 2) { if ((magic[0] == 0xd8 && magic[1] == 0xff) || (magic[1] == 0xd8 && magic[0] == 0xff)) ret = true; } if (ret) { ret = false; //check on FF D9 big + little endian on end uint64_t fileSize = fp->GetFileSize(); fp->Seek(fileSize - 2); readbytes = fp->Read(magic, 2); if (readbytes == 2) { if ((magic[0] == 0xd9 && magic[1] == 0xff) || (magic[1] == 0xd9 && magic[0] == 0xff)) ret = true; } } } delete fp; return ret; }
///////////////////////////////////////////////////////////////////////////// // load a map from the database into the current map file ///////////////////////////////////////////////////////////////////////////// void CMapDatabase::loadMap(int iMap) { CFile file; //open the database file if(!file.Open(FILE_MAP, CFile::modeRead)) { return; } //seek to this position in the game file file.Seek(m_dwOffsets[iMap], CFile::begin); CArchive ar(&file, CArchive::load); //load the file version ar >> m_fVer; //read the game data m_Map.Serialize(ar); //cleanup ar.Close(); file.Close(); }
void BMReadWeaponInfoD1 (CFile& cf) { cf.Seek ( sizeof (int) + sizeof (int) + sizeof (tBitmapIndex) * D1_MAX_TEXTURES + sizeof (D1_tmap_info) * D1_MAX_TEXTURES + sizeof (ubyte) * D1_MAX_SOUNDS + sizeof (ubyte) * D1_MAX_SOUNDS + sizeof (int) + sizeof (tVideoClip) * D1_VCLIP_MAXNUM + sizeof (int) + sizeof (D1_eclip) * D1_MAX_EFFECTS + sizeof (int) + sizeof (tD1WallClip) * D1_MAX_WALL_ANIMS + sizeof (int) + sizeof (D1Robot_info) * D1_MAX_ROBOT_TYPES + sizeof (int) + sizeof (tJointPos) * D1_MAX_ROBOT_JOINTS, SEEK_CUR); gameData.weapons.nTypes [1] = cf.ReadInt (); for (int i = 0; i < gameData.weapons.nTypes [1]; i++) BMReadWeaponInfoD1N (cf, i); }
/*A_weight*/ float A_weight(float xin[],int N,int fs) { //----------------------------- char* lpszFileName; CFile aweight; CFileException fileException; //----------------------------- lpszFileName = "C:\\Program Files\\Evndaq\\AWeightdata.dat";/**/ aweight.Open(lpszFileName,CFile::modeRead | CFile::typeBinary, &fileException); //------------------------------------------ FFT(xin,N); float p00 = (float)2e-5; int fp; float aw; float av = 0; float tem; for (int d = 0; d < N/2; d++) { if (xin[d] == 0) { xin[d] = (float)2e-5; } tem = xin[d]; xin[d]=20*log10(tem/p00); fp = d*fs/N; aweight.Seek(2*fp*sizeof(float),CFile::begin); aweight.Read((void*)&aw,sizeof(float)); xin[d] =xin[d] + aw; av += pow(10,0.1*xin[d]); } av = 10*log10(av)-14;//修正14db aweight.Close(); return av; }
void Load() { if (!CFile::Exists(GetConfigPath())) { DEBUG("ignore: Config file doesn't exist"); return; } if (!CFile::IsReg(GetConfigPath())) { DEBUG("ignore: Config file isn't a file"); return; } CFile *pFile = new CFile(GetConfigPath()); if (!pFile->Open(GetConfigPath(), O_RDONLY)) { DEBUG("ignore: Error opening config file"); delete pFile; return; } if (!pFile->Seek(0)) { DEBUG("ignore: Error, can't seek to start of config file."); delete pFile; return; } m_vIgnores.clear(); CString sLine; while (pFile->ReadLine(sLine)) { sLine.TrimLeft(); sLine.TrimRight("\n"); CIgnore Ignore = CIgnore(sLine); m_vIgnores.push_back(Ignore); } }
static int ReadBotGenInfo (CFile& cf) { if (gameFileInfo.botGen.offset > -1) { int i, j; if (cf.Seek (gameFileInfo.botGen.offset, SEEK_SET)) { Error ("Error seeking to robot generator data\n(file damaged or invalid)"); return -1; } for (i = 0; i < gameFileInfo.botGen.count; i++) { if (gameTopFileInfo.fileinfoVersion < 27) { old_tMatCenInfo m; OldMatCenInfoRead (&m, cf); gameData.matCens.botGens [i].objFlags [0] = m.objFlags; gameData.matCens.botGens [i].objFlags [1] = 0; gameData.matCens.botGens [i].xHitPoints = m.xHitPoints; gameData.matCens.botGens [i].xInterval = m.xInterval; gameData.matCens.botGens [i].nSegment = m.nSegment; gameData.matCens.botGens [i].nFuelCen = m.nFuelCen; } else MatCenInfoRead (gameData.matCens.botGens + i, cf); // Set links in gameData.matCens.botGens to gameData.matCens.fuelCenters array for (j = 0; j <= gameData.segs.nLastSegment; j++) if ((SEGMENTS [j].m_nType == SEGMENT_IS_ROBOTMAKER) && (SEGMENTS [j].m_nMatCen == i)) { gameData.matCens.botGens [i].nFuelCen = SEGMENTS [j].m_value; break; } } } return 0; }
int KiesBNR::OtherFilestoDecode(char* inputPath, char* outputPath, char* fileName){ //Read Input File CString inputPathString = (CString)inputPath; if(!PathFileExists((LPCWSTR)inputPathString)) return 0; UINT XMLDataOffset = 0; CFile input; if ( !input.Open((LPCWSTR)inputPathString, CFile::modeRead | CFile::modeNoTruncate | CFile::typeBinary) ) { return false; } //XML 데이터 크기만큼의 버퍼 생성; int nBufSize = input.GetLength(); char* XMLData = new char[nBufSize+1]; ZeroMemory(XMLData, nBufSize+1); //버퍼에 XML 내용을 읽어들인다.; input.Seek(XMLDataOffset, input.begin); input.Read(XMLData, nBufSize+1); //XML 데이터가 NULL일경우 False 반환; if (XMLData == NULL) return false; //메모리상에 있는 XML 데이터를 오픈 (Parse); TiXmlDocument m_Document; m_Document.Parse(XMLData); // xml open // 루트노드 접근.; TiXmlElement* pRoot = m_Document.FirstChildElement("MtpUtilItems"); if (!pRoot) goto END_PROCESS; // 값을 읽고자 하는 Welcome 엘리먼트로 접근.; TiXmlElement* pElem = pRoot->FirstChildElement("Items")->FirstChildElement(); if (!pElem) goto END_PROCESS; while(pElem) { CString str1=_T(""); CString element=_T(""); DWORD str_Len = 0; TCHAR * dstTCHAR = NULL; char *psNode = (char*)pElem->Value(); str_Len = MultiByteToWideChar(CP_ACP, 0, psNode, strlen(psNode), NULL, NULL); dstTCHAR = new TCHAR[str_Len + 1]; memset(dstTCHAR, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, psNode, strlen(psNode), dstTCHAR, str_Len); element.Format(L"%s",dstTCHAR); delete [] dstTCHAR; if(element.Find(L"MtpUtilItem")!=-1) { TiXmlElement* pElem_1=pElem->FirstChildElement(); while(pElem_1) { CString str_1=_T(""); CString element_1=_T(""); DWORD str_Len_1 = 0; TCHAR * dstTCHAR_1 = NULL; char *psNode_1 = (char*)pElem_1->Value(); str_Len = MultiByteToWideChar(CP_ACP, 0, psNode_1, strlen(psNode_1), NULL, NULL); dstTCHAR_1 = new TCHAR[str_Len + 1]; memset(dstTCHAR_1, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, psNode_1, strlen(psNode_1), dstTCHAR_1, str_Len); element_1.Format(L"%s",dstTCHAR_1); delete [] dstTCHAR_1; if(element_1.Find(_T("FileContent"))!= -1){ TCHAR* dstTch = NULL; const char *text = pElem_1->GetText(); if(text == NULL) break; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str1.Format((L"%s"),dstTch); delete [] dstTch; //base64 Decoding string cipher(text); PBYTE buf_cipher = (PBYTE)malloc(cipher.size()+1); buf_cipher[cipher.size()] = 0x00; memcpy(buf_cipher, cipher.c_str(), cipher.size()); INT length = base64_decode((PCHAR)buf_cipher, buf_cipher, cipher.size()); strcat_s(outputPath, strlen(outputPath)+8, "Decode_"); strcat_s(outputPath, strlen(outputPath)+strlen(fileName)+1, fileName); CFile decodefileoutput; if ( !PathFileExists((CString)outputPath) ) { if( decodefileoutput.Open((CString)outputPath, CFile::modeCreate | CFile::modeWrite ) == FALSE) return FALSE; decodefileoutput.Write(buf_cipher, length); decodefileoutput.Close(); } CArkLib ark; if(ark.Create(ARK_DLL_RELEASE_FILE_NAME)!=ARKERR_NOERR) return 0; if(ark.Open(outputPath) == FALSE) return 0; int len = strlen(outputPath)+2; strcat_s(outputPath, len + 2, "_"); ark.ExtractAllTo(outputPath); ark.Destroy(); } pElem_1 = pElem_1->NextSiblingElement(); } } pElem = pElem->NextSiblingElement(); } END_PROCESS: m_Document.Clear(); if(XMLData) delete XMLData; return 1; }
int KiesBNR::SMemoFiletoDecode(char* inputPath, char* outputPath){ CString inputPathString = (CString)inputPath; if(!PathFileExists((LPCWSTR)inputPathString)) return 0; UINT XMLDataOffset = 0; CFile input; if ( !input.Open((LPCWSTR)inputPathString, CFile::modeRead | CFile::modeNoTruncate | CFile::typeBinary) ) { return false; } //XML 데이터 크기만큼의 버퍼 생성; int nBufSize = input.GetLength(); char* XMLData = new char[nBufSize+1]; ZeroMemory(XMLData, nBufSize+1); //버퍼에 XML 내용을 읽어들인다.; input.Seek(XMLDataOffset, input.begin); input.Read(XMLData, nBufSize+1); //XML 데이터가 NULL일경우 False 반환; if (XMLData == NULL) return false; //메모리상에 있는 XML 데이터를 오픈 (Parse); TiXmlDocument m_Document; m_Document.Parse(XMLData); // xml open // 루트노드 접근.; TiXmlElement* pRoot = m_Document.FirstChildElement("SMemoItems"); if (!pRoot) goto END_PROCESS; // 값을 읽고자 하는 Welcome 엘리먼트로 접근.; TiXmlElement* pElem = pRoot->FirstChildElement("Items")->FirstChildElement(); if (!pElem) goto END_PROCESS; while(pElem) { CString str1 = _T(""); CString str2 = _T(""); CString str3 = _T(""); CString str4 = _T(""); CString element = _T(""); DWORD str_Len = 0; TCHAR * dstTCHAR = NULL; char *psNode = (char*)pElem->Value(); str_Len = MultiByteToWideChar(CP_ACP, 0, psNode, strlen(psNode), NULL, NULL); dstTCHAR = new TCHAR[str_Len + 1]; memset(dstTCHAR, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, psNode, strlen(psNode), dstTCHAR, str_Len); element.Format(L"%s",dstTCHAR); delete [] dstTCHAR; if(element.Find(L"SMemoItem")!=-1)//SMemoItem이 들어옴.. { TiXmlElement* pElem_1=pElem->FirstChildElement(); while(pElem_1) { CString str_1=_T(""); CString element_1=_T(""); DWORD str_Len_1 = 0; TCHAR * dstTCHAR_1 = NULL; char *psNode_1 = (char*)pElem_1->Value(); str_Len = MultiByteToWideChar(CP_ACP, 0, psNode_1, strlen(psNode_1), NULL, NULL); dstTCHAR_1 = new TCHAR[str_Len + 1]; memset(dstTCHAR_1, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, psNode_1, strlen(psNode_1), dstTCHAR_1, str_Len); element_1.Format(L"%s",dstTCHAR_1); delete [] dstTCHAR_1; if(element_1.Find(_T("RecordID"))!= -1){ TCHAR* dstTch1 = NULL; const char *text = pElem_1->GetText(); if(text == NULL) break; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch1 = new TCHAR[str_Len + 1]; memset(dstTch1, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch1, str_Len); str1.Format((L"%s"),dstTch1); delete [] dstTch1; }else if(element_1.Find(_T("CreateDate"))!= -1){ TCHAR* dstTch2 = NULL; const char *text = pElem_1->GetText(); if(text == NULL) break; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch2 = new TCHAR[str_Len + 1]; memset(dstTch2, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch2, str_Len); str2.Format((L"%s"),dstTch2); str2.Format((L"%s"),UnixTimeToStrTime(str2.Left(10))); delete [] dstTch2; }else if(element_1.Find(_T("ModifiedDate"))!= -1){ TCHAR* dstTch3 = NULL; const char *text = pElem_1->GetText(); if(text == NULL) break; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch3 = new TCHAR[str_Len + 1]; memset(dstTch3, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch3, str_Len); str3.Format((L"%s"),dstTch3); str3.Format((L"%s"),UnixTimeToStrTime(str3.Left(10))); delete [] dstTch3; }else if((element_1.Right(8) == _T("Location") )) { TCHAR* dstTch4 = NULL; const char *text = pElem_1->GetText(); if(text == NULL) break; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch4 = new TCHAR[str_Len + 1]; memset(dstTch4, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch4, str_Len); str4.Format((L"%s"),dstTch4); delete []dstTch4; }else if(element_1.Find(_T("LocationDecode"))!= -1){ const char *text = pElem_1->GetText(); if(text == NULL){ stSMemoXml.recordID = str1; stSMemoXml.createDate = str2; stSMemoXml.modifiedDate = str3; stSMemoXml.location_ = str4; stSMemoXml.locationDecode = L"NULL"; mSMemoXml.insert(pair_SMemoXml(stSMemoXml.recordID, stSMemoXml)); stSMemoXml.recordID.Empty(); stSMemoXml.createDate.Empty(); stSMemoXml.modifiedDate.Empty(); stSMemoXml.location_.Empty(); stSMemoXml.locationDecode.Empty(); break; } std::string cipher(text); PBYTE buf_cipher_ = (PBYTE)malloc(cipher.size()+1); buf_cipher_[cipher.size()] = 0x00; memcpy(buf_cipher_, cipher.c_str(), cipher.size()); INT length = base64_decode((PCHAR)buf_cipher_, (unsigned char*)buf_cipher_, cipher.size()-8 ); wchar_t *patt[4] = {L"<ThumbData>", L"<Text>", L"</ThumbData>", L"</Text>"}; wchar_t strUnicode[256] = {0,}; for(int i = 0 ; i < 2 ; i++){ long startOffset = ps.patternFind((char*)buf_cipher_, length, 0, (char *)patt[i], wcslen(patt[i])*2, pattern_sp::eMethod_KMP) + wcslen(patt[i])*2; long endOffset = ps.patternFind((char*)buf_cipher_, length, 0, (char *)patt[i+2], wcslen(patt[i+2])*2, pattern_sp::eMethod_KMP); char* buf;int sizes = endOffset - startOffset; buf = new char[sizes]; memcpy_s( buf, sizes, (char*)(buf_cipher_+startOffset), sizes ); for(int a = 0 ; a < sizes ; a+=2){ buf[a/2] = buf[a]; } int halfsize = sizes/2; INT length2 = base64_decode(buf, (unsigned char*)buf, halfsize ); if(i == 0){ CFile file_; CString PNGFileName = NULL; PNGFileName.Format(L"%s%s%s", (CString)outputPath, str1, L"_memo.png"); if ( !PathFileExists(PNGFileName) ) { if( file_.Open( PNGFileName, CFile::modeCreate | CFile::modeWrite ) == FALSE ) return FALSE; file_.Write(buf,sizes/2); file_.Close(); } }else{ //int nLen = MultiByteToWideChar(CP_UTF8, 0, (const char*)buf, strlen((char*)buf), NULL, NULL); //MultiByteToWideChar(CP_UTF8, 0, (const char*)buf, strlen((const char*)buf), strUnicode, strlen((char*)buf)+10);// utf-8 to unicode } delete []buf; } stSMemoXml.recordID = str1; stSMemoXml.createDate = str2; stSMemoXml.modifiedDate = str3; stSMemoXml.location_ = str4; stSMemoXml.locationDecode = L""; mSMemoXml.insert(pair_SMemoXml(stSMemoXml.recordID, stSMemoXml)); stSMemoXml.recordID.Empty(); stSMemoXml.createDate.Empty(); stSMemoXml.modifiedDate.Empty(); stSMemoXml.location_.Empty(); stSMemoXml.locationDecode.Empty(); } pElem_1 = pElem_1->NextSiblingElement(); } } pElem = pElem->NextSiblingElement(); } END_PROCESS: m_Document.Clear(); if(XMLData) delete XMLData; CreateWriteSMemoXmlCSVFile((CString)outputPath); return 1; }
int KiesBNR::MessageFiletoDecode(char* inputPath, char* outputPath){ //Read Input File CString inputPathString = (CString)inputPath; if(!PathFileExists((LPCWSTR)inputPathString)) return 0; UINT XMLDataOffset = 0; CFile input; if ( !input.Open((LPCWSTR)inputPathString, CFile::modeRead | CFile::modeNoTruncate | CFile::typeBinary) ) { return false; } //XML 데이터 크기만큼의 버퍼 생성; int nBufSize = input.GetLength(); char* XMLData = new char[nBufSize+1]; ZeroMemory(XMLData, nBufSize+1); //버퍼에 XML 내용을 읽어들인다.; input.Seek(XMLDataOffset, input.begin); input.Read(XMLData, nBufSize+1); //XML 데이터가 NULL일경우 False 반환; if (XMLData == NULL) return false; //메모리상에 있는 XML 데이터를 오픈 (Parse); TiXmlDocument m_Document; m_Document.Parse(XMLData); // xml open // 루트노드 접근.; TiXmlElement* pRoot = m_Document.FirstChildElement("MessageData"); if (!pRoot) goto END_PROCESS; // 값을 읽고자 하는 Welcome 엘리먼트로 접근.; TiXmlElement* pElem = pRoot->FirstChildElement("SMSList")->FirstChildElement(); TiXmlElement* pElem2 = pRoot->FirstChildElement("MMSList")->FirstChildElement();//HextoString if (!pElem) goto END_PROCESS; while(pElem) { CString str1=_T(""); CString str2=_T(""); CString str3=_T(""); CString str4=_T(""); CString element=_T(""); DWORD str_Len = 0; TCHAR * dstTCHAR = NULL; char *psNode = (char*)pElem->Value(); str_Len = MultiByteToWideChar(CP_ACP, 0, psNode, strlen(psNode), NULL, NULL); dstTCHAR = new TCHAR[str_Len + 1]; memset(dstTCHAR, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, psNode, strlen(psNode), dstTCHAR, str_Len); element.Format(L"%s",dstTCHAR); delete [] dstTCHAR; if(element.Find(L"SMSStoreItem") != -1) { TiXmlElement* pElem_1=pElem->FirstChildElement(); //pElem1=pElem1->FirstChildElement(); while(pElem_1) { CString str_1 = _T(""); CString element_1 = _T(""); DWORD str_Len_1 = 0; TCHAR * dstTCHAR_1 = NULL; // test.Format(L"%s", pElem->GetText()); char *psNode_1 = (char*)pElem_1->Value(); str_Len = MultiByteToWideChar(CP_ACP, 0, psNode_1, strlen(psNode_1), NULL, NULL); dstTCHAR_1 = new TCHAR[str_Len + 1]; memset(dstTCHAR_1, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, psNode_1, strlen(psNode_1), dstTCHAR_1, str_Len); element_1.Format(L"%s",dstTCHAR_1); delete [] dstTCHAR_1; // CreateDate if(element_1.Find(_T("CreateDate"))!= -1) { TCHAR* dstTch = NULL; const char *text = pElem_1->GetText(); if(text != NULL) { str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str1.Format((L"%s"),dstTch); str1 = ConvertUTC(str1, 9); // UTC 시간 적용 delete []dstTch; } } // Sender else if(element_1.Find(_T("Sender"))!= -1) { TCHAR* dstTch = NULL; const char *text = pElem_1->GetText(); if(text != NULL) { str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str2.Format((L"%s"),dstTch); delete []dstTch; } else str2 = L"NULL"; } // Receivers else if(element_1.Find(_T("Receivers"))!= -1) { TiXmlElement* pElem_2 = pElem_1->FirstChildElement(); const char *text = pElem_2->GetText(); if(text != NULL) { TCHAR* dstTch = NULL; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str3.Format((L"%s"), dstTch); delete []dstTch; } else str3 = L"NULL"; } else if(element_1.Find(_T("MsgState"))!= -1){ TCHAR* dstTch = NULL; const char *text = pElem_1->GetText(); if(text == NULL) break; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str4.Format((L"%s"),dstTch); delete []dstTch; } // Encoded Content else if(element_1.Find(_T("EncodedContent"))!= -1) { const char *text = pElem_1->GetText(); if(text == NULL) break; string cipher(text); PBYTE buf_cipher = (PBYTE)malloc(cipher.size()+1); buf_cipher[cipher.size()] = 0x00; memcpy(buf_cipher, cipher.c_str(), cipher.size()); INT length = base64_decode((PCHAR)buf_cipher, buf_cipher, cipher.size()); wchar_t strUnicode[256] = {0,}; int nLen = MultiByteToWideChar(CP_UTF8, 0, (const char*)buf_cipher, strlen((const char*)buf_cipher), NULL, NULL); MultiByteToWideChar(CP_UTF8, 0, (const char*)buf_cipher, strlen((const char*)buf_cipher), strUnicode, nLen);// utf-8 to unicode //strUnicode 바꿔 저장 stMessageXml.createDate = str1; stMessageXml.sender = str2; stMessageXml.receivers = str3; stMessageXml.msgState = str4; stMessageXml.encodedContent = strUnicode; mMessageXml.insert(pair_MessageXml(stMessageXml.createDate, stMessageXml)); stMessageXml.createDate.Empty(); stMessageXml.msgState.Empty(); stMessageXml.sender.Empty(); stMessageXml.receivers.Empty(); stMessageXml.encodedContent.Empty(); } pElem_1 = pElem_1->NextSiblingElement(); } } pElem = pElem->NextSiblingElement(); } while(pElem2) { CString str1=_T(""); CString str2=_T(""); CString str3=_T(""); CString str4=_T(""); CString str5=_T(""); CString str6=_T(""); CString element=_T(""); DWORD str_Len = 0; TCHAR * dstTCHAR = NULL; char *psNode = (char*)pElem2->Value(); str_Len = MultiByteToWideChar(CP_ACP, 0, psNode, strlen(psNode), NULL, NULL); dstTCHAR = new TCHAR[str_Len + 1]; memset(dstTCHAR, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, psNode, strlen(psNode), dstTCHAR, str_Len); element.Format(L"%s",dstTCHAR); delete [] dstTCHAR; if(element.Find(L"MMSStoreItem") != -1) { TiXmlElement* pElem_1=pElem2->FirstChildElement(); while(pElem_1) { CString str_1=_T(""); CString element_1=_T(""); DWORD str_Len_1 = 0; TCHAR * dstTCHAR_1 = NULL; char *psNode_1 = (char*)pElem_1->Value(); str_Len = MultiByteToWideChar(CP_ACP, 0, psNode_1, strlen(psNode_1), NULL, NULL); dstTCHAR_1 = new TCHAR[str_Len + 1]; memset(dstTCHAR_1, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, psNode_1, strlen(psNode_1), dstTCHAR_1, str_Len); element_1.Format(L"%s",dstTCHAR_1); delete [] dstTCHAR_1; if(element_1.Compare(_T("Folder")) == 0) { TCHAR* dstTch = NULL; const char *text = pElem_1->GetText(); if(text != NULL) { str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str1.Format((L"%s"),dstTch); delete []dstTch; } } // Sender else if(element_1.Find(_T("Sender"))!= -1) { TCHAR* dstTch = NULL; const char *text = pElem_1->GetText(); if(text != NULL) { str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str2.Format((L"%s"),dstTch); delete []dstTch; } else str2 = L"NULL"; } // Receivers else if(element_1.Find(_T("Receivers"))!= -1) { TiXmlElement* pElem_2 = pElem_1->FirstChildElement(); const char *text = pElem_2->GetText(); if(text != NULL) { TCHAR* dstTch = NULL; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str3.Format((L"%s"), dstTch); delete []dstTch; } else str3 = L"NULL"; } // CreateDate else if(element_1.Find(_T("CreateDate"))!= -1) { TCHAR* dstTch = NULL; const char *text = pElem_1->GetText(); if(text != NULL) { str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str5.Format((L"%s"),dstTch); str5 = ConvertUTC(str5, 9); // UTC 시간 적용 delete []dstTch; } } else if(element_1.Find(_T("MMSBody"))!= -1) { TCHAR* dstTch = NULL; const char *text = pElem_1->GetText(); std::string newString; if(text == NULL) break; str_Len = MultiByteToWideChar(CP_ACP, 0, text, strlen(text), NULL, NULL); dstTch = new TCHAR[str_Len + 1]; memset(dstTch, 0x00, str_Len * 2 + 2); MultiByteToWideChar(CP_ACP, 0, text, strlen(text), dstTch, str_Len); str6.Format((L"%s"),dstTch); delete []dstTch; CT2CA pszConvertedAnsiString (str6); string tmp(pszConvertedAnsiString); for(int i = 0; i < tmp.length() - 0x0c*2; i +=2) { string byte = tmp.substr(i+0x0c*2,2); char chr = (char) (int)strtol(byte.c_str(), NULL, 16); newString.push_back(chr); } wchar_t strUnicode[20480] = {0,}; int nLen = MultiByteToWideChar(CP_UTF8, 0, (const char*)newString.c_str(), strlen((const char*)newString.c_str()), NULL, NULL); MultiByteToWideChar(CP_UTF8, 0, (const char*)newString.c_str(), strlen((const char*)newString.c_str()), strUnicode, nLen);// utf-8 to unicode //strUnicode 바꿔 저장 stMMSMessageXml.folder = str1; stMMSMessageXml.sender = str2; stMMSMessageXml.receivers = str3; stMMSMessageXml.createDate = str5; stMMSMessageXml.mMsbody = strUnicode; mMMSMessageXml.insert(pair_MMSMessageXml(stMMSMessageXml.folder, stMMSMessageXml)); stMMSMessageXml.folder.Empty(); stMMSMessageXml.sender.Empty(); stMMSMessageXml.receivers.Empty(); stMMSMessageXml.createDate.Empty(); stMMSMessageXml.mMsbody.Empty(); } pElem_1 = pElem_1->NextSiblingElement(); } } pElem2 = pElem2->NextSiblingElement(); } END_PROCESS: m_Document.Clear(); if(XMLData) delete XMLData; CreateWriteSMSMessageXmlCSVFile((CString)outputPath); CreateWriteMMSMessageXmlCSVFile((CString)outputPath); return 1; }
int CFace::Read (CFile& cf, CSubModel *pso, CFaceVert *pfv, int bFlipV) { int i, v0 = 0; CEdge e; nIndent += 2; OOF_PrintLog ("reading face\n"); OOF_ReadVector (cf, &m_vNormal, "vNormal"); #if 0 m_vNormal.x = -m_vNormal.x; m_vNormal.y = -m_vNormal.y; m_vNormal.z = -m_vNormal.z; #endif m_nVerts = OOF_ReadInt (cf, "nVerts"); m_bTextured = OOF_ReadInt (cf, "bTextured"); if (m_bTextured) { m_texProps.nTexId = OOF_ReadInt (cf, "texProps.nTexId"); #if OOF_TEST_CUBE /*!!!*/ m_texProps.nTexId = nTexId % 6; /*!!!*/ nTexId++; #endif } else { m_texProps.color.red = OOF_ReadByte (cf, "texProps.color.red"); m_texProps.color.green = OOF_ReadByte (cf, "texProps.color.green"); m_texProps.color.blue = OOF_ReadByte (cf, "texProps.color.blue"); } #if OOF_MEM_OPT if (pfv) { m_verts = pfv; #else if (!(m_verts= new CFaceVert [m_nVerts])) { nIndent -= 2; return OOF_FreeFace (&f); } #endif OOF_InitMinMax (&m_vMin, &m_vMax); e.m_v1 [0] = -1; for (i = 0; i < m_nVerts; i++) if (!m_verts [i].Read (cf, bFlipV)) { nIndent -= 2; return 0; } else { e.m_v0 [0] = e.m_v1 [0]; e.m_v1 [0] = m_verts [i].m_nIndex; OOF_GetMinMax (pso->m_verts + e.m_v1 [0], &m_vMin, &m_vMax); if (i) pso->AddEdge (this, e.m_v0 [0], e.m_v1 [0]); else v0 = e.m_v1 [0]; } pso->AddEdge (this, e.m_v1 [0], v0); CalcCenter (pso); #if OOF_MEM_OPT } else cf.Seek (m_nVerts * sizeof (CFaceVert), SEEK_CUR); #endif m_fBoundingLength = OOF_ReadFloat (cf, "fBoundingLength"); m_fBoundingWidth = OOF_ReadFloat (cf, "fBoundingWidth"); nIndent -= 2; return m_nVerts; }
BOOL CWavFile::Convert8to16(LPBYTE lpData, DWORD &dwLength) { if(m_lpData == NULL || lpData == NULL) { return FALSE; } if(dwLength > (m_dwDataSize * 2)) { dwLength = m_dwDataSize * 2; } if(m_wBitPerSample != BITS_PER_SAMPLE_8) { return FALSE; } // fill in the low 8 bits data for(DWORD u = 0; u < dwLength / 2; u++) { memcpy(lpData + u * 2 + 1, m_lpData + u, sizeof(BYTE)); if((lpData[u * 2 + 1] & 0x80) == 0x80) { lpData[u * 2 + 1] &= 0x7f; } else { lpData[u * 2 + 1] |= 0x80; } lpData[u * 2] = 0x00; } // save it as a new wav file CFileDialog dlg(FALSE, NULL, _T("*.wav"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("WAV Files (*.wav)|*.wav||")); if(dlg.DoModal() == IDOK) { CFile fileNew; FILE *fileOld = NULL; LPCTSTR lpszFilePath = m_strWavePath; fileOld = fopen(lpszFilePath, "rb"); BOOL bOpen = fileNew.Open(dlg.GetPathName(), CFile::modeWrite | CFile::modeCreate); if(fileOld != NULL && bOpen) { _RIFFCHUNK RiffChunk; _WAVEFORMAT WaveFormat; // read RIFF WAVE chunk and format chunk fread(&RiffChunk, sizeof(_RIFFCHUNK), 1, fileOld); fread(&WaveFormat, sizeof(_WAVEFORMAT), 1, fileOld); // write RIFF WAVE chunk fileNew.Write(&RiffChunk, sizeof(_RIFFCHUNK)); WaveFormat.wBlockAlign *= 2; WaveFormat.dwAvgBytesPerSec *= 2; WaveFormat.wBitsPerSample = BITS_PER_SAMPLE_16; fileNew.Write(&WaveFormat, sizeof(_WAVEFORMAT)); // read next chunk BYTE byId[4]; DWORD dwSize = 0; fread(byId, sizeof(BYTE), 4, fileOld); fread(&dwSize, sizeof(DWORD), 1, fileOld); DWORD dwOffset = ftell(fileOld); LPBYTE lpTemp = (LPBYTE)malloc(m_RiffChunk.dwSize * sizeof(BYTE)); while(dwOffset < m_RiffChunk.dwSize) { // see if the data chunk or not if(strncmp((LPCSTR)byId, "data", 4) == 0) { fread(lpTemp, sizeof(BYTE), dwSize, fileOld); fileNew.Write(&byId, sizeof(DWORD)); fileNew.Write(&dwLength, sizeof(DWORD)); fileNew.Write(lpData, sizeof(BYTE) * dwLength); } // other chunks just copy them else { fread(lpTemp, sizeof(BYTE), dwSize, fileOld); fileNew.Write(&byId, sizeof(DWORD)); fileNew.Write(&dwSize, sizeof(DWORD)); fileNew.Write(lpTemp, sizeof(BYTE) * dwSize); } // continue to read next chunk fread(byId, sizeof(BYTE), 4, fileOld); fread(&dwSize, sizeof(DWORD), 1, fileOld); dwOffset = ftell(fileOld); } free(lpTemp); // adjust the size of RIFF DWORD dwRiffSize = RiffChunk.dwSize + dwLength / 2; fileNew.Seek(4, CFile::begin); fileNew.Write(&dwRiffSize, sizeof(DWORD)); fclose(fileOld); fileNew.Close(); } } return TRUE; }
LONG CRectangle::Readfile(CFile &file) { file.Seek(sizeof(TP),CFile::current); return CLine::Readfile(file); }
hmp_file *hmp_open(const char *filename, int bUseD1Hog) { int i; char buf [256]; long data = 0; CFile cf; hmp_file *hmp; int num_tracks, midi_div; ubyte *p; if (!cf.Open (filename, gameFolders.szDataDir, "rb", bUseD1Hog)) return NULL; hmp = new hmp_file; if (!hmp) { cf.Close(); return NULL; } memset(hmp, 0, sizeof(*hmp)); if ((cf.Read (buf, 1, 8) != 8) || (memcmp(buf, "HMIMIDIP", 8))) goto err; if (cf.Seek (0x30, SEEK_SET)) goto err; if (cf.Read (&num_tracks, 4, 1) != 1) goto err; if (cf.Seek (0x38, SEEK_SET)) goto err; if (cf.Read (&midi_div, 4, 1) != 1) goto err; if ((num_tracks < 1) || (num_tracks > HMP_TRACKS)) goto err; hmp->num_trks = num_tracks; hmp->midi_division = midi_div; hmp->tempo = 120; if (cf.Seek(0x308, SEEK_SET)) goto err; for (i = 0; i < num_tracks; i++) { if ((cf.Seek(4, SEEK_CUR)) || (cf.Read(&data, 4, 1) != 1)) goto err; data -= 12; #if 0 if (i == 0) /* track 0: reserve length for tempo */ data += sizeof(hmp_tempo); #endif hmp->trks [i].len = data; if (!(p = hmp->trks [i].data = new ubyte [data])) goto err; #if 0 if (i == 0) { /* track 0: add tempo */ memcpy(p, hmp_tempo, sizeof(hmp_tempo)); p += sizeof(hmp_tempo); data -= sizeof(hmp_tempo); } #endif /* finally, read track data */ if ((cf.Seek(4, SEEK_CUR)) || (cf.Read(p, data, 1) != 1)) goto err; } cf.Close(); return hmp; err: cf.Close(); hmp_close(hmp); return NULL; }
CFile cfile; cfile.Open(_T("Seek_File.dat"), CFile::modeCreate | CFile::modeReadWrite); LONGLONG lOffset = 1000; ULONGLONG lActual; lActual = cfile.Seek(lOffset, CFile::begin); ASSERT(cfile.GetPosition() == lActual);
bool External::Goto_Chunks_Header( CFile& file, short chunkCode, unsigned char& retVersion, long& retChunksSize, CString& retErrorMesg ) { // **** want OPTIMIZE search 9/06 ??? ********************** CString retTagString; long curPos = 0L; // ****** Always starts from the BEGINNING of the file. Is that good??? It is thourough. 9/06 **** if( ! Get_Chunks_TagString( chunkCode, retTagString, retErrorMesg ) ) return false; long filesLength = file.GetLength(); file.Seek( curPos, CFile::begin ); // ***** BAD, only occasionally search from beginning ****** bool stringNotFound = true; CString travStr = " "; // cheezy way to put a NULL terminator in the string do { file.Read( travStr.GetBuffer( 8 ), 8 ); if( retTagString.CompareNoCase( travStr ) == 0 ) stringNotFound = false; else { curPos++; if( (curPos + 8) >= filesLength ) // check for EOF { retErrorMesg.Format( "External::Goto_Chunks_Header FAILED, could not find tag's string [ %s ] in the file( hit eof )." , retTagString ); return false; } file.Seek( curPos, CFile::begin ); } }while( stringNotFound ); file.Read( &retVersion, 1 ); file.Read( &retChunksSize, 4 ); // long curFilePos = file.GetPosition(); // ...want to return this ??? **** DEBUG ONLY **** return true; }
BOOL CPreviewThread::Run() { //Xman // BEGINSLUGFILLER: SafeHash CReadWriteLock lock(&theApp.m_threadlock); if (!lock.ReadLock(0)) return 0; // END SLUGFILLER: SafeHash ASSERT (m_pPartfile) ; CFile destFile; CFile srcFile; if (!srcFile.Open(m_pPartfile->GetFilePath(), CFile::modeRead | CFile::shareDenyNone)) return FALSE; try{ uint64 nSize = m_pPartfile->GetFileSize(); CString strExtension = CString(_tcsrchr(m_pPartfile->GetFileName(), _T('.'))); CString strPreviewName = m_pPartfile->GetTempPath() + m_pPartfile->GetFileName().Mid(0, 5) + _T("_preview") + strExtension; bool bFullSized = true; if (!strExtension.CompareNoCase(_T(".mpg")) || !strExtension.CompareNoCase(_T(".mpeg"))) bFullSized = false; if (!destFile.Open(strPreviewName, CFile::modeWrite | CFile::shareDenyWrite | CFile::modeCreate)) return FALSE; srcFile.SeekToBegin(); if (bFullSized) destFile.SetLength(nSize); destFile.SeekToBegin(); BYTE abyBuffer[4096]; uint32 nRead; while (destFile.GetPosition()+4096 < PARTSIZE*2){ nRead = srcFile.Read(abyBuffer,4096); destFile.Write(abyBuffer,nRead); } srcFile.Seek(-(LONGLONG)(PARTSIZE*2), CFile::end); uint32 nToGo = PARTSIZE*2; if (bFullSized) destFile.Seek(-(LONGLONG)(PARTSIZE*2), CFile::end); do{ nRead = (nToGo - 4096 < 1)? nToGo:4096; nToGo -= nRead; nRead = srcFile.Read(abyBuffer,4096); destFile.Write(abyBuffer,nRead); } while (nToGo); destFile.Close(); srcFile.Close(); m_pPartfile->m_bPreviewing = false; SHELLEXECUTEINFO SE = {0}; SE.fMask = SEE_MASK_NOCLOSEPROCESS; CString strCommand; CString strArgs; CString strCommandDir; if (!m_strCommand.IsEmpty()) { SE.lpVerb = _T("open"); // "open" the specified video player // get directory of video player application strCommandDir = m_strCommand; int iPos = strCommandDir.ReverseFind(_T('\\')); if (iPos == -1) strCommandDir.Empty(); else strCommandDir = strCommandDir.Left(iPos + 1); PathRemoveBackslash(strCommandDir.GetBuffer()); strCommandDir.ReleaseBuffer(); strArgs = m_strCommandArgs; if (!strArgs.IsEmpty()) strArgs += _T(' '); if (strPreviewName.Find(_T(' ')) != -1) strArgs += _T('\"') + strPreviewName + _T('\"'); else strArgs += strPreviewName; strCommand = m_strCommand; ExpandEnvironmentStrings(strCommand); ExpandEnvironmentStrings(strArgs); ExpandEnvironmentStrings(strCommandDir); SE.lpFile = strCommand; SE.lpParameters = strArgs; SE.lpDirectory = strCommandDir; } else { SE.lpVerb = NULL; // use the default verb or the open verb for the document SE.lpFile = strPreviewName; } SE.nShow = SW_SHOW; SE.cbSize = sizeof(SE); ShellExecuteEx(&SE); if (SE.hProcess){ WaitForSingleObject(SE.hProcess, INFINITE); CloseHandle(SE.hProcess); } CFile::Remove(strPreviewName); } catch(CFileException* error){ m_pPartfile->m_bPreviewing = false; error->Delete(); } return TRUE; }
int CBinFileParser::GetBinFileBuffer(char* pFileBuf, int nFileBufLen) { int nFileBufSize=0; CFile binFile; if(binFile.Open(m_strFileName,CFile::modeRead)) { const int BUF_LEN = 1024; int linenum=1; char pBuf[BUF_LEN] = {'\0'}; int nRet = 0; int nCount = 0; binFile.Seek(0, CFile::begin); while( (nRet = binFile.Read(pBuf, BUF_LEN)) != 0 ) { if (linenum==1) { m_strASIX.Format(_T("%C%C%C%C"),pBuf[0],pBuf[1],pBuf[2],pBuf[3]); for (int i=0; i<20; i++) //¹Ì¶¨³¤¶È20¸ö { if (pBuf[256+i]!=0) { CString temp; temp.Format(_T("%C"),pBuf[256+i]); m_strProductName+=temp; } else { break; } } // m_strProductName.Format(_T("%C%C%C%C%C%C%C%C%C%C%C%C"),pBuf[256+0],pBuf[256+1],pBuf[256+2],pBuf[256+3],pBuf[256+4],pBuf[256+5],pBuf[256+6],pBuf[256+7],pBuf[256+8],pBuf[256+9],pBuf[256+10],pBuf[256+11]); } memcpy(pFileBuf + nCount, pBuf, nRet); nCount += nRet; if (nRet < BUF_LEN) { break; } ZeroMemory(pBuf, BUF_LEN); ++linenum; } nFileBufSize = nCount; binFile.Close(); } int ret_find_in_0x100 = 0; for (int i=0;i<2;i++) { memset(&global_fileInfor,0,sizeof(Bin_Info)); if(i==0) memcpy(&global_fileInfor,&pFileBuf[0x100],sizeof(Bin_Info)); else if(i == 1) memcpy(&global_fileInfor,&pFileBuf[0x200],sizeof(Bin_Info)); else return -1; //if(strlen(global_fileInfor.product_name) > 200) // nFileBufSize = -1; //return NO_VERSION_INFO; char temocolog[6]; memcpy_s(temocolog,5,global_fileInfor.company,5); temocolog[5] = 0; CString Temco_logo; MultiByteToWideChar( CP_ACP, 0, (char *)temocolog, (int)strlen(temocolog)+1, Temco_logo.GetBuffer(MAX_PATH), MAX_PATH ); Temco_logo.ReleaseBuffer(); Temco_logo.MakeUpper(); if(Temco_logo.CompareNoCase(_T("TEMCO")) != 0&&Temco_logo.CompareNoCase(L"CO2")!=0) { //return NO_VERSION_INFO; ret_find_in_0x100 = -1; } else return nFileBufSize; } return nFileBufSize; }
void CWaveIn::SaveFile(LPCSTR strFileName, bool bCreate, char *pszData, DWORD dwLen) { if (bCreate) { CFile file; if (file.Open(strFileName, CFile::modeCreate | CFile::modeReadWrite)) { RIFF_HEADER riff_header = {0}; FMT_BLOCK fmt_block = {0}; DATA_BLOCK data_block = {0}; memcpy(riff_header.szRiffID, "RIFF", 4); memcpy(riff_header.szRiffFormat, "WAVE", 4); riff_header.dwRiffSize = sizeof(RIFF_HEADER) + sizeof(FMT_BLOCK) + sizeof(DATA_BLOCK) + dwLen - 8; memcpy(fmt_block.szFmtID, "fmt ", 4); fmt_block.dwFmtSize = sizeof(WAVE_FORMAT); fmt_block.wavFormat.wFormatTag = WAVE_FORMAT_PCM; fmt_block.wavFormat.wChannels = m_wChannel; fmt_block.wavFormat.dwSamplesPerSec = m_dwSample; fmt_block.wavFormat.dwAvgBytesPerSec = m_wChannel * m_dwSample * m_wBit / 8; fmt_block.wavFormat.wBlockAlign = m_wBit * m_wChannel / 8; fmt_block.wavFormat.wBitsPerSample = m_wBit; memcpy(data_block.szDataID, "data", 4); data_block.dwDataSize = dwLen; file.Write(&riff_header, sizeof(RIFF_HEADER)); file.Write(&fmt_block, sizeof(FMT_BLOCK)); file.Write(&data_block, sizeof(DATA_BLOCK)); file.Write(pszData, dwLen); file.Close(); } } else { CFile file; if (file.Open(strFileName, CFile::modeReadWrite)) { RIFF_HEADER riff_header = {0}; FMT_BLOCK fmt_block = {0}; DATA_BLOCK data_block = {0}; FACT_BLOCK fat_block = {0}; WORD wData = 0; BOOL bHaveFact = FALSE; file.Read(&riff_header, sizeof(RIFF_HEADER)); file.Read(&fmt_block, sizeof(FMT_BLOCK)); if (18 == fmt_block.dwFmtSize) // 18 多2个字节的扩展数据 file.Read(&wData, 2); file.Read(&fat_block, sizeof(FACT_BLOCK)); if (0 != strncmp(fat_block.szFactID, "fact", 4)) // FACT_BLOCK是可选的 file.Seek(-12, CFile::current); else bHaveFact = TRUE; file.Read(&data_block, sizeof(DATA_BLOCK)); riff_header.dwRiffSize += dwLen; fat_block.dwDataSize += dwLen; data_block.dwDataSize += dwLen; file.SeekToBegin(); file.Write(&riff_header, sizeof(RIFF_HEADER)); file.Write(&fmt_block, sizeof(FMT_BLOCK)); if (18 == fmt_block.dwFmtSize) file.Seek(2, CFile::current); if (bHaveFact) file.Write(&fmt_block, sizeof(FMT_BLOCK)); file.Write(&data_block, sizeof(DATA_BLOCK)); file.SeekToEnd(); file.Write(pszData, dwLen); file.Close(); } } }
// 转换RGB void CRGB2YUVView::OnConvertPAL() { CDC *pDC = GetDC(); CRect rect; CBrush brush(RGB(128,128,128)); GetClientRect(&rect); pDC->FillRect(&rect, &brush); // PAL 720x576 : 中国的电视标准为PAL制 int CurrentXRes = 720; int CurrentYRes = 576; int size = CurrentXRes * CurrentYRes; // 分配内存 byte *Video_Field0 = (byte*)malloc(CurrentXRes*CurrentYRes); byte *Video_Field1 = (byte*)malloc(CurrentXRes*CurrentYRes); // 保存内存指针 byte *Video_Field0_ = Video_Field0; byte *Video_Field1_ = Video_Field1; byte yuv_y0, yuv_u0, yuv_v0, yuv_v1; // {y0, u0, v0, v1}; byte bufRGB[3]; // 临时保存{R,G,B} byte bufYUV[3]; // 临时保存{Y,U,V} // 初始化数组空间 ZeroMemory(bufRGB, sizeof(byte)*3); ZeroMemory(bufYUV, sizeof(byte)*3); // 初始化内存 ZeroMemory(Video_Field0, CurrentXRes*CurrentYRes); ZeroMemory(Video_Field1, CurrentXRes*CurrentYRes); // BMP 位图操作 BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih; char strFileName[MAX_PATH]="720bmp.bmp"; CFile* f; f = new CFile(); f->Open(strFileName, CFile::modeRead); f->SeekToBegin(); f->Read(&bmfh, sizeof(bmfh)); f->Read(&bmih, sizeof(bmih)); // 分配图片像素内存 RGBTRIPLE *rgb; rgb = new RGBTRIPLE[bmih.biWidth*bmih.biHeight]; f->SeekToBegin(); f->Seek(54,CFile::begin); // BMP 54个字节之后的是位像素数据 f->Read(rgb, bmih.biWidth * bmih.biHeight * 3); // 这里只读24位RGB(r,g,b)图像 // 上场 (1,3,5,7...行) for (int i = bmih.biHeight-1; i>=0; i--) { for (int j = 0; j<bmih.biWidth; j++) { if(!(i%2)==0) { bufRGB[0] = rgb[i*bmih.biWidth+j].rgbtRed; // R bufRGB[1] = rgb[i*bmih.biWidth+j].rgbtGreen; // G bufRGB[2] = rgb[i*bmih.biWidth+j].rgbtBlue; // B // RGB转换为YUV RGB2YUV(bufRGB,bufYUV); yuv_y0 = bufYUV[0]; // y yuv_u0 = bufYUV[1]; // u yuv_v0 = bufYUV[2]; // v for (int k=0; k<1000; k++) ; //延时 // 视图中显示 pDC->SetPixel(j, (bmih.biHeight-1)-i, RGB(bufRGB[0], bufRGB[1], bufRGB[2])); // UYVY标准 [U0 Y0 V0 Y1] [U1 Y2 V1 Y3] [U2 Y4 V2 Y5] 每像素点两个字节,[内]为四个字节 if ((j%2)==0) { *Video_Field0 = yuv_u0; Video_Field0++; yuv_v1 = yuv_v0; // v保存起来供下一字节使用 } else { *Video_Field0 = yuv_v1; Video_Field0++; } *Video_Field0 = yuv_y0; Video_Field0++; }// end if i%2 } } // 下场 (2,4,6,8...行) for (int i_ = bmih.biHeight-1; i_>=0; i_--) { for (int j_ = 0; j_<bmih.biWidth; j_++) { if((i_%2)==0) { bufRGB[0] = rgb[i_*bmih.biWidth+j_].rgbtRed; // R bufRGB[1] = rgb[i_*bmih.biWidth+j_].rgbtGreen; // G bufRGB[2] = rgb[i_*bmih.biWidth+j_].rgbtBlue; // B // RGB转换为YUV RGB2YUV(bufRGB,bufYUV); yuv_y0 = bufYUV[0]; // y yuv_u0 = bufYUV[1]; // u yuv_v0 = bufYUV[2]; // v for (int k=0; k<1000; k++) ; //延时 // 视图中显示 pDC->SetPixel(j_, (bmih.biHeight-1)-i_, RGB(bufRGB[0], bufRGB[1], bufRGB[2])); // UYVY标准 [U0 Y0 V0 Y1] [U1 Y2 V1 Y3] [U2 Y4 V2 Y5] 每像素点两个字节,[内]为四个字节 if ((j_%2)==0) { *Video_Field1 = yuv_u0; Video_Field1++; yuv_v1 = yuv_v0; // v保存起来供下一字节使用 } else { *Video_Field1 = yuv_v1; Video_Field1++; } *Video_Field1 = yuv_y0; Video_Field1++; } } } // 关闭BMP位图文件 f->Close(); WriteYUV(Video_Field0_, Video_Field1_, size); // 释放内存 free( Video_Field0_ ); free( Video_Field1_ ); delete f; delete rgb; }
DWORD ConnectionLimit::GetOffset(LPCTSTR path) { CFile file; DWORD dwOffset = 0; bool isWow = IsWow64(); PVOID oldValue = NULL; if(isWow) { MyWow64DisableWow64FsRedirection(&oldValue); } if(file.Open(path,CFile::modeRead|CFile::typeBinary)) { if(isWow) { MyWow64RevertWow64FsRedirection(oldValue); } unsigned int bytesRead = 0; char buffer[1024]; bytesRead = file.Read(buffer, 1024); while(bytesRead != 0) { for (int i = 0; i<bytesRead; ++i) { if(!isWow && (CAntiSpySettings::GetSuiteType() != CAntiSpySettings::SUITE_TYPE::WINDOWS_VISTA)) { if(buffer[i] == MAGIC_32[0]) { if(i>= (bytesRead - 5)) { int pos = file.GetPosition(); file.Seek(-5, CFile::current); bytesRead-=5; pos = file.GetPosition(); break; } for (int c = 1; c < 6; ++c) { if(buffer[i+c] != MAGIC_32[c]) { break; } else { if(c == 5) { dwOffset += i + 10; file.Close(); return dwOffset; } } } } } else if(!isWow && (CAntiSpySettings::GetSuiteType() == CAntiSpySettings::SUITE_TYPE::WINDOWS_VISTA)) { if(buffer[i] == VISTA_MAGIC_32[0]) { if(i>= (bytesRead - 8)) { int pos = file.GetPosition(); file.Seek(-8, CFile::current); bytesRead-=8; pos = file.GetPosition(); break; } for (int c = 1; c < 9; ++c) { if(buffer[i+c] != VISTA_MAGIC_32[c]) { break; } else { if(c == 8) { dwOffset += i + 9; file.Close(); return dwOffset; } } } } } else if(isWow && (CAntiSpySettings::GetSuiteType() != CAntiSpySettings::SUITE_TYPE::WINDOWS_VISTA)) { if(buffer[i] == MAGIC_64[0]) { if(i>= (bytesRead - 24)) { int pos = file.GetPosition(); file.Seek(-24, CFile::current); bytesRead-=24; pos = file.GetPosition(); break; } for (int c = 1; c < 24; ++c) { if(buffer[i+c] != MAGIC_64[c]) { break; } else { if(c == 23) { dwOffset += i + 50; file.Close(); return dwOffset; } } } } } } dwOffset += bytesRead; bytesRead = file.Read(buffer, 1024); } file.Close(); } return 0; }
// 隔行显示BMP void CRGB2YUVView::OnReadBmp() { // TODO: Add your command handler code here CDC *pDC = GetDC(); CRect rect; CBrush brush(RGB(128,128,128)); GetClientRect(&rect); pDC->FillRect(&rect, &brush); BITMAPFILEHEADER bmfh; BITMAPINFOHEADER bmih; char strFileName[MAX_PATH]="720bmp.bmp"; CFile* f; f = new CFile(); f->Open(strFileName, CFile::modeRead); f->SeekToBegin(); f->Read(&bmfh, sizeof(bmfh)); f->Read(&bmih, sizeof(bmih)); // 分配图片像素内存 RGBTRIPLE *rgb; rgb = new RGBTRIPLE[bmih.biWidth*bmih.biHeight]; f->SeekToBegin(); f->Seek(54,CFile::begin); // BMP 54个字节之后的是像素数据 f->Read(rgb, bmih.biWidth * bmih.biHeight * 3); // 这里只读24位RGB(r,g,b)图像 // 显示上场 (奇数行组成的奇数场) for (int i = 0; i<bmih.biHeight; i++) { for (int j = 0; j<bmih.biWidth; j++) { if(!(i%2)) pDC->SetPixel(j, bmih.biHeight-i, RGB(rgb[i*bmih.biWidth+j].rgbtRed,rgb[i*bmih.biWidth+j].rgbtGreen,rgb[i*bmih.biWidth+j].rgbtBlue)); for (int k=0; k<1000; k++) ; //延时 } } Sleep(500); // 显示下场 (偶数行组成的偶数场) for (int i_ = 0; i_<bmih.biHeight; i_++) { for (int j_ = 0; j_<bmih.biWidth; j_++) { if(i_%2) pDC->SetPixel(j_, bmih.biHeight-i_, RGB(rgb[i_*bmih.biWidth+j_].rgbtRed,rgb[i_*bmih.biWidth+j_].rgbtGreen,rgb[i_*bmih.biWidth+j_].rgbtBlue)); for (int k=0; k<1000; k++) ; //延时 } } // 显示24位BMP信息 LONG dwWidth = bmih.biWidth; LONG dwHeight = bmih.biHeight; WORD wBitCount = bmih.biBitCount; char buffer[80]; sprintf(buffer,"图像宽为:%ld 高为:%ld 像数位数:%d", dwWidth, dwHeight, wBitCount); MessageBox(buffer, "每个像素的位数", MB_OK | MB_ICONINFORMATION); f->Close(); delete f; delete rgb; }
BOOL CPreviewThread::Run() { ASSERT (m_pPartfile) ; CFile destFile; CFile srcFile; if (!srcFile.Open(m_pPartfile->GetFilePath(), CFile::modeRead | CFile::shareDenyNone)) return FALSE; try{ uint32 nSize = m_pPartfile->GetFileSize(); CString strExtension = CString(_tcsrchr(m_pPartfile->GetFileName(), _T('.'))); CString strPreviewName = m_pPartfile->GetTempPath() + _T("\\") + m_pPartfile->GetFileName().Mid(0, 5) + _T("_preview") + strExtension; bool bFullSized = true; if (!strExtension.CompareNoCase(_T(".mpg")) || !strExtension.CompareNoCase(_T(".mpeg"))) bFullSized = false; if (!destFile.Open(strPreviewName, CFile::modeWrite | CFile::shareDenyWrite | CFile::modeCreate)) return FALSE; srcFile.SeekToBegin(); if (bFullSized) destFile.SetLength(nSize); destFile.SeekToBegin(); BYTE abyBuffer[4096]; uint32 nRead; while (destFile.GetPosition()+4096 < PARTSIZE*2){ nRead = srcFile.Read(abyBuffer,4096); destFile.Write(abyBuffer,nRead); } srcFile.Seek(-(PARTSIZE*2),CFile::end); uint32 nToGo =PARTSIZE*2; if (bFullSized) destFile.Seek(-(PARTSIZE*2),CFile::end); do{ nRead = (nToGo - 4096 < 1)? nToGo:4096; nToGo -= nRead; nRead = srcFile.Read(abyBuffer,4096); destFile.Write(abyBuffer,nRead); } while (nToGo); destFile.Close(); srcFile.Close(); m_pPartfile->m_bPreviewing = false; SHELLEXECUTEINFO SE; MEMSET(&SE,0,sizeof(SE)); SE.fMask = SEE_MASK_NOCLOSEPROCESS ; SE.lpVerb = _T("open"); CString path; if (!m_player.IsEmpty()) { TCHAR shortPath[512]; //Cax2 short path for vlc GetShortPathName(strPreviewName, shortPath, ARRSIZE(shortPath)); path=thePrefs.GetVideoPlayer(); int pos = path.ReverseFind(_T('\\')); if (pos == -1) path.Empty(); else path = path.Left(pos + 1); SE.lpFile = m_player.GetBuffer(); SE.lpParameters=shortPath; SE.lpDirectory=path.GetBuffer(); } else SE.lpFile = strPreviewName.GetBuffer(); SE.nShow = SW_SHOW; SE.cbSize = sizeof(SE); ShellExecuteEx(&SE); if (SE.hProcess){ WaitForSingleObject(SE.hProcess, INFINITE); CloseHandle(SE.hProcess); } CFile::Remove(strPreviewName); } catch(CFileException* error){ m_pPartfile->m_bPreviewing = false; error->Delete(); } return TRUE; }
int CAPEv2Tag::fseek_callback(void *fp, long int offset, int whence) { CFile *file = (CFile *)fp; return (file->Seek(offset, whence) >= 0) ? 0 : -1; }
void CNameSearchDlg::OnDelete() { CString strid; int ret=0; CString strpath; CFile fidx; int bufsize = 0; TCHAR *pbuffMemo,*pbuff; int tcharlen = sizeof(TCHAR); LPTSTR pret = NULL; LPTSTR pend = NULL; TCHAR* pstr = NULL; //TCHAR strstorebuff[64]; int offlen = 0, reclen = 0; TCHAR buffid[16]; CString pSep = _T(" --- End --- "); CString p2tab = _T(" "); //tab CString rnend = _T(" "); //space memset(buffid,0,16 * sizeof(TCHAR)); ret = MessageBox(m_buffDelUserIDWarn,0, MB_YESNO); /// _T("Are you sure to delete this patient's record?"),0,MB_YESNO); if(ret == IDYES) { CString idpath; strpath = GetPTAResultLocalPath(); idpath = strpath; strpath = strpath + _T("idx.txt"); pid->GetWindowTextW(buffid,16); strid = buffid; idpath = idpath + strid; idpath += _T("\\"); DeleteIDfolder(idpath); fidx.Open(strpath,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite); ASSERT(fidx); ULONGLONG lens = fidx.GetLength(); bufsize = lens / tcharlen; if(lens) { pbuffMemo = new TCHAR [bufsize]; memset(pbuffMemo,0,bufsize*sizeof(TCHAR)); fidx.SeekToBegin(); fidx.Read(pbuffMemo,lens); pret = _tcsstr(pbuffMemo,strid); pend = _tcsstr(pret,pSep); if(pret == NULL) return; offlen = pret - pbuffMemo; reclen = pend - pret; pstr = new TCHAR [reclen-1]; //memset(pstr,0,(reclen-1) * sizeof(TCHAR)); //memset(pstr,' ',(reclen-1) * sizeof(TCHAR)); wmemset(pstr,_T(' '),(reclen-1)); //memset(pstr,_T(' '),(reclen-1) * sizeof(TCHAR)); pstr[reclen-1-1] = _T('\0'); pstr[reclen-1-2] = _T('\n'); pstr[reclen-1-3] = _T('\r'); int slen = 0; slen = _tcslen(pstr); fidx.Seek(offlen*sizeof(TCHAR),CFile::begin); fidx.Write(p2tab,_tcslen(p2tab) * tcharlen); fidx.Write(pstr,_tcslen(pstr) * tcharlen); //fidx.Write(rnend,_tcslen(rnend)*tcharlen); //fidx.Write(rnend,_tcslen(rnend)*tcharlen); //fidx.Write(rnend,_tcslen(rnend)*tcharlen); fidx.Close(); pid->DeleteString(selindex); pname->DeleteString(selindex); page->DeleteString(selindex); pgender->DeleteString(selindex); pid->SetCurSel(-1); pname->SetCurSel(-1); page->SetCurSel(-1); pgender->SetCurSel(-1); } } }
// Config Parser. Might drop this. bool CConfig::Parse(CFile& file, CString& sErrorMsg) { CString sLine; unsigned int uLineNum = 0; CConfig *pActiveConfig = this; std::stack<ConfigStackEntry> ConfigStack; bool bCommented = false; // support for /**/ style comments if (!file.Seek(0)) { sErrorMsg = "Could not seek to the beginning of the config."; return false; } while (file.ReadLine(sLine)) { uLineNum++; #define ERROR(arg) do { \ std::stringstream stream; \ stream << "Error on line " << uLineNum << ": " << arg; \ sErrorMsg = stream.str(); \ m_SubConfigs.clear(); \ m_ConfigEntries.clear(); \ return false; \ } while (0) // Remove all leading spaces and trailing line endings sLine.TrimLeft(); sLine.TrimRight("\r\n"); if (bCommented || sLine.Left(2) == "/*") { /* Does this comment end on the same line again? */ bCommented = (sLine.Right(2) != "*/"); continue; } if ((sLine.empty()) || (sLine[0] == '#') || (sLine.Left(2) == "//")) { continue; } if ((sLine.Left(1) == "<") && (sLine.Right(1) == ">")) { sLine.LeftChomp(); sLine.RightChomp(); sLine.Trim(); CString sTag = sLine.Token(0); CString sValue = sLine.Token(1, true); sTag.Trim(); sValue.Trim(); if (sTag.Left(1) == "/") { sTag = sTag.substr(1); if (!sValue.empty()) ERROR("Malformated closing tag. Expected \"</" << sTag << ">\"."); if (ConfigStack.empty()) ERROR("Closing tag \"" << sTag << "\" which is not open."); const struct ConfigStackEntry& entry = ConfigStack.top(); CConfig myConfig(entry.Config); CString sName(entry.sName); if (!sTag.Equals(entry.sTag)) ERROR("Closing tag \"" << sTag << "\" which is not open."); // This breaks entry ConfigStack.pop(); if (ConfigStack.empty()) pActiveConfig = this; else pActiveConfig = &ConfigStack.top().Config; SubConfig &conf = pActiveConfig->m_SubConfigs[sTag.AsLower()]; SubConfig::const_iterator it = conf.find(sName); if (it != conf.end()) ERROR("Duplicate entry for tag \"" << sTag << "\" name \"" << sName << "\"."); conf[sName] = CConfigEntry(myConfig); } else { if (sValue.empty()) ERROR("Empty block name at begin of block."); ConfigStack.push(ConfigStackEntry(sTag.AsLower(), sValue)); pActiveConfig = &ConfigStack.top().Config; } continue; } // If we have a regular line, figure out where it goes CString sName = sLine.Token(0, false, "="); CString sValue = sLine.Token(1, true, "="); // Only remove the first space, people might want // leading spaces (e.g. in the MOTD). if (sValue.Left(1) == " ") sValue.LeftChomp(); // We don't have any names with spaces, trim all // leading/trailing spaces. sName.Trim(); if (sName.empty() || sValue.empty()) ERROR("Malformed line"); CString sNameLower = sName.AsLower(); pActiveConfig->m_ConfigEntries[sNameLower].push_back(sValue); } if (bCommented) ERROR("Comment not closed at end of file."); if (!ConfigStack.empty()) { const CString& sTag = ConfigStack.top().sTag; ERROR("Not all tags are closed at the end of the file. Inner-most open tag is \"" << sTag << "\"."); } return true; }
void ModEncrypt::VerifyEncryptFile(/*CString& strPassWord*/) { char *szPassWord=NULL; char *MP=NULL; char *EP=NULL; char *EP1=NULL; try { long i=0,iPos=0; char tmp; // a$ // bTmp String * 1 CFile f; DWORD lngEP,lngMP; if(!f.Open(user::gstrWinDir+FilejmBASE1,CFile::modeRead)) return; //开始字符串长度 f.SeekToBegin(); f.Read(&lngMP,sizeof(lngMP)); MP=new char[lngMP+1]; f.Read(MP,lngMP); MP[lngMP]='\0'; //然后是密码长度 f.Read(& lngEP,sizeof(lngEP)); f.Read(& glngLimitedDemoVersionDays,sizeof(DWORD)); f.Read(& gLngSavedMicroDogID,sizeof(DWORD)); f.Read(& gLngVersionID,sizeof(DWORD)); f.Read(& glngVersion,sizeof(glngVersion)); EP=new char[lngEP+1]; f.Read(EP,lngEP); EP[lngEP]='\0'; f.Close(); //if(strPassWord=="") { if(!f.Open(user::gstrWinDir + FilePsw,CFile::modeRead)) goto FunOut; int len=f.GetLength(); len-=16; f.Seek(16,CFile::begin); szPassWord=new char[len+1]; f.Read(szPassWord,len); szPassWord[len]='\0'; f.Close(); } //MP.ReleaseBuffer(); //EP.ReleaseBuffer(); //strPassWord.ReleaseBuffer(); int passlen=strlen(szPassWord); EP1=new char [passlen+1]; for( i = 0 ; i<passlen;i++) { tmp=szPassWord[i]; if( '0' <= tmp && tmp <='9' ){ iPos = tmp - '0' + 2; }else if( 'A' <= tmp && tmp <= 'Z' ){ iPos = tmp - 'A' + 12; } else if('a' <= tmp && tmp <= 'z' ){ iPos = tmp - 'a' + 12; } EP1[i]=(char)MP[iPos-1]; //MsgBox EP1 } EP1[i]='\0'; if( strcmp(EP1, EP)==0 ) { EncryptCompanyName(szPassWord, true); //EncryptCompanyName(strPassWord, false); /*#if DebugMode = -1 ){ //MsgBox "你是合法用户!" #endif*/ if( gLngVersionID == 1236 && glngVersion == glngAppVersion ){ //标准版标志 gbLegalUser = true; }else{ gbLegalUser = false; } if( FileExists(user::gstrWinDir + FileOutDate) ) ::DeleteFile( user::gstrWinDir + FileOutDate); if( FileExists(user::gstrWinDir + FileFlag) ) ::DeleteFile( user::gstrWinDir + FileFlag); if(!f.Open(user::gstrWinDir+FileFlag,CFile::modeWrite|CFile::modeCreate)) goto FunOut; lngEP = 1234; f.Write(&lngEP,sizeof(DWORD)); f.Close(); SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileFlag); } else { //MsgBox "你是非法用户!" gstrLegalCompanyName = GetResStr(IDS_YouAreIllegalUser); gLngVersionID=0; gbLegalUser = false; } } catch(CFileException * e) { e->ReportError(); e->Delete(); } FunOut: delete [] szPassWord; delete [] MP; delete [] EP; delete [] EP1; }
RET_VAL ConnectionLimit::IsVistaPatched(LPCTSTR path) { UnlockFile("c:\\windows\\system32\\drivers\\vga.sys"); CFile file; DWORD dwOffset = 0; bool isWow = IsWow64(); PVOID oldValue = NULL; if(isWow) { MyWow64DisableWow64FsRedirection(&oldValue); } if(file.Open(path,CFile::modeRead)) { TCHAR patchedChar = 0x90; if(isWow) { MyWow64RevertWow64FsRedirection(oldValue); } unsigned int bytesRead = 0; TCHAR buffer[1024]; bytesRead = file.Read(buffer, 1024); while(bytesRead != 0) { for (int i = 0; i<bytesRead; ++i) { if(!isWow) { if(buffer[i] == VISTA_MAGIC_32[0]) { if(i>= (bytesRead - 8)) { int pos = file.GetPosition(); file.Seek(-8, CFile::current); bytesRead-=8; pos = file.GetPosition(); break; } for (int c = 1; c < 9; ++c) { if(buffer[i+c] != VISTA_MAGIC_32[c]) { break; } else { if(c == 8) { dwOffset += i + 9; bool patched = true; for(int p = 0; p < 6; ++p) { if(buffer[i+9+p] != patchedChar) patched = false; } file.Close(); if(patched) return RET_YES; else return RET_NO; //return dwOffset; } } } } } else { if(buffer[i] == MAGIC_64[0]) { if(i>= (bytesRead - 24)) { int pos = file.GetPosition(); file.Seek(-24, CFile::current); bytesRead-=24; pos = file.GetPosition(); break; } for (int c = 1; c < 24; ++c) { if(buffer[i+c] != MAGIC_64[c]) { break; } else { if(c == 23) { dwOffset += i + 50; file.Close(); //return dwOffset; } } } } } } dwOffset += bytesRead; bytesRead = file.Read(buffer, 1024); } file.Close(); } return RET_ERROR; }
int CSubModel::Read (CFile& cf, CModel* po, int bFlipV) { int h, i; #if OOF_MEM_OPT int bReadData, nPos, nFaceVerts = 0; #endif char szId [20] = ""; nIndent += 2; OOF_PrintLog ("reading submodel\n"); Init (); m_nIndex = OOF_ReadInt (cf, "nIndex"); if (m_nIndex >= OOF_MAX_SUBOBJECTS) { nIndent -= 2; return 0; } m_nParent = OOF_ReadInt (cf, "nParent"); OOF_ReadVector (cf, &m_vNormal, "vNormal"); m_fd = OOF_ReadFloat (cf, "fd"); OOF_ReadVector (cf, &m_vPlaneVert, "vPlaneVert"); OOF_ReadVector (cf, &m_vOffset, "vOffset"); m_fRadius = OOF_ReadFloat (cf, "fRadius"); m_nTreeOffset = OOF_ReadInt (cf, "nTreeOffset"); m_nDataOffset = OOF_ReadInt (cf, "nDataOffset"); if (po->m_nVersion > 1805) OOF_ReadVector (cf, &m_vCenter, "vCenter"); if (!(m_pszName = OOF_ReadString (cf, "pszName"))) { Destroy (); return 0; } if (!(m_pszProps = OOF_ReadString (cf, "pszProps"))) { Destroy (); return 0; } SetProps (m_pszProps); m_nMovementType = OOF_ReadInt (cf, "nMovementType"); m_nMovementAxis = OOF_ReadInt (cf, "nMovementAxis"); m_fsLists = NULL; if ((m_nFSLists = OOF_ReadInt (cf, "nFSLists"))) cf.Seek (m_nFSLists * sizeof (int), SEEK_CUR); m_nVerts = OOF_ReadInt (cf, "nVerts"); if (m_nVerts) { if (!OOF_ReadVertList (cf, m_verts, m_nVerts, &m_vMin, &m_vMax)) { Destroy (); nIndent -= 2; return 0; } m_vCenter = (m_vMin + m_vMax) / 2.0f; if (!m_rotVerts.Create (m_nVerts)) { Destroy (); nIndent -= 2; return 0; } if (!m_vertColors.Create (m_nVerts)) { Destroy (); nIndent -= 2; return 0; } m_vertColors.Clear (0); if (!(OOF_ReadVertList (cf, m_normals, m_nVerts, NULL, NULL))) { nIndent -= 2; Destroy (); return 0; } if (!m_pfAlpha.Create (m_nVerts)) { Destroy (); nIndent -= 2; return 0; } for (i = 0; i < m_nVerts; i++) if (po->m_nVersion < 2300) m_pfAlpha [i] = 1.0f; else { if (bLogOOF) sprintf (szId, "pfAlpha [%d]", i); m_pfAlpha [i] = OOF_ReadFloat (cf, szId); if (m_pfAlpha [i] < 0.99) po->m_nFlags |= OOF_PMF_ALPHA; } } m_faces.m_nFaces = OOF_ReadInt (cf, "nFaces"); if (!m_faces.m_list.Create (m_faces.m_nFaces)) { Destroy (); nIndent -= 2; return 0; } #if OOF_MEM_OPT nPos = cf.Tell (); m_edges.m_nEdges = 0; for (bReadData = 0; bReadData < 2; bReadData++) { cf.Seek (nPos, SEEK_SET); if (bReadData) { if (!m_faces.m_verts.Create (nFaceVerts)) { Destroy (); nIndent -= 2; return 0; } if (!m_edges.m_list.Create (nFaceVerts)) { Destroy (); nIndent -= 2; return 0; } m_edges.m_list.Clear (); m_edges.m_nEdges = 0; } for (i = 0, nFaceVerts = 0; i < m_faces.m_nFaces; i++) { if (!(h = m_faces.m_list [i].Read (cf, this, bReadData ? m_faces.m_verts + nFaceVerts : NULL, bFlipV))) { Destroy (); nIndent -= 2; return 0; } nFaceVerts += h; } } #else for (i = 0; i < m_faces.m_nFaces; i++) if (!OOF_ReadFace (cf, &so, m_faces.faces + i, NULL, bFlipV)) { nIndent -= 2; Destroy (); return 0; } #endif nIndent -= 2; return 1; }
BOOL CWindowsMetaFile::GetMetaFile(LPCSTR pszFileName, ALDUS_WMF_HEADER* pAldusHeader, METAHEADER* pHeader, HMETAFILE* phMetaFile) { BOOL fSuccess = FALSE; ASSERT(pszFileName != NULL); // Create the file we will be using. CFile File; // Attempt to open the file. if (File.Open(pszFileName, CFile::modeRead | CFile::shareDenyWrite)) { ALDUS_WMF_HEADER AldusHeader; // Read the Aldus header. if (File.Read(&AldusHeader, sizeof(AldusHeader)) == sizeof(AldusHeader)) { // Save the Aldus header if the user has requested it. if (pAldusHeader != NULL) { *pAldusHeader = AldusHeader; } // Validate the header. if (AldusHeader.key == ALDUS_WMF_KEY) { // If the user has only requested the Aldus header, stop and return TRUE. fSuccess = (pHeader == NULL) && (phMetaFile == NULL); if (!fSuccess) { // Read the metafile header. METAHEADER Header; DWORD dwPosition = File.GetPosition(); if (File.Read(&Header, sizeof(Header)) == sizeof(Header)) { // Save the metafile header if the user has requested it. if (pHeader != NULL) { *pHeader = Header; } // If the user does not want a metafile handle, stop and return TRUE. fSuccess = phMetaFile == NULL; if (!fSuccess) { *phMetaFile = NULL; // Get the size from the metafile header. DWORD dwSize = Header.mtSize*2; if (dwSize != 0) { // Allocate the memory to hold the metafile data. HGLOBAL hMetaFileData; hMetaFileData = GlobalAlloc(GMEM_MOVEABLE|GMEM_SHARE, dwSize); if (hMetaFileData != NULL) { LPVOID pMetaFileData; pMetaFileData = GlobalLock(hMetaFileData); if (pMetaFileData != NULL) { // Seek back to the start of the metafile header. File.Seek(dwPosition, CFile::begin); // Read the metafile data. if (File.ReadHuge(pMetaFileData, dwSize) == dwSize) { // We have now read the data, make a metafile from it. #ifdef WIN32 *phMetaFile = ::SetMetaFileBitsEx(dwSize, (LPBYTE)pMetaFileData); #else *phMetaFile = ::SetMetaFileBits(hMetaFileData); #endif fSuccess = *phMetaFile != NULL; } #ifdef WIN32 GlobalUnlock(hMetaFileData); pMetaFileData = NULL; #else if (*phMetaFile == NULL) { GlobalUnlock(hMetaFileData); pMetaFileData = NULL; } #endif } #ifdef WIN32 GlobalFree(hMetaFileData); hMetaFileData = NULL; #else if (*phMetaFile == NULL) { GlobalFree(hMetaFileData); hMetaFileData = NULL; } #endif } } } } } } } } return fSuccess; }
int CModel::Read (char *filename, short nModel, int bFlipV, int bCustom) { if (m_nModel >= 0) return 0; CFile cf; char fileId [4]; int i, nLength, nFrames, nSubModels, bTimed = 0; bLogOOF = (fErr != NULL) && FindArg ("-printoof"); nIndent = 0; OOF_PrintLog ("\nreading %s/%s\n", gameFolders.szModelDir [bCustom], filename); if (!(*filename && cf.Open (filename, gameFolders.szModelDir [bCustom], "rb", 0))) { OOF_PrintLog (" file not found"); return 0; } if (!cf.Read (fileId, sizeof (fileId), 1)) { OOF_PrintLog (" invalid file id\n"); cf.Close (); return 0; } if (strncmp (fileId, "PSPO", 4)) { OOF_PrintLog (" invalid file id\n"); cf.Close (); return 0; } Init (); m_nModel = nModel; m_bCustom = bCustom; m_nVersion = OOF_ReadInt (cf, "nVersion"); if (m_nVersion >= 2100) m_nFlags |= OOF_PMF_LIGHTMAP_RES; if (m_nVersion >= 22) { bTimed = 1; m_nFlags |= OOF_PMF_TIMED; m_frameInfo.m_nFirstFrame = 0; m_frameInfo.m_nLastFrame = 0; } nSubModels = 0; while (!cf.EoF ()) { char chunkID [4]; if (!cf.Read (chunkID, sizeof (chunkID), 1)) { cf.Close (); return 0; } OOF_PrintLog (" chunkID = '%c%c%c%c'\n", chunkID [0], chunkID [1], chunkID [2], chunkID [3]); nLength = OOF_ReadInt (cf, "nLength"); switch (ListType (chunkID)) { case 0: if (!ReadTextures (cf)) { Destroy (); return 0; } break; case 1: if (!ReadInfo (cf)) { Destroy (); return 0; } break; case 2: if (!m_subModels [nSubModels].Read (cf, this, bFlipV)) { Destroy (); return 0; } nSubModels++; break; case 3: if (!m_gunPoints.Read (cf, m_nVersion >= 1908, MAX_GUNS)) { Destroy (); return 0; } break; case 4: if (!m_specialPoints.Read (cf)) { Destroy (); return 0; } break; case 5: if (!m_attachPoints.Read (cf)) { Destroy (); return 0; } break; case 6: nFrames = m_frameInfo.m_nFrames; if (!bTimed) m_frameInfo.m_nFrames = OOF_ReadInt (cf, "nFrames"); for (i = 0; i < m_nSubModels; i++) if (!m_subModels [i].m_posAnim.Read (cf, this, bTimed)) { Destroy (); return 0; } if (m_frameInfo.m_nFrames < nFrames) m_frameInfo.m_nFrames = nFrames; break; case 7: case 8: nFrames = m_frameInfo.m_nFrames; if (!bTimed) m_frameInfo.m_nFrames = OOF_ReadInt (cf, "nFrames"); for (i = 0; i < m_nSubModels; i++) if (!m_subModels [i].m_rotAnim.Read (cf, this, bTimed)) { Destroy (); return 0; } if (m_frameInfo.m_nFrames < nFrames) m_frameInfo.m_nFrames = nFrames; break; case 9: if (!m_armament.Read (cf)) { Destroy (); return 0; } break; case 10: if (!m_attachPoints.ReadNormals (cf)) { Destroy (); return 0; } break; default: cf.Seek (nLength, SEEK_CUR); break; } } cf.Close (); ConfigureSubModels (); BuildAnimMatrices (); AssignChildren (); LinkBatteries (); BuildPosTickRemapList (); BuildRotTickRemapList (); gameData.models.bHaveHiresModel [this - gameData.models.oofModels [bCustom != 0].Buffer ()] = 1; return 1; }