예제 #1
0
        public Options()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
            Text           = PluginTranslate.PluginName;
            tpOptions.Text = PluginTranslate.OptionsCaption;
            tpHelp.Text    = KeePass.Resources.KPRes.Description;
            AdjustCheckBox(cbSearchForm, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchForm));
            AdjustCheckBox(cbSearchLastMod, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchLastMod));
            AdjustCheckBox(cbSearchLarge, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchLargeEntries));
            AdjustCheckBox(cbSearchDupPw, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchDupPw));
            AdjustCheckBox(cbSearchPwPairs, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordPairs));
            AdjustCheckBox(cbSearchPwCluster, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordClusters));
            AdjustCheckBox(cbSearchPwQuality, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordQuality));
            AdjustCheckBox(cbSearchPwQuality, SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchPasswordQuality));

            FindInfo fiExpired = SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchExpired);

            cbSearchAllExpired.Enabled = fiExpired.StandardMethod != null;
            cbSearchAllExpired.Text    = KeePass.Resources.KPRes.ExpiredEntries;

            cbMultiDBSearchInfoSearchFormActive.Text   = string.Format(PluginTranslate.MultiDBSearchInfoSearchFormActive, cbSearchForm.Text);
            cbMultiDBSearchInfoSingleSearchActive.Text = PluginTranslate.MultiDBSearchInfoSingleSearchActive;
            string sDesc = string.Format(PluginTranslate.Description, PluginTranslate.PluginName, cbSearchForm.Text);

            tbDesc.Lines = sDesc.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
        }
예제 #2
0
        private static void PrepareFindInfoItem(FindInfo fi)
        {
            if (string.IsNullOrEmpty(fi.OptionsText))
            {
                if (string.IsNullOrEmpty(fi.Title))
                {
                    fi.OptionsText = fi.Name;
                }
                else
                {
                    fi.OptionsText = fi.Title;
                }
            }

            if (fi.SearchType != SearchType.QuickFind)
            {
                try { fi.tsiMenuItem = Tools.FindToolStripMenuItem(KeePass.Program.MainForm.MainMenu.Items, fi.Name, true); }
                catch { }
                if (fi.tsiMenuItem == null)
                {
                    return;
                }

                fi.OptionsText = fi.tsiMenuItem.Text;
                fi.img         = fi.tsiMenuItem.Image;
            }

            if (fi.SearchType == SearchType.BuiltIn)
            {
                Assembly a = typeof(KeePass.Program).Assembly;
                Type     t = a.GetType("KeePass.Util.EntryUtil");
                fi.StandardMethod = t.GetMethod(fi.Func, BindingFlags.Static | BindingFlags.NonPublic);
            }
            else if (fi.SearchType == SearchType.Expiring)
            {
                if (!string.IsNullOrEmpty(fi.OptionsText))
                {
                    fi.Title = fi.OptionsText;
                    try { fi.Title = fi.tsiMenuItem.OwnerItem.Text + " - " + fi.OptionsText; }
                    catch { }
                    fi.Title = KeePassLib.Utility.StrUtil.RemoveAccelerator(fi.Title);
                }
                fi.StandardMethod = typeof(SearchHelp).GetMethod("FindWrapper", BindingFlags.Static | BindingFlags.NonPublic);
            }
        }
예제 #3
0
 private bool CallStandardSearch(FindInfo fi, string sendername)
 {
     if (fi == null)
     {
         PluginDebug.AddError("Call standard find routine", 0, "Reason for standard call: FindInfo empty", "Event sender: " + sendername);
         return(true);
     }
     if (fi.StandardMethod == null)
     {
         PluginDebug.AddError("Call standard find routine", 0, "Action: " + fi.Name, "Reason for standard call: No hook for " + fi.Name);
         return(true);
     }
     if (m_host.MainWindow.DocumentManager.GetOpenDatabases().Count < 2)
     {
         PluginDebug.AddInfo("Call standard find routine", 0, "Action: " + fi.Name, "Reason for standard call: No more than one db opened");
         return(true);
     }
     return(false);
 }
