示例#1
0
        internal static string ShowKeyFileDialog(bool bSaveMode, string strTitle,
                                                 string strSuggestedFileName, bool bAllFilesByDefault, bool bSecureDesktop)
        {
            Debug.Assert(!bSaveMode || !bAllFilesByDefault);             // Not all files when saving

            string strFilter    = AppDefs.GetKeyFileFilter();
            int    iFilterIndex = (bAllFilesByDefault ? 2 : 1);
            string strExt       = (bSaveMode ? AppDefs.FileExtension.KeyFile : null);
            string strContext   = AppDefs.FileDialogContext.KeyFile;

            return(ShowFileDialog(bSaveMode, strTitle, strSuggestedFileName,
                                  strFilter, iFilterIndex, strExt, strContext, bSecureDesktop));
        }
        private string GetKeyFilePath()
        {
            string strExt    = AppDefs.FileExtension.KeyFile;
            string strFilter = AppDefs.GetKeyFileFilter();

            string strName = UrlUtil.StripExtension(UrlUtil.GetFileName(m_ioInfo.Path));

            if (string.IsNullOrEmpty(strName))
            {
                strName = KPRes.KeyFileSafe;
            }

            SaveFileDialogEx sfd = UIUtil.CreateSaveFileDialog(KPRes.KeyFileCreateTitle,
                                                               strName + "." + strExt, strFilter, 1, strExt, AppDefs.FileDialogContext.KeyFile);

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                return(sfd.FileName);
            }
            return(null);
        }
示例#3
0
        private void OnClickKeyFileBrowse(object sender, EventArgs e)
        {
            string strFile = null;

            if (m_bSecureDesktop)
            {
                FileBrowserForm dlg = new FileBrowserForm();
                dlg.InitEx(false, KPRes.KeyFileSelect, KPRes.SecDeskFileDialogHint,
                           AppDefs.FileDialogContext.KeyFile);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    strFile = dlg.SelectedFile;
                }
                UIUtil.DestroyForm(dlg);
            }
            else
            {
                string           strFilter = AppDefs.GetKeyFileFilter();
                OpenFileDialogEx ofd       = UIUtil.CreateOpenFileDialog(KPRes.KeyFileSelect,
                                                                         strFilter, 2, null, false, AppDefs.FileDialogContext.KeyFile);

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    strFile = ofd.FileName;
                }
            }

            if (!string.IsNullOrEmpty(strFile))
            {
                if ((Program.Config.UI.KeyPromptFlags &
                     (ulong)AceKeyUIFlags.UncheckKeyFile) == 0)
                {
                    UIUtil.SetChecked(m_cbKeyFile, true);
                }

                AddKeyFileSuggPriv(strFile, true);
            }

            EnableUserControls();
        }
示例#4
0
        private void OnClickKeyFileBrowse(object sender, EventArgs e)
        {
            string           strFilter = AppDefs.GetKeyFileFilter();
            OpenFileDialogEx ofd       = UIUtil.CreateOpenFileDialog(KPRes.KeyFileUseExisting,
                                                                     strFilter, 1, null, false, AppDefs.FileDialogContext.KeyFile);

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string strFile = ofd.FileName;

            try
            {
                // Test whether we can read the file
                IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile);
                IOConnection.OpenRead(ioc).Close();

                // Check the file size?
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); return; }

            if (!KfxFile.CanLoad(strFile))
            {
                if (!MessageService.AskYesNo(strFile + MessageService.NewParagraph +
                                             KPRes.KeyFileNoXml + MessageService.NewParagraph +
                                             KPRes.KeyFileUseAnywayQ, null, false))
                {
                    return;
                }
            }

            m_cmbKeyFile.Items.Add(strFile);
            m_cmbKeyFile.SelectedIndex = m_cmbKeyFile.Items.Count - 1;

            EnableUserControls();
        }
示例#5
0
        /// <summary>
        /// Fill a <c>ListView</c> with password entries.
        /// </summary>
        /// <param name="lv"><c>ListView</c> to fill.</param>
        /// <param name="vEntries">Entries.</param>
        /// <param name="vColumns">Columns of the <c>ListView</c>. The first
        /// parameter of the key-value pair is the internal string field name,
        /// and the second one the text displayed in the column header.</param>
        public static void CreateEntryList(ListView lv, IEnumerable <PwEntry> vEntries,
                                           List <KeyValuePair <string, string> > vColumns, ImageList ilIcons)
        {
            if (lv == null)
            {
                throw new ArgumentNullException("lv");
            }
            if (vEntries == null)
            {
                throw new ArgumentNullException("vEntries");
            }
            if (vColumns == null)
            {
                throw new ArgumentNullException("vColumns");
            }
            if (vColumns.Count == 0)
            {
                throw new ArgumentException();
            }

            lv.BeginUpdate();

            lv.Items.Clear();
            lv.Columns.Clear();
            lv.ShowGroups     = true;
            lv.SmallImageList = ilIcons;

            foreach (KeyValuePair <string, string> kvp in vColumns)
            {
                lv.Columns.Add(kvp.Value);
            }

            DocumentManagerEx dm    = Program.MainForm.DocumentManager;
            ListViewGroup     lvg   = new ListViewGroup(Guid.NewGuid().ToString());
            DateTime          dtNow = DateTime.Now;
            bool bFirstEntry        = true;

            foreach (PwEntry pe in vEntries)
            {
                if (pe == null)
                {
                    Debug.Assert(false); continue;
                }

                if (pe.ParentGroup != null)
                {
                    string strGroup = pe.ParentGroup.GetFullPath();

                    if (strGroup != lvg.Header)
                    {
                        lvg = new ListViewGroup(strGroup, HorizontalAlignment.Left);
                        lv.Groups.Add(lvg);
                    }
                }

                ListViewItem lvi = new ListViewItem(AppDefs.GetEntryField(pe, vColumns[0].Key));

                if (pe.Expires && (pe.ExpiryTime <= dtNow))
                {
                    lvi.ImageIndex = (int)PwIcon.Expired;
                }
                else if (pe.CustomIconUuid == PwUuid.Zero)
                {
                    lvi.ImageIndex = (int)pe.IconId;
                }
                else
                {
                    lvi.ImageIndex = (int)pe.IconId;

                    foreach (DocumentStateEx ds in dm.Documents)
                    {
                        int nInx = ds.Database.GetCustomIconIndex(pe.CustomIconUuid);
                        if (nInx > -1)
                        {
                            ilIcons.Images.Add((Image)ds.Database.GetCustomIcon(
                                                   pe.CustomIconUuid).Clone());
                            lvi.ImageIndex = ilIcons.Images.Count - 1;
                            break;
                        }
                    }
                }

                for (int iCol = 1; iCol < vColumns.Count; ++iCol)
                {
                    lvi.SubItems.Add(AppDefs.GetEntryField(pe, vColumns[iCol].Key));
                }

                lvi.Tag = pe;

                lv.Items.Add(lvi);
                lvg.Items.Add(lvi);

                if (bFirstEntry)
                {
                    lvi.Selected = true;
                    lvi.Focused  = true;

                    bFirstEntry = false;
                }
            }

            int nColWidth = (lv.ClientRectangle.Width - GetVScrollBarWidth()) /
                            vColumns.Count;

            foreach (ColumnHeader ch in lv.Columns)
            {
                ch.Width = nColWidth;
            }

            lv.EndUpdate();
        }