Make sure profilePath exists before loading it.

Cleaning up Action names
Change to development build for user profiles
This commit is contained in:
Lars Brubaker 2016-07-07 17:05:50 -07:00
parent 737955d654
commit 80c3a4708c
4 changed files with 23 additions and 21 deletions

View file

@ -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<string> 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
{

View file

@ -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<ProfileManager>(File.ReadAllText(profilesDBPath));
Instance = JsonConvert.DeserializeObject<ProfileManager>(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));
}
}
}

@ -1 +1 @@
Subproject commit 3a1a07f41177a390df86dcf950f6847c6f61dc43
Subproject commit 15925e9ed6d7fa24c870fcdef81e3a8b5a7e962c

@ -1 +1 @@
Subproject commit 62174d719b7e54a122075fd59b1f59ee429bf0d3
Subproject commit 162194b37fe0aec1b6360336f4366aec97c8efca