示例#1
0
  void Process2()
  {
    // NCOM::CComInitializer comInitializer;
    ProgressDialog->WaitCreating();

    CVolSeqName volSeqName;
    if (!volSeqName.ParseName(FirstVolumeName))
      throw L"Can not detect file as splitted file";

    UString nextName = InputDirPrefix + FirstVolumeName;
    UInt64 totalSize = 0;
    for (;;)
    {
      NFile::NFind::CFileInfoW fileInfo;
      if (!NFile::NFind::FindFile(nextName, fileInfo))
        break;
      if (fileInfo.IsDirectory())
        break;
      totalSize += fileInfo.Size;
      nextName = InputDirPrefix + volSeqName.GetNextName();
    }
    if (totalSize == 0)
      throw L"no data";
    ProgressDialog->ProgressSynch.SetProgress(totalSize, 0);

    if (!volSeqName.ParseName(FirstVolumeName))
      throw L"Can not detect file as splitted file";

    UString outName = volSeqName.UnchangedPart;
    while(!outName.IsEmpty())
    {
      int lastIndex = outName.Length() - 1;
      if (outName[lastIndex] != L'.')
        break;
      outName.Delete(lastIndex);
    }
    if (outName.IsEmpty())
      outName = L"file";
    NFile::NIO::COutFile outFile;
    if (!outFile.Create(OutputDirPrefix + outName, false))
      throw L"Can create open output file";

    NFile::NIO::CInFile inFile;
    CMyBuffer bufferObject;
    if (!bufferObject.Allocate(kBufSize))
      throw L"Can not allocate buffer";
    Byte *buffer = (Byte *)(void *)bufferObject;
    UInt64 pos = 0;
    nextName = InputDirPrefix + FirstVolumeName;
    bool needOpen = true;
    for (;;)
    {
      if (needOpen)
      {
        NFile::NFind::CFileInfoW fileInfo;
        if (!NFile::NFind::FindFile(nextName, fileInfo))
          break;
        if (fileInfo.IsDirectory())
          break;
        if (!inFile.Open(nextName))
          throw L"Can not open file";
        ProgressDialog->ProgressSynch.SetCurrentFileName(fileInfo.Name);
        nextName = InputDirPrefix + volSeqName.GetNextName();
        needOpen = false;
      }
      UInt32 processedSize;
      if (!inFile.Read(buffer, kBufSize, processedSize))
        throw L"Can not read input file";
      if (processedSize == 0)
      {
        needOpen = true;
        continue;
      }
      UInt32 needSize = processedSize;
      if (!outFile.Write(buffer, needSize, processedSize))
        throw L"Can not write output file";
      if (needSize != processedSize)
        throw L"Can not write output file";
      pos += processedSize;
      HRESULT res = ProgressDialog->ProgressSynch.SetPosAndCheckPaused(pos);
      if (res != S_OK)
        return;
    }
  }
示例#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;
    }
  }