Exemplo n.º 1
0
        public void ReadChunk()
        {
#if FR2_DEBUG
            if (currentChunk == 0)
            {
                Debug.LogWarning("Read <" + chunkList[0].file + "> " + currentChunk + ":" + nChunk);
            }
#endif
            if (currentChunk == nChunk)
            {
                Debug.LogWarning("Something wrong, should dead <" + isDead + ">");
                return;
            }

            int from = currentChunk * chunkSize;
            size = (int)Mathf.Min(fileSize - from, chunkSize);

            for (var i = 0; i < chunkList.Count; i++)
            {
                FR2_Chunk chunk = chunkList[i];
                chunk.size = size;
                chunk.stream.Read(chunk.buffer, 0, size);
            }

            currentChunk++;
        }
Exemplo n.º 2
0
        public void AddToDict(byte b, FR2_Chunk chunk, Dictionary <byte, List <FR2_Chunk> > dict)
        {
            List <FR2_Chunk> list;

            if (!dict.TryGetValue(b, out list))
            {
                list = new List <FR2_Chunk>();
                dict.Add(b, list);
            }

            list.Add(chunk);
        }
Exemplo n.º 3
0
        public void CompareChunk(List <FR2_Head> heads)
        {
            int idx = chunkList.Count;

            byte[] buffer = chunkList[idx - 1].buffer;

            while (--idx >= 0)
            {
                FR2_Chunk chunk = chunkList[idx];
                int       diff  = FirstDifferentIndex(buffer, chunk.buffer, size);
                if (diff == -1)
                {
                    continue;
                }
#if FR2_DEBUG
                Debug.Log(string.Format(
                              " --> Different found at : idx={0} diff={1} size={2} chunk={3}",
                              idx, diff, size, currentChunk));
#endif

                byte v = buffer[diff];
                var  d = new Dictionary <byte, List <FR2_Chunk> >();             //new heads
                chunkList.RemoveAt(idx);
                FR2_FileCompare.HashChunksNotComplete.Add(chunk);

                AddToDict(chunk.buffer[diff], chunk, d);

                for (int j = idx - 1; j >= 0; j--)
                {
                    FR2_Chunk tChunk = chunkList[j];
                    byte      tValue = tChunk.buffer[diff];
                    if (tValue == v)
                    {
                        continue;
                    }

                    idx--;
                    FR2_FileCompare.HashChunksNotComplete.Add(tChunk);
                    chunkList.RemoveAt(j);
                    AddToDict(tChunk.buffer[diff], tChunk, d);
                }

                foreach (KeyValuePair <byte, List <FR2_Chunk> > item in d)
                {
                    List <FR2_Chunk> list = item.Value;
                    if (list.Count == 1)
                    {
#if FR2_DEBUG
                        Debug.Log(" --> Dead head found for : " + list[0].file);
#endif
                    }
                    else if (list.Count > 1)                     // 1 : dead head
                    {
#if FR2_DEBUG
                        Debug.Log(" --> NEW HEAD : " + list[0].file);
#endif
                        heads.Add(new FR2_Head
                        {
                            nChunk       = nChunk,
                            fileSize     = fileSize,
                            currentChunk = currentChunk - 1,
                            chunkList    = list
                        });
                    }
                }
            }
        }