예제 #4
0
        public override bool Initialize(IPluginHost host)
        {
            m_host = host;
            PluginTranslate.Init(this, KeePass.Program.Translation.Properties.Iso6391Code);
            Tools.DefaultCaption = PluginTranslate.PluginName;
            Tools.PluginURL      = "https://github.com/rookiestyle/globalsearch/";

            GetStandardMethods();

            m_lvEntries = (ListView)Tools.GetControl("m_lvEntries");
            if (m_lvEntries == null)
            {
                PluginDebug.AddError("Could not get 'm_lvEntries'", 0);
            }

            Tools.OptionsFormShown  += Tools_OptionsFormShown;
            Tools.OptionsFormClosed += Tools_OptionsFormClosed;

            Activate();
            FindInfo fi = SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchForm);

            if (fi != null)
            {
                m_img = fi.img;
            }
            if (m_img == null)
            {
                try { m_img = (Image)KeePass.Program.Resources.GetObject("B16x16_XMag"); }
                catch { }
            }
            if (m_img == null)
            {
                m_img = m_host.MainWindow.ClientIcons.Images[(int)PwIcon.EMailSearch];
            }

            m_menu        = new ToolStripMenuItem();
            m_menu.Click += OnShowOptions;
            m_menu.Text   = PluginTranslate.PluginName + "...";
            m_menu.Image  = m_img;
            m_host.MainWindow.ToolsMenu.DropDownItems.Add(m_menu);

            return(true);
        }
예제 #5
0
        private void OnSelectAllDB_CheckedChanged(object sender, EventArgs e)
        {
            if ((m_cbSearchAllDatabases == null) || !m_cbSearchAllDatabases.Enabled)
            {
                return;
            }
            FindInfo fi = SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchForm);

            Config.SearchFormGlobalSession = m_cbSearchAllDatabases.Checked;
            if (m_cbSearchAllDatabases.Checked)
            {
                fi.StandardEventHandlers = m_btnOK.GetEventHandlers("Click");
                List <string> lInfos = new List <string>();
                foreach (Delegate d in fi.StandardEventHandlers)
                {
                    lInfos.Add(d.Method.DeclaringType.FullName + " " + d.Method.Name);
                }
                lInfos.Insert(0, "Count: " + lInfos.Count.ToString());
                lInfos.Insert(0, fi.ToString());
                PluginDebug.AddInfo("Replaced eventhandler", 0, lInfos.ToArray());
                m_btnOK.RemoveEventHandlers("Click", fi.StandardEventHandlers);
                m_btnOK.Click += OnSearchExecute;
                if (fi.StandardEventHandlers.Count == 0)
                {
                    m_btnOK.DialogResult = DialogResult.None;
                    m_sf.AcceptButton    = null;
                }
            }
            else
            {
                m_btnOK.Click -= OnSearchExecute;
                m_btnOK.AddEventHandlers("Click", fi.StandardEventHandlers);
                PluginDebug.AddInfo("Restored eventhandler", 0);
                m_btnOK.DialogResult = DialogResult.OK;
                m_sf.AcceptButton    = m_btnOK;
            }
        }
예제 #6
0
 private void AdjustCheckBox(CheckBox cbBox, FindInfo fiInfo)
 {
     cbBox.Text    = fiInfo.OptionsText.Replace("&", string.Empty);
     cbBox.Enabled = fiInfo.StandardMethod != null || (fiInfo.Name == SearchHelp.SearchForm);
 }
