xml settings backup
This commit is contained in:
@ -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 (!fnameChosen.Text.StartsWith("Inga"))
|
||||
if (lvGenFiles.SelectedItems.Count > 0)
|
||||
{
|
||||
showGeneratedFile(fnameChosen.Text, fnameChosen.SubItems[3].Text + "\\" + fnameChosen.SubItems[2].Text);
|
||||
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);
|
||||
}
|
||||
}
|
||||
else MessageBox.Show(fnameChosen.Text);
|
||||
|
||||
}
|
||||
|
||||
private void showGeneratedFile(string usageName,string fname){
|
||||
ShowCode FileWin = new ShowCode();
|
||||
FileWin.Parent = null;
|
||||
FileWin.Labeltext = usageName;
|
||||
FileWin.CodeShower.Text = File.ReadAllText(fname);
|
||||
FileWin.ShowDialog();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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