public void SetDownloadPriority(string strFileHash, Constants.Priority priority) { CElement ChangedElement = (CElement)this[CKernel.StringToHash(strFileHash)]; if ((ChangedElement == null) || (ChangedElement.File.DownPriority == priority) || (ChangedElement.File.FileStatus == Protocol.FileState.Complete)) { return; } ChangedElement.File.DownPriority = (Constants.Priority)priority; CKernel.ClientsList.SwapClientsToHigherPriorityFile(); }
/// <summary> /// constructor for complete shared files /// </summary> public CFile(byte[] in_FileHash, DateTime in_fecha, string in_m_FileFolder, string in_nombreFichero,uint in_m_FileSize, Constants.Priority in_Prioridad, byte permisos, ArrayList in_HashSet, string in_strComment, byte in_rating) { FileHash=in_FileHash; //fechaFichero=in_fecha; m_FileName=in_nombreFichero; m_FileFolder=in_m_FileFolder; m_FileSize=in_m_FileSize; m_Transferred=in_m_FileSize; m_FileStatus=Protocol.FileState.Complete; m_UpPriority=in_Prioridad; permisos=permisos; m_Completed=true; m_isEmpty=false; m_HashSet=in_HashSet; //nPartes=(ushort)(((int)(m_FileSize-1)/(int)Protocol.PartSize) + 1); m_NumChunks=(ushort)in_HashSet.Count; m_MyComment=in_strComment; m_MyRating=in_rating; m_ChunksStatus=new Byte[m_NumChunks]; for (int i=0;i!=m_ChunksStatus.Length;i++) { m_ChunksStatus[i]=(byte)Protocol.ChunkState.Complete; } m_CompleteName=Path.Combine(m_FileFolder, m_FileName); m_FileDate=new DateTime(); m_FileDate=File.GetLastWriteTime(m_CompleteName).ToUniversalTime(); if (DateTime.Compare(in_fecha,m_FileDate)!=0) { //TODO: Rehash el fichero } m_FileType=2; // TODO ver porque el tipo es fijo a 2.... m_FileDetails = new CFileDetails(m_CompleteName,m_FileName); // Info.Loaded=false; // GetInfo(); m_MaxSources=0; }
private void m_LoadMetParameters(BinaryReader reader) { CParameterReader ParameterReader; uint nparameters=reader.ReadUInt32(); for (uint parameter=0;parameter!=nparameters;parameter++) { ParameterReader=new CParameterReader(reader); string parametername; byte parameterid; parametername=ParameterReader.nombreParam; parameterid = ParameterReader.id; switch( (Protocol.FileTag)ParameterReader.id ) { case Protocol.FileTag.Name: m_FileName=ParameterReader.valorString; break; case Protocol.FileTag.Size: m_FileSize=ParameterReader.valorNum; break; case Protocol.FileTag.Priority: m_DownPriority=(Constants.Priority)ParameterReader.valorNum; break; case Protocol.FileTag.UploadPriority: m_UpPriority=(Constants.Priority)ParameterReader.valorNum; break; case Protocol.FileTag.Transfered: m_Transferred=ParameterReader.valorNum; break; case Protocol.FileTag.LastSeenComplete: m_LastSeenComplete=ParameterReader.valorNum; break; case Protocol.FileTag.State: m_FileStatus=(Protocol.FileState)ParameterReader.valorNum; break; case Protocol.FileTag.Comment: m_MyComment=ParameterReader.valorString; break; case Protocol.FileTag.Rating: m_MyRating=(byte)ParameterReader.valorNum; break; case Protocol.FileTag.CorruptedPart: if (m_CorruptedChunks == null) m_CorruptedChunks=new ArrayList(); m_CorruptedChunks.Add((int)ParameterReader.valorNum); break; case Protocol.FileTag.Category: m_CategoryID=ParameterReader.valorNum; break; default: if (!(ParameterReader.nombreParam == null)) { if ((byte)ParameterReader.nombreParam.ToCharArray()[0] == (byte)Protocol.FileTag.GapStart) { uint inicio_gap; inicio_gap=ParameterReader.valorNum; ParameterReader=new CParameterReader(reader); parameter++; if ((byte)ParameterReader.nombreParam.ToCharArray()[0]!=(byte)Protocol.FileTag.GapEnd) { //TODO: lanzar error en gap } else { uint fin_gap; fin_gap=ParameterReader.valorNum; //TODO: for next revision: m_AddGap(inicio_gap, fin_gap-1); //Debug.WriteLine("Gap:"+inicio_gap.ToString()+" : "+(fin_gap-1).ToString()); if (((byte)m_FileFormat==(byte)Protocol.PartMet.eDonkeyOld)&&(ParameterReader.nombreParam.IndexOf(" ")>0)) continue; m_AddGap(inicio_gap, fin_gap-1); //if (fin_gap>=m_FileSize) fin_gap=m_FileSize-1; //if ((fin_gap>=inicio_gap) && (fin_gap>=0) && (inicio_gap>=0) && (fin_gap<m_FileSize) && (inicio_gap<m_FileSize)) Gaps.Add((uint)inicio_gap, (uint)fin_gap); } } else { if (ParameterReader.nombreParam==Protocol.FT_MAXSOURCES) m_MaxSources=ParameterReader.valorNum; else if (ParameterReader.nombreParam==Protocol.FT_COMMENT) m_MyComment=ParameterReader.valorString; else if (ParameterReader.nombreParam==Protocol.FT_RATING) m_MyRating=(byte)ParameterReader.valorNum; else m_UnknownParameters.Add(ParameterReader); } } else m_UnknownParameters.Add(ParameterReader); break; //TODO: faltan los parameters para las estadisticas.... } } }
/// <summary> /// constructor for a new downloading file /// </summary> public CFile(byte[] in_FileHash, string in_realfilename, uint in_FileSize) { //buscar el primer nombre .Part que este vacio en el 1er //TODO controlar posible error: que este vacio el array de directorios temporales string in_fileFolder; string in_fileName; in_fileFolder=(string)CKernel.Preferences.GetStringArray("TempFolders")[0]; uint cont=1; if (!Directory.Exists(in_fileFolder)) { Directory.CreateDirectory(in_fileFolder); } while (File.Exists(Path.Combine(in_fileFolder, cont.ToString("000") + ".part"))) { cont++; } in_fileName=cont.ToString("000") + ".part"; FileHash = in_FileHash; m_FileName = in_realfilename; m_PartFileName = in_fileName; m_FileFolder = in_fileFolder; m_FileSize = in_FileSize; m_MyComment=""; m_CompleteName = Path.Combine(m_FileFolder, m_PartFileName); m_MetFile = string.Concat(m_PartFileName, ".met"); m_CompleteNameMet = string.Concat(m_CompleteName, ".met"); m_Transferred = 0; m_UpPriority =Constants.Priority.High; m_DownPriority =Constants.Priority.Normal; //nPartes = (ushort)(((int)(m_FileSize-1)/(int)Protocol.PartSize) + 1); m_NumChunks = 0; if (m_CreateWriteFile()) { m_ChunksStatus=new Byte[m_NumChunks]; for (int i=0;i!=m_ChunksStatus.Length;i++) { m_ChunksStatus[i]=(byte)Protocol.ChunkState.Empty; } m_HashSet=new ArrayList(m_NumChunks); m_Gaps=new SortedList(); m_RequestingBlocks=new SortedList(); m_Gaps.Add((uint)0,m_FileSize-1); m_FileDate=new DateTime(); m_FileDate=File.GetLastWriteTime(m_CompleteName).ToUniversalTime(); SaveMet(); SaveMetBackup(); } m_CategoryID=CKernel.CategoriesList.GetAutoCategory(in_realfilename); m_FileDetails = new CFileDetails(m_CompleteName,m_FileName); m_FileType = 2; // TODO ver porque el tipo es fijo a 2.... m_MaxSources=0; // Info.Loaded=false; }