From 0a15124e4b418a5f7d004cd418d1181cfed503fa Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 31 Aug 2016 13:38:16 -0700 Subject: [PATCH] Fix issues in ChangeID - New ID should be set in all cases - Conditionally load local profile if exists --- .../Settings/ProfileManager.cs | 1 - .../Settings/SettingsHelpers.cs | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index 0d2864b39..c4d63dfae 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -367,7 +367,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration layeredProfile.Save(); importSuccessful = true; } - } break; } diff --git a/SlicerConfiguration/Settings/SettingsHelpers.cs b/SlicerConfiguration/Settings/SettingsHelpers.cs index 334455c5e..652898056 100644 --- a/SlicerConfiguration/Settings/SettingsHelpers.cs +++ b/SlicerConfiguration/Settings/SettingsHelpers.cs @@ -449,23 +449,30 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public bool MarkedForDelete { get; set; } = false; public string SHA1 { get; set; } - public void ChangeID(string deviceToken) + public void ChangeID(string newID) { + // Update in memory state if IDs match if (ActiveSliceSettings.Instance.ID == this.ID) { - ActiveSliceSettings.Instance.ID = deviceToken; + ActiveSliceSettings.Instance.ID = newID; } + this.ID = newID; + + // Ensure the local file with the old ID moves with the new ID change string existingProfile = ProfilePath; if (File.Exists(existingProfile)) { - this.ID = deviceToken; File.Move(existingProfile, ProfilePath); } - var profile = PrinterSettings.LoadFile(ProfilePath); - profile.ID = deviceToken; - profile.SetValue(SettingsKey.device_token, deviceToken); + if (File.Exists(ProfilePath)) + { + var profile = PrinterSettings.LoadFile(ProfilePath); + profile.ID = newID; + profile.Save(); + } + ProfileManager.Instance.Save(); }