~ubuntu-branches/ubuntu/vivid/unrar-nonfree/vivid

« back to all changes in this revision

Viewing changes to rdwrfn.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2015-02-03 12:58:01 UTC
  • mfrom: (1.1.18) (5.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20150203125801-od6ev8cqy1er51vz
Tags: 1:5.2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
  // block size. We can do it by simple masking, because unpack read code
45
45
  // always reads more than CRYPT_BLOCK_SIZE, so we do not risk to make it 0.
46
46
  if (Decryption)
47
 
    Count&=~CRYPT_BLOCK_MASK;
 
47
    Count &= ~CRYPT_BLOCK_MASK;
48
48
#endif
 
49
  
49
50
  int ReadSize=0,TotalRead=0;
50
51
  byte *ReadAddr;
51
52
  ReadAddr=Addr;
62
63
    else
63
64
    {
64
65
      size_t SizeToRead=((int64)Count>UnpPackedSize) ? (size_t)UnpPackedSize:Count;
65
 
      if (SizeToRead==0)
66
 
        return 0;
67
 
      if (!SrcFile->IsOpened())
68
 
        return(-1);
69
 
      ReadSize=SrcFile->Read(ReadAddr,SizeToRead);
70
 
      FileHeader *hd=SubHead!=NULL ? SubHead:&SrcArc->FileHead;
71
 
      if (hd->SplitAfter)
72
 
        PackedDataHash.Update(ReadAddr,ReadSize);
 
66
      if (SizeToRead > 0)
 
67
      {
 
68
        if (UnpVolume && Decryption && (int64)Count>UnpPackedSize)
 
69
        {
 
70
          // We need aligned blocks for decryption and we want "Keep broken
 
71
          // files" to work efficiently with missing encrypted volumes.
 
72
          // So for last data block in volume we adjust the size to read to
 
73
          // next equal or smaller block producing aligned total block size.
 
74
          // So we'll ask for next volume only when processing few unaligned
 
75
          // bytes left in the end, when most of data is already extracted.
 
76
          size_t NewTotalRead = TotalRead + SizeToRead;
 
77
          size_t Adjust = NewTotalRead - (NewTotalRead  & ~CRYPT_BLOCK_MASK);
 
78
          size_t NewSizeToRead = SizeToRead - Adjust;
 
79
          if ((int)NewSizeToRead > 0)
 
80
            SizeToRead = NewSizeToRead;
 
81
        }
 
82
 
 
83
        if (!SrcFile->IsOpened())
 
84
          return -1;
 
85
        ReadSize=SrcFile->Read(ReadAddr,SizeToRead);
 
86
        FileHeader *hd=SubHead!=NULL ? SubHead:&SrcArc->FileHead;
 
87
        if (hd->SplitAfter)
 
88
          PackedDataHash.Update(ReadAddr,ReadSize);
 
89
      }
73
90
    }
74
91
    CurUnpRead+=ReadSize;
75
92
    TotalRead+=ReadSize;
80
97
    Count-=ReadSize;
81
98
#endif
82
99
    UnpPackedSize-=ReadSize;
83
 
    if (UnpPackedSize == 0 && UnpVolume)
 
100
 
 
101
    // Do not ask for next volume if we read something from current volume.
 
102
    // If next volume is missing, we need to process all data from current
 
103
    // volume before aborting. It helps to recover all possible data
 
104
    // in "Keep broken files" mode. But if we process encrypted data,
 
105
    // we ask for next volume also if we have non-aligned encryption block.
 
106
    // Since we adjust data size for decryption earlier above,
 
107
    // it does not hurt "Keep broken files" mode efficiency.
 
108
    if (UnpVolume && UnpPackedSize == 0 && 
 
109
        (ReadSize==0 || Decryption && (TotalRead & CRYPT_BLOCK_MASK) != 0) )
84
110
    {
85
111
#ifndef NOVOLUME
86
112
      if (!MergeArchive(*SrcArc,this,true,CurrentCommand))
87
113
#endif
88
114
      {
89
115
        NextVolumeMissing=true;
90
 
        return(-1);
 
116
        return -1;
91
117
      }
92
118
    }
93
119
    else
204
230
    int CurPercent=ToPercent(ArcPos,ArcSize);
205
231
    if (!Cmd->DisablePercentage && CurPercent!=LastPercent)
206
232
    {
207
 
      mprintf(L"\b\b\b\b%3d%%",CurPercent);
 
233
      uiExtractProgress(CurUnpWrite,SrcArc->FileHead.UnpSize,ArcPos,ArcSize);
208
234
      LastPercent=CurPercent;
209
235
    }
210
236
  }
280
306
  UnpackToMemoryAddr=Addr;
281
307
  UnpackToMemorySize=Size;
282
308
}
283
 
 
284