public static HashTrackerList LoadFromFile(string file) { if (!File.Exists(file)) { return(new HashTrackerList()); } else { return(HashTrackerList.Deserialize(file)); } }
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; } }
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; } }
public static void SaveToFile(string file, HashTrackerList mtl) { AutoCreateLongHash = false; Serialize(file, mtl); AutoCreateLongHash = true; }