Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. protected override void SaveToFile(string path)
  2.         {
  3.             var profile = new EquipData();
  4.  
  5.             profile.DamageType = (StatType)cboDamageType.SelectedItem;
  6.             profile.MainStat = (StatType)cboMainStat.SelectedItem;
  7.             profile.SubStat = (StatType)cboSubStat.SelectedItem;
  8.  
  9.             profile.Physical = (float)numPhysical.Value;
  10.             profile.Magical = (float)numMagical.Value;
  11.             profile.Special = (float)numSpecial.Value;
  12.  
  13.             //First we'll back up the old file.
  14.             if (File.Exists(path))
  15.             {
  16.                 string backuppath = path + ".bak";
  17.  
  18.                 if (File.Exists(backuppath))
  19.                 {
  20.                     File.Delete(backuppath);
  21.                 }
  22.  
  23.                 File.Copy(path, backuppath);
  24.                 File.Delete(path);
  25.             }
  26.  
  27.             //Then save it!
  28.             var doc = new XDocument(profile.SaveToXml());
  29.  
  30.             using (var stream = File.OpenWrite(path))
  31.             {
  32.                 doc.Save(stream);
  33.             }
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement