/lib/UnrarXLib/rawread.cpp

http://github.com/xbmc/xbmc · C++ · 101 lines · 82 code · 19 blank · 0 comment · 5 complexity · 3681605375f51d8abe36b5a8e891ebd1 MD5 · raw file

  1. #include "rar.hpp"
  2. RawRead::RawRead(File *SrcFile)
  3. {
  4. RawRead::SrcFile=SrcFile;
  5. ReadPos=0;
  6. DataSize=0;
  7. #ifndef SHELL_EXT
  8. Crypt=NULL;
  9. #endif
  10. }
  11. void RawRead::Read(int Size)
  12. {
  13. #if !defined(SHELL_EXT) && !defined(NOCRYPT)
  14. if (Crypt!=NULL)
  15. {
  16. int CurSize=Data.Size();
  17. int SizeToRead=Size-(CurSize-DataSize);
  18. if (SizeToRead>0)
  19. {
  20. int AlignedReadSize=SizeToRead+((~SizeToRead+1)&0xf);
  21. Data.Add(AlignedReadSize);
  22. int ReadSize=SrcFile->Read(&Data[CurSize],AlignedReadSize);
  23. Crypt->DecryptBlock(&Data[CurSize],AlignedReadSize);
  24. DataSize+=ReadSize==0 ? 0:Size;
  25. }
  26. else
  27. DataSize+=Size;
  28. }
  29. else
  30. #endif
  31. if (Size!=0)
  32. {
  33. Data.Add(Size);
  34. DataSize+=SrcFile->Read(&Data[DataSize],Size);
  35. }
  36. }
  37. void RawRead::Read(byte *SrcData,int Size)
  38. {
  39. if (Size!=0)
  40. {
  41. Data.Add(Size);
  42. memcpy(&Data[DataSize],SrcData,Size);
  43. DataSize+=Size;
  44. }
  45. }
  46. void RawRead::Get(byte &Field)
  47. {
  48. Field=Data[ReadPos];
  49. ReadPos++;
  50. }
  51. void RawRead::Get(ushort &Field)
  52. {
  53. Field=Data[ReadPos]+(Data[ReadPos+1]<<8);
  54. ReadPos+=2;
  55. }
  56. void RawRead::Get(uint &Field)
  57. {
  58. Field=Data[ReadPos]+(Data[ReadPos+1]<<8)+(Data[ReadPos+2]<<16)+
  59. (Data[ReadPos+3]<<24);
  60. ReadPos+=4;
  61. }
  62. void RawRead::Get8(Int64 &Field)
  63. {
  64. uint Low,High;
  65. Get(Low);
  66. Get(High);
  67. Field=int32to64(High,Low);
  68. }
  69. void RawRead::Get(byte *Field,int Size)
  70. {
  71. memcpy(Field,&Data[ReadPos],Size);
  72. ReadPos+=Size;
  73. }
  74. void RawRead::Get(wchar *Field,int Size)
  75. {
  76. RawToWide(&Data[ReadPos],Field,Size);
  77. ReadPos+=2*Size;
  78. }
  79. uint RawRead::GetCRC(bool ProcessedOnly)
  80. {
  81. return(DataSize>2 ? CRC(0xffffffff,&Data[2],(ProcessedOnly ? ReadPos:DataSize)-2):0xffffffff);
  82. }