예제 #7
0
        private void OnClickFindEntry(object sender, EventArgs e)
        {
            string   f  = (sender as ToolStripItem).Name;
            FindInfo fi = SearchHelp.FindList.Find(x => x.Name == (sender as ToolStripItem).Name);

            if (CallStandardSearch(fi, (sender as ToolStripItem).Name))
            {
                if (fi != null)
                {
                    foreach (Delegate d in fi.StandardEventHandlers)
                    {
                        d.DynamicInvoke(new object[] { sender, e });
                    }
                }
                return;
            }

            PluginDebug.AddInfo("Call own find routine", 0, "Action: " + f);
            //Show status logger
            Form          fOptDialog = null;
            IStatusLogger sl         = StatusUtil.CreateStatusDialog(m_host.MainWindow, out fOptDialog, null,
                                                                     (KPRes.SearchingOp ?? "..."), true, false);

            m_host.MainWindow.UIBlockInteraction(true);

            m_aStandardLvInit = null;

            //Perform find for all open databases
            PwDatabase    dbAll = MergeDatabases();
            List <object> l     = null;

            try
            {
                object[] parameters;
                if (fi.SearchType != SearchType.BuiltIn)
                {
                    parameters = new object[] { dbAll, sl, null, fi }
                }
                ;
                else
                {
                    parameters = new object[] { dbAll, sl, null }
                };

                l = (List <object>)fi.StandardMethod.Invoke(m_host, parameters);
                m_aStandardLvInit = (Action <ListView>)parameters[2];
            }
            catch (Exception ex)
            {
                l = null;
                PluginDebug.AddError("Call standard find routine", 0, "Action: " + f, "Reason for standard call: " + ex.Message);
                foreach (Delegate d in fi.StandardEventHandlers)
                {
                    d.DynamicInvoke(new object[] { sender, e });
                }
            }
            finally { dbAll.Close(); }

            m_host.MainWindow.UIBlockInteraction(false);
            sl.EndLogging();

            if (l == null)
            {
                return;
            }

            //Fill db column
            ImageList il  = new ImageList();
            ImageList il2 = (ImageList)Tools.GetField("m_ilCurrentIcons", m_host.MainWindow);

            foreach (Image img in il2.Images)
            {
                il.Images.Add(img);
            }

            foreach (var o in l)
            {
                ListViewItem lvi = o as ListViewItem;
                if (lvi == null)
                {
                    continue;
                }
                ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem();
                if (lvi.Tag is PwEntry)
                {
                    lvsi.Text = SearchHelp.GetDBName(lvi.Tag as PwEntry);
                    PwEntry    pe = lvi.Tag as PwEntry;
                    PwDatabase db = m_host.MainWindow.DocumentManager.FindContainerOf(pe);
                    if (!pe.CustomIconUuid.Equals(PwUuid.Zero))
                    {
                        il.Images.Add(db.GetCustomIcon(pe.CustomIconUuid, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16)));
                        lvi.ImageIndex = il.Images.Count - 1;
                    }
                    else
                    {
                        lvi.ImageIndex = (int)pe.IconId;
                    }
                }
                else if (lvi.Tag is PwGroup)
                {
                    PwGroup pg = lvi.Tag as PwGroup;
                    lvsi.Text = SearchHelp.GetDBName(pg.Entries.GetAt(0));
                }
                lvi.SubItems.Insert(0, lvsi);
            }

            if ((l.Count == 0) && !string.IsNullOrEmpty(fi.NothingFound))
            {
                Tools.ShowInfo(fi.NothingFound);
                il.Dispose();
                return;
            }

            //Show results
            ListViewForm dlg = new ListViewForm();

            //Prepare ImageList (CustomIcons can be different per database)
            dlg.InitEx(fi.Title, fi.SubTitle, fi.Note, fi.img, l, il, InitListView);
            UIUtil.ShowDialogAndDestroy(dlg);
            if (dlg.DialogResult != DialogResult.OK)
            {
                return;
            }
            il.Dispose();
            NavigateToSelectedEntry(dlg, false);
        }
