Fix issues in ChangeID

- New ID should be set in all cases
- Conditionally load local profile if exists
This commit is contained in:
John Lewin 2016-08-31 13:38:16 -07:00
parent 180c559d09
commit 0a15124e4b
2 changed files with 13 additions and 7 deletions

View file

@ -367,7 +367,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
layeredProfile.Save();
importSuccessful = true;
}
}
break;
}

View file

@ -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();
}