xml settings backup
This commit is contained in:
@ -1257,15 +1257,32 @@ namespace CobXmlSupport
|
||||
try
|
||||
{
|
||||
XmlSerializer x = new XmlSerializer(saveColl.GetType());
|
||||
StreamWriter writer = new StreamWriter(SavePath + "\\FilnamnsDict.xml", false);
|
||||
StreamWriter writer = new StreamWriter(SavePath + "\\FilnamnsDict.new", false);
|
||||
x.Serialize(writer, saveColl);
|
||||
//MessageBox.Show("Objektet är serialiserat !(" + SavePath + "\\FilnamnsDict.xml)");
|
||||
writer.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Serialisering : " + ex.Message);
|
||||
}
|
||||
|
||||
long lNewSize = fileSize(SavePath + "\\FilnamnsDict.new");
|
||||
long lOldSize = fileSize(SavePath + "\\FilnamnsDict.xml");
|
||||
|
||||
if (lNewSize > 0 && lNewSize >= lOldSize)
|
||||
{
|
||||
File.Replace(SavePath + "\\FilnamnsDict.new", SavePath + "\\FilnamnsDict.xml", SavePath + "\\FilnamnsDict.old");
|
||||
// File.Move(SavePath + "\\FilnamnsDict.xml", SavePath + "\\FilnamnsDict.old");
|
||||
// File.Move(SavePath + "\\FilnamnsDict.new", SavePath + "\\FilnamnsDict.xml");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private long fileSize(string fileStr)
|
||||
{
|
||||
FileInfo fi = new FileInfo(fileStr);
|
||||
return fi.Length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user