Beispiel #1
0
 /// <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(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      = string.Concat(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....
     //          Info.Loaded=false;
 }
Beispiel #2
0
 /// <summary>
 /// constructor for incomplete files with its own .met
 /// the file is opened in write mode and it remains open until exit or file completes
 /// </summary>
 public CFile(string in_m_FileFolder, string in_filename)
 {
     m_PartFileName  = in_filename;
     m_FileFolder    = in_m_FileFolder;
     m_CompleteName  = string.Concat(m_FileFolder, "\\" , m_PartFileName);
     m_MetFile       = string.Concat(m_PartFileName, ".met");
     m_CompleteNameMet   = string.Concat(m_CompleteName, ".met");
     m_MyComment="";
     m_Gaps=new SortedList();
     m_UnknownParameters=new ArrayList();
     m_RequestingBlocks=new SortedList();
     if (m_LoadMet())
     {
     DateTime fileDate=new DateTime();
     fileDate=File.GetLastWriteTime(m_CompleteName).ToUniversalTime();
     //m_LoadChunkStatus();
     m_Completed=false;
     if (!m_OpenFileWrite()) //se abre el fichero en modo escritura y se mantiene abierto hasta que se cierra el objeto
     {
         //si da un error al abrir el fichero: devolver un error en el constructor???
     }
     //if (Gaps.Count>0) m_RepairLphantOldGaps();
     m_LoadChunkStatus();
     //m_LoadCrumbsStatus();
     if (DateTime.Compare(fileDate,m_FileDate)!=0)
     {
         m_FileDate=fileDate;
         //TODO: Rehash las partes completas del fichero y comprobar que estan completas las que dicen que lo estan??
         //m_CheckCompleteFile();
     }
     m_FileDetails = new CFileDetails(m_CompleteName,m_FileName);
     if (m_Gaps.Count==0)
     {
         //comprobar que esta completo... llamar a m_CheckCompleteFile
         if (m_HashSet.Count>0)
         {
             m_CheckCompleteFile();
         }
         else
         {
             m_Gaps.Add((uint)0,m_FileSize-1);
         }
     }
     }
     else
     {
     FileHash=null; //file bad loaded
     CLog.Log(Constants.Log.Notify,"Error loading MET file: " + m_CompleteNameMet);
     }
     m_FileType = 2; // TODO ver porque el tipo es fijo a 2....
     //          Info.Loaded=false;
     //          GetInfo();
 }
Beispiel #3
0
 /// <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;
     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=string.Concat(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();
 }