Mark IsDirty during profile save

- Issue MatterHackers/MatterControl#4574
Started using my printer at home and it reverted to an old web
setting that lost all my recent changes
This commit is contained in:
jlewin 2019-05-29 14:16:25 -07:00
parent 203235c50c
commit 6bd0e87cf8
6 changed files with 28 additions and 16 deletions

View file

@ -93,7 +93,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
public static void Save(this PrinterSettings settings)
public static void Save(this PrinterSettings settings, bool userDrivenChange = true)
{
// Skip save operation if on the EmptyProfile
if (!settings.PrinterSelected || !AutoSave)
@ -102,10 +102,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
settings.Save(
filePath: ProfileManager.Instance.ProfilePath(settings.ID));
filePath: ProfileManager.Instance.ProfilePath(settings.ID),
userDrivenChange);
}
public static void Save(this PrinterSettings settings, string filePath)
public static void Save(this PrinterSettings settings, string filePath, bool userDrivenChange = true)
{
// TODO: Rewrite to be owned by ProfileManager and simply mark as dirty and every n period persist and clear dirty flags
lock (writeLock)
@ -116,6 +117,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (printerInfo != null)
{
printerInfo.ContentSHA1 = settings.ComputeSHA1(json);
if (printerInfo.ServerSHA1 == printerInfo.ContentSHA1)
{
// Any change that results in our content arriving at the last known server content fingerprint, should clear the dirty flag
printerInfo.IsDirty = false;
}
else
{
printerInfo.IsDirty |= userDrivenChange;
}
ProfileManager.Instance.Save();
}