From 80c3a4708cbef63643af5d2c953f090eeeedcf1e Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 7 Jul 2016 17:05:50 -0700 Subject: [PATCH] Make sure profilePath exists before loading it. Cleaning up Action names Change to development build for user profiles --- ApplicationView/MainApplicationWidget.cs | 20 ++++++++----------- .../Settings/ProfileManager.cs | 20 ++++++++++++------- Submodules/MatterSlice | 2 +- Submodules/agg-sharp | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/ApplicationView/MainApplicationWidget.cs b/ApplicationView/MainApplicationWidget.cs index 8d38444c5..9a448ee4a 100644 --- a/ApplicationView/MainApplicationWidget.cs +++ b/ApplicationView/MainApplicationWidget.cs @@ -162,13 +162,9 @@ namespace MatterHackers.MatterControl public RootedObjectEventHandler DoneReloadingAll = new RootedObjectEventHandler(); public RootedObjectEventHandler PluginsLoaded = new RootedObjectEventHandler(); - public delegate string GetSessionInfoDelegate(); - - public static event GetSessionInfoDelegate GetSessionInfoEventHandler; - - public static event EventHandler StartLoginEventHandler; - - public static event EventHandler StartLogoutEventHandler; + public static Action StartLoginEventHandler; + public static Action StartLogoutEventHandler; + public static Func GetSessionInfo; public SlicePresetsWindow EditMaterialPresetsWindow { get; set; } @@ -205,7 +201,7 @@ namespace MatterHackers.MatterControl } else // do the regular login { - StartLoginEventHandler?.Invoke(null, null); + StartLoginEventHandler?.Invoke(); UserSettings.Instance.set("ActiveUserName", ApplicationController.Instance.GetSessionUsernameForFileSystem()); } } @@ -230,14 +226,14 @@ namespace MatterHackers.MatterControl { if (clickedLogout) { - StartLogoutEventHandler?.Invoke(null, null); + StartLogoutEventHandler?.Invoke(); UserSettings.Instance.set("ActiveUserName", ""); } }, "Are you sure you want to logout? You will not have access to your printer profiles or cloud library.".Localize(), "Logout?".Localize(), StyledMessageBox.MessageType.YES_NO, "Logout".Localize(), "Cancel".Localize()); } else // just run the logout event { - StartLogoutEventHandler?.Invoke(null, null); + StartLogoutEventHandler?.Invoke(); UserSettings.Instance.set("ActiveUserName", ""); } } @@ -245,9 +241,9 @@ namespace MatterHackers.MatterControl public string GetSessionUsername() { - if (GetSessionInfoEventHandler != null) + if (GetSessionInfo != null) { - return GetSessionInfoEventHandler(); + return GetSessionInfo(); } else { diff --git a/SlicerConfiguration/Settings/ProfileManager.cs b/SlicerConfiguration/Settings/ProfileManager.cs index 3640f30b0..f06cd19c6 100644 --- a/SlicerConfiguration/Settings/ProfileManager.cs +++ b/SlicerConfiguration/Settings/ProfileManager.cs @@ -48,12 +48,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private static readonly string userDataPath = DataStorage.ApplicationDataStorage.ApplicationUserDataPath; internal static readonly string ProfilesPath = Path.Combine(userDataPath, "Profiles"); - private static string profilesDBPath + private static string ProfilesDBPath { get { string username = UserSettings.Instance.get("ActiveUserName"); - return Path.Combine(ProfilesPath, string.IsNullOrEmpty(username) ? "profiles.json" : username + ".json"); } } @@ -85,15 +84,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration Directory.CreateDirectory(ProfilesPath); // Load the profiles.json document - if (File.Exists(profilesDBPath)) + if (File.Exists(ProfilesDBPath)) { - Instance = JsonConvert.DeserializeObject(File.ReadAllText(profilesDBPath)); + Instance = JsonConvert.DeserializeObject(File.ReadAllText(ProfilesDBPath)); } else { Instance = new ProfileManager(); - if (Path.GetFileName(profilesDBPath) == "profiles.json") + if (Path.GetFileName(ProfilesDBPath) == "profiles.json") { // Import classic db based profiles into local json files DataStorage.ClassicDB.ClassicSqlitePrinterProfiles.ImportPrinters(Instance, ProfilesPath); @@ -179,7 +178,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration internal static SettingsProfile LoadProfileFromDisk(string profilePath) { - return new SettingsProfile(PrinterSettings.LoadFile(profilePath)); + if (File.Exists(profilePath)) + { + return new SettingsProfile(PrinterSettings.LoadFile(profilePath)); + } + else + { + return LoadEmptyProfile(); + } } internal static void ImportFromExisting(string settingsFilePath) @@ -324,7 +330,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration public void Save() { - File.WriteAllText(profilesDBPath, JsonConvert.SerializeObject(this, Formatting.Indented)); + File.WriteAllText(ProfilesDBPath, JsonConvert.SerializeObject(this, Formatting.Indented)); } } } \ No newline at end of file diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index 3a1a07f41..15925e9ed 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit 3a1a07f41177a390df86dcf950f6847c6f61dc43 +Subproject commit 15925e9ed6d7fa24c870fcdef81e3a8b5a7e962c diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 62174d719..162194b37 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 62174d719b7e54a122075fd59b1f59ee429bf0d3 +Subproject commit 162194b37fe0aec1b6360336f4366aec97c8efca