예제 #8
0
        private void OnSearchExecute(object sender, EventArgs e)
        {
            //Perform search in all open databases
            m_dDBGroups = new Dictionary <PwDatabase, PwGroup>();
            PwGroup           g       = null;
            List <PwDatabase> lOpenDB = m_host.MainWindow.DocumentManager.GetOpenDatabases();

            m_btnOK.Click -= OnSearchExecute;
            List <string> lMsg = new List <string>();

            foreach (PwDatabase db in lOpenDB)
            {
                lMsg.Clear();
                lMsg.Add("DB: " + db.IOConnectionInfo.Path);
                if ((m_sf != null) && (m_sf.SearchResultsGroup != null) && (m_sf.SearchResultsGroup.Entries != null))
                {
                    lMsg.Add("Previos search results cleared: " + true.ToString());
                    m_sf.SearchResultsGroup.Entries.Clear();
                }
                m_sf.InitEx(db, db.RootGroup);
                FindInfo fi = SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchForm);
                if (fi.StandardEventHandlers.Count > 0)
                {
                    using (MonoWorkaroundDialogResult mwaDR = new MonoWorkaroundDialogResult(sender))
                    {
                        foreach (Delegate onclick in fi.StandardEventHandlers)
                        {
                            lMsg.Add("Calling method: " + onclick.Method.Name + " - " + onclick.Method.ReflectedType.Name);
                            onclick.DynamicInvoke(new object[] { sender, e });
                        }
                    }
                }
                else
                {
                    lMsg.Add("Calling standard method");
                    m_btnOK.PerformClick();
                }
                if ((m_sf.SearchResultsGroup == null) || (m_sf.SearchResultsGroup.Entries == null))
                {
                    lMsg.Add("Found entries: 0");
                }
                else
                {
                    lMsg.Add("Found entries: " + m_sf.SearchResultsGroup.Entries.UCount.ToString());
                }

                //Do NOT use m_sf.SearchResultsGroup.CloneDeep
                //It makes the virtual SearchResultsGroup the
                //parent group of the found entries
                if (g == null)
                {
                    g = new PwGroup(true, true, m_sf.SearchResultsGroup.Name, m_sf.SearchResultsGroup.IconId);
                }
                foreach (PwEntry pe in m_sf.SearchResultsGroup.Entries)
                {
                    g.AddEntry(pe, false);
                }
                PluginDebug.AddInfo("Executing search", 0, lMsg.ToArray());
            }

            //Don't continue if not even a single entry was found
            if ((g == null) || (g.GetEntriesCount(true) == 0))
            {
                if (m_sf.DialogResult == DialogResult.None)
                {
                    m_sf.DialogResult = DialogResult.OK;
                }
                return;
            }
            //Prepare ImageList (CustomIcons can be different per database)
            ImageList il  = new ImageList();
            ImageList il2 = (ImageList)Tools.GetField("m_ilCurrentIcons", m_host.MainWindow);

            foreach (Image img in il2.Images)
            {
                il.Images.Add(img);
            }
            Dictionary <PwEntry, int> dEntryIconIndex = new Dictionary <PwEntry, int>();
            PwDatabase dbFirst     = null;
            bool       bMultipleDB = false;

            foreach (PwEntry pe in g.Entries)
            {
                PwDatabase db = m_host.MainWindow.DocumentManager.FindContainerOf(pe);
                if (db == null)
                {
                    PluginDebug.AddError("Could not get database for entry", 0, pe.Uuid.ToHexString());
                    continue;
                }
                if (!m_dDBGroups.ContainsKey(db))
                {
                    m_dDBGroups[db] = new PwGroup(true, false, SearchHelp.GetDBName(pe), PwIcon.Folder)
                    {
                        IsVirtual = true
                    }
                }
                ;
                m_dDBGroups[db].AddEntry(pe, false);
                if (dbFirst == null)
                {
                    dbFirst = db;
                }
                bMultipleDB |= db != dbFirst;
                if (!pe.CustomIconUuid.Equals(PwUuid.Zero))
                {
                    il.Images.Add(db.GetCustomIcon(pe.CustomIconUuid, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16)));
                    dEntryIconIndex[pe] = dEntryIconIndex.Count - 1;
                }
                else
                {
                    dEntryIconIndex[pe] = (int)pe.IconId;
                }
            }

            //If all found entries are contained in the same database
            //simply activate this database (might not be active yet) and return
            if (!bMultipleDB)
            {
                PwGroup pgSF = (PwGroup)Tools.GetField("m_pgResultsGroup", m_sf);
                if (pgSF != null)
                {
                    //clear list of found entries
                    //otherwise duplicates might be shown if last searched db is the only one that is to be shown
                    pgSF.Entries.Clear();
                    pgSF.Entries.Add(g.Entries);
                }
                else                 //KeePass 2.47
                {
                    pgSF           = new PwGroup(true, true, g.Name, g.IconId);
                    pgSF.IsVirtual = true;
                    pgSF.Entries.Add(g.Entries);
                }
                PluginDebug.AddInfo("Found " + pgSF.Entries.UCount.ToString() + " entries in 1 database");
                m_host.MainWindow.UpdateUI(false, m_host.MainWindow.DocumentManager.FindDocument(dbFirst), true, pgSF, false, null, false);
                il.Dispose();
                m_sf.SearchResultsGroup.Entries.Clear();
                m_sf.SearchResultsGroup.Entries.Add(pgSF.Entries);
                m_sf.DialogResult = DialogResult.OK;
                return;
            }

            //We found entries from at least 2 databases
            //Show the results in ListViewForm and close SearchForm
            try
            {
                PluginDebug.AddInfo("Found " + g.Entries.UCount.ToString() + " entries in multiple database");
                m_sf.DialogResult = DialogResult.Abort;
                m_sf.Visible      = false;
                m_sf.Close();
            }
            catch (Exception ex)
            {
                PluginDebug.AddError("Error closing searchform", new string[] { ex.Message });
            }

            m_aStandardLvInit = InitListViewMain;
            List <object> l = GetFoundEntriesList(g, dEntryIconIndex);

            ListViewForm dlg       = new ListViewForm();
            int          iCount    = l.FindAll(x => (x as ListViewItem) != null).Count;
            string       sSubTitle = iCount == 1 ? KPRes.SearchEntriesFound1 : KPRes.SearchEntriesFound;

            sSubTitle = sSubTitle.Replace("{PARAM}", iCount.ToString());
            dlg.InitEx(KPRes.Search, sSubTitle, null, null, l, il, InitListView);
            ShowMultiDBInfo(true);
            PluginDebug.AddInfo("Multi-DB results: Show", 0);
            if (dlg.ShowDialog(m_host.MainWindow) != DialogResult.OK)
            {
                PluginDebug.AddInfo("Multi-DB results: Shown", 0);
                UIUtil.DestroyForm(dlg);
                return;
            }
            PluginDebug.AddInfo("Multi-DB results: Show and navigate", 0);
            il.Dispose();
            NavigateToSelectedEntry(dlg, true);
            PluginDebug.AddInfo("Multi-DB results: Dispose form", 0);
            UIUtil.DestroyForm(dlg);
            PluginDebug.AddInfo("Multi-DB results: Disposed form", 0);
        }
예제 #9
0
        internal static List <object> FindWrapper(KeePassLib.PwDatabase db,
                                                  IStatusLogger sl, out Action <ListView> fInit, FindInfo fi)
        {
            if (fi.Name == SearchExpired)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, true, 0, 0));
            }
            else if (fi.Name == SearchExpired_1D)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, false, 1, 0));
            }
            else if (fi.Name == SearchExpired_2D)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, false, 2, 0));
            }
            else if (fi.Name == SearchExpired_3D)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, false, 3, 0));
            }
            else if (fi.Name == SearchExpired_7D)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, false, 7, 0));
            }
            else if (fi.Name == SearchExpired_14D)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, false, 14, 0));
            }
            else if (fi.Name == SearchExpired_1M)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, false, 0, 1));
            }
            else if (fi.Name == SearchExpired_2M)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, false, 0, 2));
            }
            else if (fi.Name == SearchExpired_F)
            {
                return(SpecialSearches.SearchExpired.FindExpired(db, sl, out fInit, false, int.MaxValue, 0));
            }

            List <object> l = null;

            fInit = null;
            return(l);
        }