예제 #1
0
 public static bool IsEntryInRecycleBin(this PwDatabase db, PwEntry entry)
 {
     if (db.RecycleBinEnabled)
     {
         return(entry.IsContainedIn(db.GetRecycleBinGroup()));
     }
     return(false);
 }
예제 #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;
        }
예제 #3
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();
            Dictionary <string, List <PwEntry> > dEntries = new Dictionary <string, List <PwEntry> >();
            DateTime dtExpired = DateTime.UtcNow;

            foreach (PwDatabase db in lDB)
            {
                string dbName = UrlUtil.GetFileName(db.IOConnectionInfo.Path);
                if (!string.IsNullOrEmpty(db.Name))
                {
                    dbName = db.Name + " (" + dbName + ")";
                }
                string sSearch = Config.UseDBForOTPSeeds(db) ? OTPDAO.OTPHandler_DB.DBNAME : Config.OTPFIELD;
                var    entries = db.RootGroup.GetEntries(true).Where(x => x.Strings.Exists(sSearch)).ToList();
                if (!Program.Config.Integration.AutoTypeExpiredCanMatch)                 // Remove expired entries
                {
                    entries = entries.Where(x => !x.Expires || x.ExpiryTime >= dtExpired).ToList();
                }
                PluginDebug.AddInfo("Tray setup: Check database", 0, "DB: " + dbName, "Entries: " + entries.Count.ToString());
                if (entries.Count == 0)
                {
                    continue;
                }
                //Ignore deleted entries
                PwGroup pgRecycle = db.RecycleBinEnabled ? db.RootGroup.FindGroup(db.RecycleBinUuid, true) : null;
                if (pgRecycle != null)
                {
                    for (int i = entries.Count - 1; i >= 0; i--)
                    {
                        PwEntry pe = entries[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;
        }