/////////////////////////////////////////////////////////////////////
| 309 | |
| 310 | ////////////////////////////////////////////////////////////////////////// |
| 311 | bool CDataProbe::GetCode( SDataProbeContext &ctx ) |
| 312 | { |
| 313 | if (ctx.nSize <= 0) |
| 314 | return false; |
| 315 | |
| 316 | if (ctx.pBuffer) |
| 317 | { |
| 318 | return GetDataCode( (char*)ctx.pBuffer,ctx.nSize,ctx ); |
| 319 | } |
| 320 | |
| 321 | // Try to open file and hash it. |
| 322 | FILE *file = fopen( ctx.sFilename.c_str(),"rb" ); |
| 323 | if (file) |
| 324 | { |
| 325 | fseek( file,0,SEEK_END ); |
| 326 | unsigned int nFileSize = ftell(file); |
| 327 | if (ctx.nOffset >= nFileSize) |
| 328 | { |
| 329 | fclose(file); |
| 330 | return false; |
| 331 | } |
| 332 | ctx.nSize = min( ctx.nSize,nFileSize-ctx.nOffset ); |
| 333 | |
| 334 | if (fseek( file,ctx.nOffset,SEEK_SET ) != 0) |
| 335 | { |
| 336 | fclose( file ); |
| 337 | return false; |
| 338 | } |
| 339 | char *pBuf = (char*)malloc( ctx.nSize ); |
| 340 | if (fread( pBuf,ctx.nSize,1,file ) != 1) |
| 341 | { |
| 342 | free( pBuf ); |
| 343 | fclose(file); |
| 344 | return false; |
| 345 | } |
| 346 | |
| 347 | // Hash readed data with choosen algorithm, store result into 64bit nCode. |
| 348 | bool bOk = GetDataCode( pBuf,ctx.nSize,ctx ); |
| 349 | |
| 350 | free( pBuf ); |
| 351 | fclose(file); |
| 352 | |
| 353 | return bOk; |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | // Real file on disk not found... so check against one in the pak. |
| 358 | // Try to open file and hash it. |
| 359 | CCryFile cryfile; |
| 360 | if (cryfile.Open( ctx.sFilename.c_str(),"rb" )) |
| 361 | { |
| 362 | unsigned int nFileSize = cryfile.GetLength(); |
| 363 | if (ctx.nOffset >= nFileSize) |
| 364 | { |
| 365 | return false; |
| 366 | } |
| 367 | ctx.nSize = min( ctx.nSize,nFileSize-ctx.nOffset ); |
| 368 |
no test coverage detected