Revise IsDirty and profile/printersettings nomenclature

This commit is contained in:
John Lewin 2016-09-14 12:36:05 -07:00
parent d3802a5b80
commit 4ad70ca38c
3 changed files with 18 additions and 13 deletions

View file

@ -200,14 +200,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
// SHA1 value is based on UTF8 encoded file contents
using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
string sha1 = GenerateSha1(memoryStream);
this.UserLayer["profile_sha1"] = sha1;
string contentSHA1 = GenerateSha1(memoryStream);
this.UserLayer["profile_sha1"] = contentSHA1;
var printerInfo = ProfileManager.Instance[this.ID];
if (printerInfo != null)
{
printerInfo.SHA1 = sha1;
printerInfo.IsDirty = true;
string beforeSaveSHA1 = printerInfo.SHA1;
printerInfo.SHA1 = contentSHA1;
printerInfo.IsDirty = beforeSaveSHA1 != contentSHA1;
ProfileManager.Instance.Save();
}
}

View file

@ -393,14 +393,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
// TODO: jlewin - how can we handle lookup failures at this point? Should we throw and check for the exception?
//if (publicDevice == null)
var newProfile = await LoadOemProfileAsync(publicDevice, make, model);
newProfile.ID = guid;
newProfile.DocumentVersion = PrinterSettings.LatestVersion;
var printerSettings = await LoadOemProfileAsync(publicDevice, make, model);
printerSettings.ID = guid;
printerSettings.DocumentVersion = PrinterSettings.LatestVersion;
newProfile.UserLayer[SettingsKey.printer_name.ToString()] = printerName;
printerSettings.UserLayer[SettingsKey.printer_name.ToString()] = printerName;
// Import named macros as defined in the following printers: (Airwolf Axiom, HD, HD-R, HD2x, HDL, HDx, Me3D Me2, Robo R1[+])
var classicDefaultMacros = newProfile.GetValue("default_macros");
var classicDefaultMacros = printerSettings.GetValue("default_macros");
if (!string.IsNullOrEmpty(classicDefaultMacros))
{
var namedMacros = new Dictionary<string, string>();
@ -418,7 +418,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
string gcode;
if (namedMacros.TryGetValue(namedMacro.Trim(), out gcode))
{
newProfile.Macros.Add(new GCodeMacro()
printerSettings.Macros.Add(new GCodeMacro()
{
Name = namedMacro.Trim(),
GCode = gcode
@ -427,6 +427,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
// Add to Profiles - fires ProfileManager.Save due to ObservableCollection event listener
Instance.Profiles.Add(new PrinterInfo
{
Name = printerName,
@ -435,12 +436,13 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
Model = model
});
// Update SHA1
newProfile.Save();
// Persist changes to PrinterSettings - must come after adding to Profiles above
printerSettings.Save();
// Set as active profile
UserSettings.Instance.set("ActiveProfileID", guid);
ActiveSliceSettings.Instance = newProfile;
ActiveSliceSettings.Instance = printerSettings;
}
public static List<string> ThemeIndexNameMapping = new List<string>()

View file

@ -477,6 +477,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
var profile = PrinterSettings.LoadFile(ProfilePath);
profile.ID = value;
profile.Save();
this.IsDirty = false;
}
}
}