Пример #1
0
 //递归从每个子目录中读取文件信息
 private void Load(System.IO.DirectoryInfo diparent)
 {
     foreach (System.IO.DirectoryInfo di in diparent.GetDirectories())
     {
         Load(di);
     }
     foreach (System.IO.FileInfo fi in diparent.GetFiles())
     {
         FileInfo finew = new FileInfo(fi);
         this.Add(finew.ID, finew);
     }
 }
Пример #2
0
 //递归读出每个Xml节点表示的文件信息
 private void Load(XmlNode nodeparent)
 {
     foreach (XmlNode node in nodeparent.ChildNodes)
     {
         if (node.Name.Equals("Folder"))
         {
             Load(node);
         }
         else if(node.Name.Equals("File"))
         {
             int id = Convert.ToInt32(node.Attributes["ID"].Value);
             string name = node.Attributes["Name"].Value;
             DateTime date = Convert.ToDateTime(node.Attributes["Date"].Value);
             int length = Convert.ToInt32(node.Attributes["Length"].Value);
             string directoryname = string.Empty;
             if (nodeparent.Name.Equals("Folder"))
             {
                 directoryname = nodeparent.Attributes["Name"].Value;
             }
             FileInfo finew = new FileInfo(id, name, directoryname, date, length);
             if (node.Attributes["OverWritable"] != null)
             {
                 finew.OverWritable = Convert.ToBoolean(node.Attributes["OverWritable"].Value);
             }
             this.Add(finew.ID,finew);
         }
         else if (node.Name.Equals("FileResume"))
         {
             int id = Convert.ToInt32(node.Attributes["ID"].Value);
             DateTime date = Convert.ToDateTime(node.Attributes["Date"].Value);
             int length = Convert.ToInt32(node.Attributes["Length"].Value);
             int offset = Convert.ToInt32(node.Attributes["Offset"].Value);
             SetFiletoResumeInfo(id, date, length, offset);
         }
     }
 }
Пример #3
0
 /// <summary>
 /// 设置续传文件的信息和开始位置
 /// </summary>
 /// <param name="id"></param>
 /// <param name="offset"></param>
 public void SetFiletoResumeInfo(int id, DateTime dt, int length, int offset)
 {
     _FileResume = new FileInfo(id, null, null, dt, length);
     _FileOffSet = offset;
 }
Пример #4
0
 /// <summary>
 /// 清空续传信息
 /// </summary>
 private void ClearFiletoResume()
 {
     _FileResume = null;
     _FileOffSet = 0;
 }
Пример #5
0
 //未测试
 /// <summary>
 /// 通过文件标识号,修改日期,文件长度来比较是否与当前文件是否相同
 /// </summary>
 /// <param name="fi">待比较的文件实例</param>
 /// <returns>是否相同</returns>
 public bool Equals(FileInfo fi)
 {
     return (!OverWritable) || (!fi.OverWritable)
        || ID.Equals(fi.ID) && Math.Abs(((TimeSpan)(Date - fi.Date)).TotalSeconds) < 1.01 && Length.Equals(fi.Length);//时间类型的比较 0.5Ms会有不相等的情况
 }