public static void CheckPassword(SqliteConnection connection, SqliteConnection _conn, string password, bool isError = false) { var passwordInput = new NSSecureTextField(new CGRect(0, 0, 300, 20)); passwordInput.PlaceholderAttributedString = new Foundation.NSAttributedString("Enter password..."); var passwordAlert = new NSAlert() { AlertStyle = isError ? NSAlertStyle.Critical : NSAlertStyle.Informational, InformativeText = isError ? "Previous password attempt was incorrect, please retry" : "Enter SittingDucks Password", MessageText = "Authentication Required", }; passwordAlert.AddButton("Enter"); passwordAlert.AddButton("Change Password"); passwordAlert.AccessoryView = passwordInput; passwordAlert.Layout(); var result = passwordAlert.RunModal(); passwordAlert.Dispose(); if (passwordInput.StringValue != password) { CheckPassword(connection, _conn, password, true); } else if (result == 1001) { NewPassword(connection, _conn); } }
public override WindowResponse Show(object parent, string message, string title, MessageWindowType type, MessageWindowButtons bType) { NSAlert al = new NSAlert(); al.AlertStyle = CocoaHelper.GetWinType(type); al.MessageText = title; al.InformativeText = message; switch (bType) { case MessageWindowButtons.AbortRetryIgnore: al.AddButton(Message.GetString("Abort")); al.AddButton(Message.GetString("Retry")); al.AddButton(Message.GetString("Ignore")); break; case MessageWindowButtons.Cancel: al.AddButton(Message.GetString("Cancel")); break; case MessageWindowButtons.Close: al.AddButton(Message.GetString("Close")); break; case MessageWindowButtons.Ok: al.AddButton(Message.GetString("Ok")); break; case MessageWindowButtons.OkCancel: al.AddButton(Message.GetString("Ok")); al.AddButton(Message.GetString("Cancel")); break; case MessageWindowButtons.RetryCancel: al.AddButton(Message.GetString("Retry")); al.AddButton(Message.GetString("Cancel")); break; case MessageWindowButtons.YesNo: al.AddButton(Message.GetString("Yes")); al.AddButton(Message.GetString("No")); break; case MessageWindowButtons.YesNoCancel: al.AddButton(Message.GetString("Yes")); al.AddButton(Message.GetString("No")); al.AddButton(Message.GetString("Cancel")); break; } WindowResponse resp = CocoaHelper.GetResponse(al.RunModal(), bType); al.Dispose(); return(resp); }
public static void Alert(string title, string message, NSAlertStyle style) { NSAlert alert = new NSAlert() { AlertStyle = style, InformativeText = message, MessageText = title }; alert.RunModal(); alert.Dispose(); }
private void MessageBox(string message, string title) { var alert = new NSAlert(); alert.AddButton("OK"); alert.MessageText = title; alert.InformativeText = message; alert.BeginSheet(this, delegate { alert.Dispose(); }); }
public static void UpdateCheck(bool confirm = false) { bool hasUpdate = false; string versionDetails = new WebClient().DownloadString(versionURL); if (versionDetails != "") { string[] versionNumbers = versionDetails.Split(","); if (float.Parse(versionNumbers[0].Trim()) > float.Parse(appVersion)) { hasUpdate = true; } if (int.Parse(versionNumbers[1].Trim()) > int.Parse(appBuild)) { hasUpdate = true; } } if (hasUpdate == true) { NSAlert alert = new NSAlert() { AlertStyle = NSAlertStyle.Informational, InformativeText = "An updated version of IPList is available! Would you like to download it now?", MessageText = "Software Update" }; alert.AddButton("Yes"); alert.AddButton("No"); alert.ShowsSuppressionButton = true; nint result = alert.RunModal(); if (alert.SuppressionButton.State == NSCellStateValue.On) { Settings.UpdateCheck = 0; Alert("Software Update", "Automatic update check has been disabled. You can re-enable it in Preferences.", NSAlertStyle.Informational); } if (result == 1000) { Process.Start(downloadURL); } alert.Dispose(); } if (confirm) { Alert("Software Update", "No new updates were found.", NSAlertStyle.Informational); } }
protected virtual IDisposable Present(Func <NSAlert> alertFunc) { NSAlert alert = null; var app = NSApplication.SharedApplication; app.InvokeOnMainThread(() => { alert = alertFunc(); }); return(new DisposableAction(() => app.BeginInvokeOnMainThread(() => { if (alert == null) { return; } this.windowFunc().EndSheet(alert.Window); alert.Dispose(); }))); }
public static void NewPassword(SqliteConnection connection, SqliteConnection _conn) { var newPasswordInput = new NSStackView(new CGRect(0, 0, 300, 50)); var originalPassword = new NSSecureTextField(new CGRect(0, 25, 300, 20)); originalPassword.PlaceholderAttributedString = new Foundation.NSAttributedString("Type new password..."); var confirmedPassword = new NSSecureTextField(new CGRect(0, 0, 300, 20)); confirmedPassword.PlaceholderAttributedString = new Foundation.NSAttributedString("Confirm password..."); newPasswordInput.AddSubview(originalPassword); newPasswordInput.AddSubview(confirmedPassword); var newPasswordAlert = new NSAlert() { AlertStyle = NSAlertStyle.Informational, InformativeText = "Enter new password to secure SittingDucks", MessageText = "Adding New Password", }; var enterButton = newPasswordAlert.AddButton("Enter"); originalPassword.NextKeyView = confirmedPassword; confirmedPassword.NextKeyView = enterButton; newPasswordAlert.AccessoryView = newPasswordInput; newPasswordAlert.Layout(); var result = newPasswordAlert.RunModal(); if (result == 1000 && originalPassword.StringValue == confirmedPassword.StringValue) { bool shouldClose; var encryptedPassword = EncryptionTool.Encrypt(originalPassword.StringValue); (_conn, shouldClose) = SqliteManager.OpenConnection(connection); // Execute query using (var command = connection.CreateCommand()) { // Create new command command.CommandText = "UPDATE [System] SET ID = @COL1, Password = @COL2, INIT = @COL3"; // Populate with data from the record command.Parameters.AddWithValue("@COL1", new Guid()); command.Parameters.AddWithValue("@COL2", encryptedPassword); command.Parameters.AddWithValue("@COL3", true); // Write to database command.ExecuteNonQuery(); } _conn = SqliteManager.CloseConnection(shouldClose, connection); newPasswordAlert.Dispose(); var confirmPasswordAlert = new NSAlert() { AlertStyle = NSAlertStyle.Informational, InformativeText = "Remember this password, store it somewhere safe! You will not be able to recover it if lost.", MessageText = "Password sucessfully saved", }; confirmPasswordAlert.AddButton("OK"); var confirmResult = confirmPasswordAlert.RunModal(); if (confirmResult == 1000) { confirmPasswordAlert.Dispose(); } } else if (result == 1000 && originalPassword.StringValue != confirmedPassword.StringValue) { newPasswordAlert.AlertStyle = NSAlertStyle.Warning; newPasswordAlert.InformativeText = "Passwords do not match"; } }