Get person files to auto-backup when we save them.

This commit is contained in:
Tim Young 2017-08-05 13:11:26 -05:00
parent 22552ce1a9
commit 9905d2e2cb
3 changed files with 17 additions and 4 deletions

View File

@ -312,6 +312,7 @@ namespace EduNetworkBuilder
public static int DefaultPasswordLen = 6;
public static int DefaultMachinePasswordLen = 20;
public static int DefaultSaltLen = 50;
public static int NormalRotation = 5;
public static string AllowedPasswordCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=!~@#$%^&*()_+{}[]/?<>,.";
public static string AllowedUsernameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890._";
@ -1039,6 +1040,16 @@ namespace EduNetworkBuilder
MoveFileWithRotation(SourceFileWithDir, StandardDest, rotation);
}
/// <summary>
/// Move a file out of the way, making a rotating backup at the same time. backup to appdata
/// </summary>
/// <param name="SourceFileWithDir">A source filename with a directory</param>
public static void MoveFileWithRotation(string SourceFileWithDir)
{
string StandardDest = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EduNetworkBuilder");
MoveFileWithRotation(SourceFileWithDir, StandardDest, NB.NormalRotation);
}
/// <summary>
/// Given a file, rotate it with the specified number of versions.
/// </summary>

View File

@ -1559,7 +1559,7 @@ namespace EduNetworkBuilder
OurSettings.Save(NB.IsRunningOnMono());
if (CurrentUser != null)
CurrentUser.Save();
CurrentUser.Save(true); //Save the person, making a backup of the person file
}
private void dHCPRequestToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -167,18 +167,20 @@ namespace EduNetworkBuilder
}
}
public void Save()
public void Save(bool doRotation = false)
{
//Save to our pre-existing / pre-defined file
string filename = Path.Combine(filepath, FileName);
Save(filename);
Save(filename, doRotation);
}
public void Save(string filename)
public void Save(string filename, bool doRotation = false)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = true;
if (doRotation && File.Exists(filename))
NB.MoveFileWithRotation(filename); //make a backup of the file
XmlWriter writer = XmlWriter.Create(filename, settings);
//Now we write the file: