예제 #1
0
 public CCCmdCachedMultiBlockFile(ArrayList cachedBlocks, uint IPProxy, byte[] fileHash, byte[] fileStatus, MemoryStream buffer)
 {
     if ((cachedBlocks != null) && (cachedBlocks.Count != 0))
     {
         BinaryWriter writer1 = new BinaryWriter(buffer);
         DonkeyHeader header1 = new DonkeyHeader(0x21, writer1, Protocol.ProtocolType.Ant);
         this.n = 0;
         writer1.Write(this.n);
         writer1.Write(IPProxy);
         writer1.Write(fileHash);
         foreach (CCachedBlock block1 in cachedBlocks)
         {
             if (((block1.Element == null) || (block1.Element.File == null)) || !CKernel.SameHash(ref fileHash, ref block1.Element.File.FileHash))
             {
                 continue;
             }
             uint num1 = CHash.GetChunkNumberAt(block1.StartOffset);
             if (fileStatus[(int)((IntPtr)num1)] == 0)
             {
                 writer1.Write(block1.IPClient);
                 writer1.Write(block1.PortClient);
                 writer1.Write(block1.StartOffset);
                 writer1.Write(block1.EndOffset);
                 writer1.Write(block1.Key);
                 writer1.Write(block1.ID);
                 this.n = (ushort)(this.n + 1);
             }
         }
         header1.Packetlength = (((uint)writer1.BaseStream.Length) - header1.Packetlength) + 1;
         writer1.Seek(0, SeekOrigin.Begin);
         header1.Serialize(writer1);
         writer1.Write(this.n);
     }
 }
예제 #2
0
파일: FilesList.cs 프로젝트: biuken/eAnt
        private bool m_LoadFilesFromFolder(string folder /*,bool refreshing*/)
        {
            if (!Directory.Exists(folder))
            {
                return(false);
            }
            string [] ficheros = Directory.GetFiles(folder);
            DateTime  date;
            string    name;

            if (m_EdonkeyHash == null)
            {
                m_EdonkeyHash = new CHash();
            }
            foreach (string file in ficheros)
            {
                // 0 Kb file are ignored, avoid a crash
                FileInfo filInfo = new FileInfo(file);
                if ((filInfo.Length == 0) ||
                    ((filInfo.Attributes & (FileAttributes.Hidden | FileAttributes.System)) != 0))
                {
                    continue;
                }

                date = File.GetLastWriteTime(file).ToUniversalTime();
                name = Path.GetFileName(file);
                CKnownFileAttributes Atributos;
                if ((Atributos = m_IsKnown(name, date)) != null)
                {
                    //if (refreshing) continue;
                    if (!m_Contains(Atributos.FileHash))
                    {
                        CElement Element = new CElement();
                        Element.File        = new CFile(Atributos.FileHash, Atributos.Date, folder, name, Atributos.Size, Atributos.Priority, Atributos.Permisions, Atributos.HashSet, Atributos.Comment, Atributos.Rating);
                        Element.SourcesList = null;
                        Element.Statistics  = new CFileStatistics();
                        this.m_FileList.Add(Element);
                        CKernel.NewSharedFile(Element);
                    }
                    //if (!m_Contains(Atributos.FileHash))this.m_FileList.Add(Element);
                }
                else                 //new file
                {
                    m_EdonkeyHash.AddFile(file);
                }
            }
            return(true);
        }
예제 #3
0
파일: SourcesList.cs 프로젝트: biuken/eAnt
 public void AddChunksAvaibility(byte[] chunkStatus)
 {
     if (m_Avaibility == null)
     {
         m_Avaibility = new ushort[CHash.GetChunksCount(m_Element.File.FileSize)];
     }
     if ((chunkStatus == null) || (chunkStatus.Length != m_Avaibility.Length))
     {
         return;
     }
     for (int i = 0; i != chunkStatus.Length; i++)
     {
         if ((Protocol.ChunkState)chunkStatus[i] == Protocol.ChunkState.Complete)
         {
             m_Avaibility[i]++;
         }
     }
 }
예제 #4
0
파일: SourcesList.cs 프로젝트: biuken/eAnt
        public void UpdateChunksAvaibility()
        {
            byte[] DownFileChunks;
            if (m_Avaibility == null)
            {
                m_Avaibility = new ushort[CHash.GetChunksCount(m_Element.File.FileSize)];
            }
            ushort[] avaibilitytmp = new ushort[m_Avaibility.Length];
            if (m_Element == null)
            {
                return;
            }
            int nChunks = m_Element.File.NumChunks;

            for (int i = 0; i != avaibilitytmp.Length; i++)
            {
                avaibilitytmp[i] = 0;
            }
            lock (m_ArrayList.SyncRoot)
            {
                foreach (CClient source in m_ArrayList)
                {
                    if (m_Element == null)
                    {
                        return;
                    }
                    DownFileChunks = source.DownFileChunks;
                    if (DownFileChunks != null)
                    {
                        for (int i = 0; i != nChunks; i++)
                        {
                            if ((Protocol.ChunkState)DownFileChunks[i] == Protocol.ChunkState.Complete)
                            {
                                avaibilitytmp[i]++;
                            }
                        }
                    }
                }
            }
            m_Avaibility = avaibilitytmp;
        }
예제 #5
0
파일: SourcesList.cs 프로젝트: biuken/eAnt
 public void RemoveChunksAvaibility(byte[] chunkStatus)
 {
     if (m_Element == null)
     {
         return;                              //possible when stopping the file
     }
     if (m_Avaibility == null)
     {
         m_Avaibility = new ushort[CHash.GetChunksCount(m_Element.File.FileSize)];
     }
     if ((chunkStatus == null) || (chunkStatus.Length != m_Avaibility.Length))
     {
         return;
     }
     for (int i = 0; i != chunkStatus.Length; i++)
     {
         if (((Protocol.ChunkState)chunkStatus[i] == Protocol.ChunkState.Complete) &&
             (m_Avaibility[i] > 0))
         {
             m_Avaibility[i]--;
         }
     }
 }