1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
void CPropPgFormDoc::OnAddCrc(LPCTSTR lpszPathName)
{ //calcul the cRC of the file Spath
CFileException fe;
CFile* pFile = NULL;
CString sPath = lpszPathName;
CString sCRC;
// static char BASED_CODE szFilter[] = "Patch Files (*.fdw)|*.fdw|All Files (*.*)|*.*||";
BYTE ser_data;
WORD CRC, tmp,i;
static DWORD CrcTabReady=0;
static CrcTab[512];
CRC=0xFFFF;
pFile = GetFile(sPath,
CFile::modeReadWrite | CFile::shareExclusive, &fe);
int nLgFile = 0;
nLgFile = pFile->GetLength();
BYTE* lpPatchFile = new BYTE[nLgFile];
BYTE* lpStartPatchFile = lpPatchFile;
pFile->Read(lpPatchFile, nLgFile);
if(CrcTabReady==0){
for(i=0;i<512;i++){
tmp=0;
if((i&1)!=0) tmp=(tmp^0x1021);
if((i&2)!=0) tmp=(tmp^0x2042);
if((i&4)!=0) tmp=(tmp^0x4084);
if((i&8)!=0) tmp=(tmp^0x8108);
if((i&16)!=0) tmp=(tmp^0x1231);
if((i&32)!=0) tmp=(tmp^0x2462);
if((i&64)!=0) tmp=(tmp^0x48C4);
if((i&128)!=0) tmp=(tmp^0x9188);
CrcTab[i]=tmp;
}
CrcTabReady=1;
}
nLgFile -= 2;
lpPatchFile += 2;
while(nLgFile--) CRC=((CRC << 8)^CrcTab[(CRC>>8)^*lpPatchFile++]);
pFile->SeekToBegin();
pFile->Write(&CRC,2);
pFile->Close();
/* CWaitCursor waitCursor;
AfxMessageBox("BBy Factory Settings + CRC saved successfully",
MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
*/
delete [] lpStartPatchFile;
} |