HRESULT CThreadSplit::ProcessVirt()
{
  NFile::NIO::CInFile inFile;
  if (!inFile.Open(FilePath))
    return GetLastError();
  NFile::NIO::COutFile outFile;
  CMyBuffer bufferObject;
  if (!bufferObject.Allocate(kBufSize))
    return E_OUTOFMEMORY;
  Byte *buffer = (Byte *)(void *)bufferObject;
  UInt64 curVolSize = 0;
  CVolSeqName seqName;
  seqName.SetNumDigits(NumVolumes);
  UInt64 length;
  if (!inFile.GetLength(length))
    return GetLastError();
  
  CProgressSync &sync = ProgressDialog.Sync;
  sync.SetProgress(length, 0);
  UInt64 pos = 0;
  
  UInt64 numFiles = 0;
  int volIndex = 0;
  
  for (;;)
  {
    UInt64 volSize;
    if (volIndex < VolumeSizes.Size())
      volSize = VolumeSizes[volIndex];
    else
      volSize = VolumeSizes.Back();
    
    UInt32 needSize = (UInt32)(MyMin((UInt64)kBufSize, volSize - curVolSize));
    UInt32 processedSize;
    if (!inFile.Read(buffer, needSize, processedSize))
      return GetLastError();
    if (processedSize == 0)
      break;
    needSize = processedSize;
    if (curVolSize == 0)
    {
      UString name = VolBasePath;
      name += L'.';
      name += seqName.GetNextName();
      sync.SetCurrentFileName(name);
      sync.SetNumFilesCur(numFiles++);
      if (!outFile.Create(name, false))
      {
        HRESULT res = GetLastError();
        ErrorPath1 = name;
        return res;
      }
    }
    if (!outFile.Write(buffer, needSize, processedSize))
      return GetLastError();
    if (needSize != processedSize)
      throw g_Message_FileWriteError;
    curVolSize += processedSize;
    if (curVolSize == volSize)
    {
      outFile.Close();
      if (volIndex < VolumeSizes.Size())
        volIndex++;
      curVolSize = 0;
    }
    pos += processedSize;
    RINOK(sync.SetPosAndCheckPaused(pos));
  }
  sync.SetNumFilesCur(numFiles);
  return S_OK;
}
Exemple #2
0
  void Process2()
  {
    // NCOM::CComInitializer comInitializer;
    ProgressDialog->WaitCreating();
    NFile::NIO::CInFile inFile;
    if (!inFile.Open(FilePath))
      throw L"Can not open file";
    NFile::NIO::COutFile outFile;
    CMyBuffer bufferObject;
    if (!bufferObject.Allocate(kBufSize))
      throw L"Can not allocate buffer";
    Byte *buffer = (Byte *)(void *)bufferObject;
    UInt64 curVolSize = 0;
    CVolSeqName seqName;
    UInt64 length;
    if (!inFile.GetLength(length))
      throw "error";

    ProgressDialog->ProgressSynch.SetProgress(length, 0);
    UInt64 pos = 0;

    int volIndex = 0;

    for (;;)
    {
      UInt64 volSize;
      if (volIndex < VolumeSizes.Size())
        volSize = VolumeSizes[volIndex];
      else
        volSize = VolumeSizes.Back();

      UInt32 needSize = (UInt32)(MyMin((UInt64)kBufSize, volSize - curVolSize));
      UInt32 processedSize;
      if (!inFile.Read(buffer, needSize, processedSize))
        throw L"Can not read input file";
      if (processedSize == 0)
        break;
      needSize = processedSize;
      if (curVolSize == 0)
      {
        UString name = VolBasePath;
        name += L".";
        name += seqName.GetNextName();
        if (!outFile.Create(name, false))
          throw L"Can not create output file";
        ProgressDialog->ProgressSynch.SetCurrentFileName(name);
      }
      if (!outFile.Write(buffer, needSize, processedSize))
        throw L"Can not write output file";
      if (needSize != processedSize)
        throw L"Can not write output file";
      curVolSize += processedSize;
      if (curVolSize == volSize)
      {
        outFile.Close();
        if (volIndex < VolumeSizes.Size())
          volIndex++;
        curVolSize = 0;
      }
      pos += processedSize;
      HRESULT res = ProgressDialog->ProgressSynch.SetPosAndCheckPaused(pos);
      if (res != S_OK)
        return;
    }
  }