private bool HasAccounts() { if (_configService.Accounts.Any()) { return(true); } var result = MessageService.Ask( "At least one account is required to work with KeeAnywhere.\r\nWould you like to open KeeAnywhere Settings to create a new account?", "KeeAnywhere", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { _uiService.ShowSettingsDialog(); } return(false); //AccountConfiguration account = null; //while (account == null) //{ // account = await _uiService.CreateOrUpdateAccount(StorageType.OneDrive); // if (account != null) continue; // var result = MessageService.Ask("You did not created a new account.\nAt least one account is required to work with KeeAnywhere.", "KeeAnywhere", MessageBoxButtons.RetryCancel); // if (result != DialogResult.Retry) // { // return false; // } //} //return true; }
private void OnFormClosing(object sender, FormClosingEventArgs e) { if (m_bModified) { DialogResult dr = MessageService.Ask(KPRes.SaveBeforeCloseQuestion, PwDefs.ShortProductName, MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Yes) { OnFileSave(sender, EventArgs.Empty); } else if (dr == DialogResult.No) { } else { e.Cancel = true; return; } } if (m_bURtfWithHighChar && (m_pbEditedData != null) && !MemUtil.ArraysEqual(m_pbEditedData, m_pbData)) { string strUrl = AppHelp.GetOnlineUrl(AppDefs.HelpTopics.KbFaq, AppDefs.HelpTopics.KbFaqURtf); string strLink = VistaTaskDialog.CreateLink(strUrl, strUrl); string strMsg = KPRes.URtfProblem + MessageService.NewParagraph + KPRes.URtfCheck + MessageService.NewParagraph + KPRes.URtfSuggestion + MessageService.NewParagraph + KPRes.MoreInfo + ":" + MessageService.NewLine; VistaTaskDialog dlg = new VistaTaskDialog(); dlg.AddButton((int)DialogResult.Cancel, KPRes.Ok, null); dlg.CommandLinks = false; dlg.Content = strMsg + strLink; dlg.DefaultButtonID = (int)DialogResult.Cancel; dlg.EnableHyperlinks = true; dlg.SetIcon(VtdIcon.Warning); dlg.WindowTitle = PwDefs.ShortProductName; if (!dlg.ShowDialog()) { MessageService.ShowWarning(strMsg + strUrl); } } Debug.Assert(m_uBlockEvents == 0); string strRect = UIUtil.GetWindowScreenRect(this); if (strRect != m_strInitialFormRect) // Don't overwrite "" { Program.Config.UI.DataEditorRect = strRect; } m_ctxText.Detach(); GlobalWindowManager.RemoveWindow(this); }
public static void FindDatabaseFiles(MainForm mf, string strRootPath) { if (mf == null) { Debug.Assert(false); return; } Debug.Assert(GlobalWindowManager.TopWindow == null); // mf should be parent VistaTaskDialog dlg = new VistaTaskDialog(); dlg.CommandLinks = true; dlg.Content = KPRes.FileSearchModes + MessageService.NewParagraph + KPRes.QuickSearchQ; dlg.DefaultButtonID = (int)DialogResult.Yes; dlg.WindowTitle = PwDefs.ShortProductName; dlg.SetIcon(VtdCustomIcon.Question); dlg.AddButton((int)DialogResult.Yes, KPRes.Quick, KPRes.FileSearchQuickDesc); dlg.AddButton((int)DialogResult.No, KPRes.Normal, KPRes.FileSearchNormalDesc); dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, null); int dr; if (dlg.ShowDialog(mf)) { dr = dlg.Result; } else { dr = (int)MessageService.Ask(KPRes.FileSearchModes + MessageService.NewParagraph + KPRes.Quick + ": " + KPRes.FileSearchQuickDesc + MessageService.NewParagraph + KPRes.Normal + ": " + KPRes.FileSearchNormalDesc + MessageService.NewParagraph + KPRes.QuickSearchQ, PwDefs.ShortProductName, MessageBoxButtons.YesNoCancel); } FsxMatchFn fMatch; if (dr == (int)DialogResult.Yes) { fMatch = MatchDatabaseFileQuick; } else if (dr == (int)DialogResult.No) { fMatch = MatchDatabaseFileContent; } else { return; } string strFile = FindUI(mf, fMatch, strRootPath); if (!string.IsNullOrEmpty(strFile)) { mf.OpenDatabase(IOConnectionInfo.FromPath(strFile), null, true); } }
private static bool AskForRetry(string strObj, string strText) { string strContent = strObj + MessageService.NewParagraph + strText; int i = VistaTaskDialog.ShowMessageBoxEx(strContent, null, PwDefs.ShortProductName, VtdIcon.Warning, null, KPRes.RetryCmd, (int)DialogResult.Retry, KPRes.Cancel, (int)DialogResult.Cancel); if (i < 0) { i = (int)MessageService.Ask(strContent, PwDefs.ShortProductName, MessageBoxButtons.RetryCancel); } return((i == (int)DialogResult.Retry) || (i == (int)DialogResult.Yes) || (i == (int)DialogResult.OK)); }
/// <summary> /// Save all attachments of an array of entries to a directory. /// </summary> /// <param name="vEntries">Array of entries whose attachments are extracted and saved.</param> /// <param name="strBasePath">Directory in which the attachments are stored.</param> public static void SaveEntryAttachments(PwEntry[] vEntries, string strBasePath) { Debug.Assert(vEntries != null); if (vEntries == null) { return; } Debug.Assert(strBasePath != null); if (strBasePath == null) { return; } string strPath = UrlUtil.EnsureTerminatingSeparator(strBasePath, false); bool bCancel = false; foreach (PwEntry pe in vEntries) { foreach (KeyValuePair <string, ProtectedBinary> kvp in pe.Binaries) { string strFile = strPath + kvp.Key; if (File.Exists(strFile)) { string strMsg = KPRes.FileExistsAlready + MessageService.NewLine; strMsg += strFile + MessageService.NewParagraph; strMsg += KPRes.OverwriteExistingFileQuestion; DialogResult dr = MessageService.Ask(strMsg, null, MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Cancel) { bCancel = true; break; } else if (dr == DialogResult.Yes) { try { File.Delete(strFile); } catch (Exception exDel) { MessageService.ShowWarning(strFile, exDel); continue; } } else { continue; // DialogResult.No } } byte[] pbData = kvp.Value.ReadData(); try { File.WriteAllBytes(strFile, pbData); } catch (Exception exWrite) { MessageService.ShowWarning(strFile, exWrite); } MemUtil.ZeroByteArray(pbData); } if (bCancel) { break; } } }
public static DialogResult ShowFileSaveQuestion(string strFile, FileSaveOrigin fsOrigin) { bool bFile = ((strFile != null) && (strFile.Length > 0)); if (WinUtil.IsAtLeastWindowsVista) { VistaTaskDialog dlg = new VistaTaskDialog(); string strText = KPRes.DatabaseModifiedNoDot; if (bFile) { strText += ":\r\n" + strFile; } else { strText += "."; } dlg.CommandLinks = true; dlg.WindowTitle = PwDefs.ShortProductName; dlg.Content = strText; dlg.SetIcon(VtdCustomIcon.Question); bool bShowCheckBox = true; if (fsOrigin == FileSaveOrigin.Locking) { dlg.MainInstruction = KPRes.FileSaveQLocking; dlg.AddButton((int)DialogResult.Yes, KPRes.SaveCmd, KPRes.FileSaveQOpYesLocking); dlg.AddButton((int)DialogResult.No, KPRes.DiscardChangesCmd, KPRes.FileSaveQOpNoLocking); dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel + " " + KPRes.FileSaveQOpCancelLocking); } else if (fsOrigin == FileSaveOrigin.Exiting) { dlg.MainInstruction = KPRes.FileSaveQExiting; dlg.AddButton((int)DialogResult.Yes, KPRes.SaveCmd, KPRes.FileSaveQOpYesExiting); dlg.AddButton((int)DialogResult.No, KPRes.DiscardChangesCmd, KPRes.FileSaveQOpNoExiting); dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel + " " + KPRes.FileSaveQOpCancelExiting); } else { dlg.MainInstruction = KPRes.FileSaveQClosing; dlg.AddButton((int)DialogResult.Yes, KPRes.SaveCmd, KPRes.FileSaveQOpYesClosing); dlg.AddButton((int)DialogResult.No, KPRes.DiscardChangesCmd, KPRes.FileSaveQOpNoClosing); dlg.AddButton((int)DialogResult.Cancel, KPRes.Cancel, KPRes.FileSaveQOpCancel + " " + KPRes.FileSaveQOpCancelClosing); bShowCheckBox = false; } if (Program.Config.Application.FileClosing.AutoSave) { bShowCheckBox = false; } if (bShowCheckBox) { dlg.VerificationText = KPRes.AutoSaveAtExit; } if (dlg.ShowDialog()) { if (bShowCheckBox && (dlg.Result == (int)DialogResult.Yes)) { Program.Config.Application.FileClosing.AutoSave = dlg.ResultVerificationChecked; } return((DialogResult)dlg.Result); } } string strMessage = (bFile ? (strFile + MessageService.NewParagraph) : string.Empty); strMessage += KPRes.DatabaseModifiedNoDot + "." + MessageService.NewParagraph + KPRes.SaveBeforeCloseQuestion; return(MessageService.Ask(strMessage, KPRes.SaveBeforeCloseTitle, MessageBoxButtons.YesNoCancel)); }
// Copied from PwEntryForm.BinImportFiles (PwEntryForm.cs), as the functionality isn't otherwise exposed. private void BinImportFiles(string[] vPaths) { var m_vBinaries = Entry.Binaries; // Allow copied code to refer directly to entry binaries if (vPaths == null) { Debug.Assert(false); return; } //UpdateEntryBinaries(true, false); foreach (string strFile in vPaths) { if (string.IsNullOrEmpty(strFile)) { Debug.Assert(false); continue; } byte[] vBytes = null; string strMsg, strItem = UrlUtil.GetFileName(strFile); if (m_vBinaries.Get(strItem) != null) { strMsg = KPRes.AttachedExistsAlready + MessageService.NewLine + strItem + MessageService.NewParagraph + KPRes.AttachNewRename + MessageService.NewParagraph + KPRes.AttachNewRenameRemarks0 + MessageService.NewLine + KPRes.AttachNewRenameRemarks1 + MessageService.NewLine + KPRes.AttachNewRenameRemarks2; DialogResult dr = MessageService.Ask(strMsg, null, MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Cancel) { continue; } else if (dr == DialogResult.Yes) { string strFileName = UrlUtil.StripExtension(strItem); string strExtension = "." + UrlUtil.GetExtension(strItem); int nTry = 0; while (true) { string strNewName = strFileName + nTry.ToString() + strExtension; if (m_vBinaries.Get(strNewName) == null) { strItem = strNewName; break; } ++nTry; } } } try { vBytes = File.ReadAllBytes(strFile); //vBytes = DataEditorForm.ConvertAttachment(strItem, vBytes); vBytes = ConvertAttachment(strItem, vBytes); if (vBytes != null) { ProtectedBinary pb = new ProtectedBinary(false, vBytes); m_vBinaries.Set(strItem, pb); } } catch (Exception exAttach) { MessageService.ShowWarning(KPRes.AttachFailed, strFile, exAttach); } } //UpdateEntryBinaries(false, true); //ResizeColumnHeaders(); }