示例#1
0
 public static HashTrackerList LoadFromFile(string file)
 {
     if (!File.Exists(file))
     {
         return(new HashTrackerList());
     }
     else
     {
         return(HashTrackerList.Deserialize(file));
     }
 }
示例#2
0
 private static HashTrackerList Deserialize(string file)
 {
     try
     {
         using (Stream streamRead = File.OpenRead(file))
         {
             System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(HashTrackerList));
             HashTrackerList obj = (HashTrackerList)xs.Deserialize(streamRead);
             obj.Sort();
             return(obj);
         }
     }
     catch
     {
         throw;
     }
 }
示例#3
0
        private static void Serialize(string file, HashTrackerList mtl)
        {
            string tmpFile = file + ".tmp";

            try
            {
                using (Stream streamWrite = File.Create(tmpFile))
                {
                    System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(mtl.GetType());
                    xs.Serialize(streamWrite, mtl);
                }

                if (File.Exists(file))
                {
                    File.Delete(file);
                }

                File.Move(tmpFile, file);
            }
            catch
            {
                throw;
            }
        }
示例#4
0
 public static void SaveToFile(string file, HashTrackerList mtl)
 {
     AutoCreateLongHash = false;
     Serialize(file, mtl);
     AutoCreateLongHash = true;
 }