public StartupOptionsDialog() : base("OPlanner Startup Options") { DialogContent = new StartupOptionsDialogContent(); Dialog.Content = DialogContent; ShouldUseClone = false; ShouldClearCurrentProductGroup = false; ShouldClearUserPreferences = false; DialogContent.UserPreferencesPathBox.Text = UserPreferences.GetUserPreferencesFullPath(); AddButton(Dialog.OkButton).Click += OkButton_Click; AddButton(Dialog.CancelButton).Click += CancelButton_Click; AddButton("Quit").Click += QuitButton_Click; }
public static UserPreferences Unserialize(bool shouldClearUserPreferences) { UserPreferences userPreferences = null; string preferencesFullPath = GetUserPreferencesFullPath(); if (shouldClearUserPreferences) { File.Delete(preferencesFullPath); } if (File.Exists(preferencesFullPath)) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(preferencesFullPath, FileMode.Open, FileAccess.Read, FileShare.Read); try { userPreferences = (UserPreferences)formatter.Deserialize(stream); } catch (Exception) { if (File.Exists(preferencesFullPath)) { File.Delete(preferencesFullPath); } userPreferences = null; } finally { stream.Close(); if (userPreferences == null) { userPreferences = null; } } } if (userPreferences == null || userPreferences.ProductPreferences == null || userPreferences.GlobalPreferences == null) { userPreferences = new UserPreferences(); } return(userPreferences); }
//------------------------------------------------------------------------------------ /// <summary> /// Give user diagnostic start-up options, initialize user preferences, etc. /// </summary> //------------------------------------------------------------------------------------ bool InitializeStartupOptions(out bool shouldClearProductGroup) { bool optionsDialogInUse = false; bool shouldUseCloneHostStore = false; bool shouldClearUserPreferences = false; shouldClearProductGroup = false; if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.LeftShift)) { StartupOptionsDialog dialog = new StartupOptionsDialog(); dialog.ShowDialog(); if (dialog.Result == DialogResult.Quit) { Shutdown(); return(false); } else if (dialog.Result != DialogResult.Cancel) { optionsDialogInUse = true; shouldUseCloneHostStore = dialog.ShouldUseClone; shouldClearUserPreferences = dialog.ShouldClearUserPreferences; shouldClearProductGroup = dialog.ShouldClearCurrentProductGroup; } } UserPreferences = UserPreferences.Unserialize(shouldClearUserPreferences); if (optionsDialogInUse) { UserPreferences.ShouldUseCloneHostStore = shouldUseCloneHostStore; } if (shouldUseCloneHostStore) { shouldClearProductGroup = true; } return(true); }