xml settings backup

This commit is contained in:
2015-07-22 14:58:06 +02:00
parent 461b24cc4f
commit e35dbc8df2
2 changed files with 48 additions and 11 deletions

View File

@ -39,7 +39,7 @@ namespace CobXmlSupport
FileList.TryGetValue(fnameChosen, out lSetting);
if (lSetting.ActualFile == S.ettingActualFile)
{
lSetting.SetSettings();
lSetting.GetSettings();
}
lvGenFiles.Items.Clear();
if (lSetting.fileList != null)
@ -67,20 +67,40 @@ namespace CobXmlSupport
private void lvGenFiles_SelectedIndexChanged(object sender, EventArgs e)
{
ListViewItem fnameChosen = lvGenFiles.SelectedItems[0];
if (lvGenFiles.SelectedItems.Count > 0)
{
ListViewItem fnameChosen;
try
{
fnameChosen = lvGenFiles.SelectedItems[0];
if (!fnameChosen.Text.StartsWith("Inga"))
{
showGeneratedFile(fnameChosen.Text, fnameChosen.SubItems[3].Text + "\\" + fnameChosen.SubItems[2].Text);
}
else MessageBox.Show(fnameChosen.Text);
}
catch (Exception ex)
{
MessageBox.Show("Problem listView :\r\n" + ex.Message);
}
}
}
private void showGeneratedFile(string usageName,string fname){
try
{
ShowCode FileWin = new ShowCode();
FileWin.Parent = null;
FileWin.Labeltext = usageName;
FileWin.CodeShower.Text = File.ReadAllText(fname);
FileWin.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show("Misslyckad filläsning!\r\n"+ex.Message);
}
}
}

View File

@ -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;
}