Beispiel #1
0
        /// <summary>
        /// Finds and removes duplicate proxy entry in a PwGroup. (ca happen if the user shares
        /// a folder more than once)
        /// </summary>
        /// <returns>True if made changes.</returns>
        private Changes RemoveDuplicateProxies()
        {
            PwObjectList <PwEntry> allProxies = m_database.GetAllProxyNodes();

            allProxies.Sort(new PwProxyComparer());
            PwEntry lastEntry  = null;
            Changes changeFlag = Changes.None;

            foreach (PwEntry proxy in allProxies)
            {
                //we only have to compare the last and the actual pwEntry because they are sorted alphabetically
                if (AreEqualProxies(proxy, lastEntry))
                {
                    proxy.DeleteFrom(proxy.ParentGroup);
                    changeFlag |= Changes.EntryDeleted;
                }
                lastEntry = proxy;
            }
            return(changeFlag);
        }
Beispiel #2
0
        private void OnTrayOpening(object sender, EventArgs e)
        {
            PluginDebug.AddInfo("Tray setup: Start", 0);
            m_TrayMenu.DropDownItems.Clear();
            List <PwDatabase> lDB = m_host.MainWindow.DocumentManager.GetOpenDatabases();
            SearchParameters  sp  = new SearchParameters();

            sp.ExcludeExpired      = !Program.Config.Integration.AutoTypeExpiredCanMatch;        //exclude expired entries only if they can not match
            sp.SearchInStringNames = true;
            Dictionary <string, PwObjectList <PwEntry> > dEntries = new Dictionary <string, PwObjectList <PwEntry> >();

            foreach (PwDatabase db in lDB)
            {
                string dbName = UrlUtil.GetFileName(db.IOConnectionInfo.Path);
                if (!string.IsNullOrEmpty(db.Name))
                {
                    dbName = db.Name + " (" + dbName + ")";
                }
                PwObjectList <PwEntry> entries = new PwObjectList <PwEntry>();
                if (Config.UseDBForOTPSeeds(db))
                {
                    sp.SearchString = OTPDAO.OTPHandler_DB.DBNAME;
                }
                else
                {
                    sp.SearchString = Config.OTPFIELD;                     // Config.SEED + " " + Config.SETTINGS;
                }
                db.RootGroup.SearchEntries(sp, entries);

                PluginDebug.AddInfo("Tray setup: Check database", 0, "DB: " + dbName, "Entries: " + entries.UCount.ToString());
                if ((entries == null) || (entries.UCount == 0))
                {
                    continue;
                }
                //Ignore deleted entries
                PwGroup pgRecycle = db.RecycleBinEnabled ? db.RootGroup.FindGroup(db.RecycleBinUuid, true) : null;
                if (pgRecycle != null)
                {
                    for (int i = (int)entries.UCount - 1; i >= 0; i--)
                    {
                        PwEntry pe = entries.GetAt((uint)i);
                        if (pe.IsContainedIn(pgRecycle))
                        {
                            entries.Remove(pe);
                        }
                    }
                }
                entries.Sort(SortEntries);
                dEntries.Add(dbName, entries);
            }
            foreach (var kvp in dEntries)
            {
                ToolStripMenuItem parent = null;
                //If entries of only one DB are found don't include the DB as additional menu level
                if (dEntries.Count == 1)
                {
                    parent = m_TrayMenu;
                }
                else
                {
                    parent = new ToolStripMenuItem(kvp.Key);
                    m_TrayMenu.DropDownItems.Add(parent);
                }
                foreach (PwEntry pe in kvp.Value)
                {
                    ToolStripMenuItem entry = new ToolStripMenuItem();
                    string[]          text  = GetTrayText(pe);
                    PluginDebug.AddInfo("Tray setup: Add entry", 0, "Uuid: " + text[2]);                     // Do NOT add username and entry title to debugfile
                    if (text[0] == string.Empty)
                    {
                        entry.Text = StrUtil.EncodeMenuText(string.Format(PluginTranslate.User, text[1]));
                    }
                    else if (text[1] == string.Empty)
                    {
                        entry.Text = StrUtil.EncodeMenuText(text[0]);
                    }
                    else
                    {
                        entry.Text = StrUtil.EncodeMenuText(text[0] + " (" + text[1] + ")");
                    }
                    entry.Name   = "KPOTP_" + pe.Uuid.ToString();
                    entry.Click += OnOTPTray;
                    entry.Tag    = pe;
                    parent.DropDownItems.Add(entry);
                }
            }
            m_TrayMenu.Enabled = dEntries.Count > 0;
            m_TrayMenu.Text    = m_TrayMenu.Enabled ? PluginTranslate.OTPCopyTrayEntries : PluginTranslate.OTPCopyTrayNoEntries;
        }