internal static void ShowError(Window owner, string caption, string message) { Application.Current.Dispatcher.Invoke(new Action(() => { MessageWindow window = new MessageWindow(); window.DataContext = new MessageWindowViewModel(caption, message, MessageWindowIcon.Error, MessageWindowButton.OK); window.Owner = owner; window.ShowDialog(); })); }
internal static bool? Show(Window owner, string caption, string message, MessageWindowIcon icon = MessageWindowIcon.OK, MessageWindowButton buttons = MessageWindowButton.OK) { bool? result = null; Application.Current.Dispatcher.Invoke(new Action(() => { MessageWindow window = new MessageWindow(); window.DataContext = new MessageWindowViewModel(caption, message, icon, buttons); window.Owner = owner; result = window.ShowDialog(); })); return result; }
/// <summary> /// Called from View when main window has loaded /// </summary> public void Loaded() { // Check for exception loading config file if (configLoadException != null) { App.LogCrash(configLoadException); MessageWindow.Show(owner, "Invalid config file", "An error occurred loading the config file: \n\n" + configLoadException.Message + "\n\nDefault values will be used for most settings.", MessageWindowIcon.Error, MessageWindowButton.OK); } // Make sure parity folder exists if (!String.IsNullOrEmpty(config.ParityDir)) { try { Directory.CreateDirectory(config.ParityDir); } catch (Exception e) { LogFile.Log("Could not create parity folder " + config.ParityDir + ": " + e.Message); App.LogCrash(e); MessageWindow.Show(owner, "Could not access parity folder", "Unable to access the parity location " + config.ParityDir + "\n\n" + "You will need to set a valid parity location (under Options) before proceeding.", MessageWindowIcon.Error, MessageWindowButton.OK); } } // the ParitySet constructor really, really should not fail. If it does, there's nothing we can do, // so just let the global unhandled exception handler catch it, report it, and close the app. paritySet = new ParitySet(config, new disParityUI.Environment()); try { paritySet.ReloadDrives(); } catch (Exception e) { App.LogCrash(e); MessageWindow.Show(owner, "Can't load backup information", "An error occurred while trying to load the backup: \n\n" + e.Message, MessageWindowIcon.Error, MessageWindowButton.OK); } AddDrives(); paritySet.PropertyChanged += HandleParitySetPropertyChanged; UpdateStartupMessage(); UpdateParityStatus(); try { if (!disParity.License.Accepted) { if (!ShowLicenseAgreement()) { owner.Close(); return; } disParity.License.Accepted = true; } // check for new version now and again every 24 hours disParity.Version.DoUpgradeCheck(HandleNewVersionAvailable); pingTimer.Start(); ScanAll(); } catch (Exception e) { App.LogCrash(e); LogFile.Log("Exception in MainWindow.Loaded: " + e.Message); } }