Ejemplo n.º 1
0
 public void Cut(string mFilePath, List <FilePiece> mQueeue)
 {
     using (var reader = new FileStream(mFilePath, FileMode.Open, FileAccess.Read))
     {
         var  counter = 0;
         long oldPs   = 0;
         while (reader.Position < reader.Length)
         {
             var buffer = new byte[8];
             //читаем заголовок файла
             reader.Read(buffer, 0, 8);
             //выбираем из прочитанного размер блока
             var compressedBlockLength = BitConverter.ToInt32(buffer, 4);
             //Console.WriteLine(compressedBlockLength);
             var comressedBytes = new byte[compressedBlockLength + 1];
             buffer.CopyTo(comressedBytes, 0);
             reader.Read(comressedBytes, 8, compressedBlockLength - 8);
             var blockSize         = BitConverter.ToInt32(comressedBytes, compressedBlockLength - 4);
             var decompressedBytes = ProcessUnPacking.ProcessArchive(comressedBytes, blockSize);
             mQueeue.Add(new FilePiece(counter, decompressedBytes));
             counter++;
             long ps = reader.Position * 100 / reader.Length;
             if (ps != oldPs)
             {
                 oldPs = ps;
                 NotifyProgress?.Invoke(ps.ToString());
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void CutPath(object o)
        {
            // индекс потока
            int index  = (int)o;
            var inList = m_AnchorListThread[index];

            // файл, чтобы складывать все с потока
            var filePath     = AppPropertiesSingle.GetInstance().TempPath;
            var tempFileName = index + Path.GetRandomFileName();

            filePath = Path.Combine(filePath, tempFileName);

            using (var reader = new FileStream(m_FilePath, FileMode.Open, FileAccess.Read))
            {
                // для расчета прогресса
                long counter = 0;
                long oldPs   = 0;

                // создаем файлик для записи
                using (var bw = new BinaryWriter(new FileStream(filePath, FileMode.Create)))
                {
                    foreach (var anchor in inList)
                    {
                        // считаем порцию байт (найдем размер порции и саму её по якорям)
                        reader.Seek(anchor, SeekOrigin.Begin);
                        var buffer = new byte[8];
                        reader.Read(buffer, 0, 8);
                        var compressedBlockLength = BitConverter.ToInt32(buffer, 4);
                        var comressedBytes        = new byte[compressedBlockLength + 1];
                        buffer.CopyTo(comressedBytes, 0);
                        reader.Read(comressedBytes, 8, compressedBlockLength - 8);
                        var blockSize = BitConverter.ToInt32(comressedBytes, compressedBlockLength - 4);

                        // разархивируем файл
                        var uncompressedBytes = ProcessUnPacking.ProcessArchive(comressedBytes, blockSize);

                        // запишем во временный файл
                        bw.Write(uncompressedBytes);

                        // расчет прогресса
                        counter++;
                        long ps = counter * 100 / inList.Count;
                        if (ps != oldPs)
                        {
                            m_ProgressList[index] = ps;
                        }
                    }
                    m_ThreadPieceList[index] = new FilePiece(filePath);
                }
            }
        }