Beispiel #1
0
        public Drawable GetIconDrawable(Context context, PwDatabase db, PwUuid icon)
        {
            InitBlank(context);
            if (icon.Equals(PwUuid.Zero))
            {
                return(_blank);
            }
            Drawable draw;

            if (!_customIconMap.TryGetValue(icon, out draw))
            {
                Bitmap bitmap = db.GetCustomIcon(icon);

                // Could not understand custom icon
                if (bitmap == null)
                {
                    return(_blank);
                }

                draw = new BitmapDrawable(context.Resources, bitmap);
                _customIconMap[icon] = draw;
            }

            return(draw);
        }
Beispiel #2
0
        private void SaveImageFile(ListViewItem lvi, string strFile)
        {
            if ((lvi == null) || string.IsNullOrEmpty(strFile))
            {
                Debug.Assert(false); return;
            }

            try
            {
                PwUuid pwUuid = (lvi.Tag as PwUuid);
                if (pwUuid == null)
                {
                    Debug.Assert(false); return;
                }
                Image img = m_pwDatabase.GetCustomIcon(pwUuid);
                if (img == null)
                {
                    Debug.Assert(false); return;
                }

                // string strExt = UrlUtil.GetExtension(strFile);
                ImageFormat fmt = ImageFormat.Png;
                // if(strExt.Equals("ico", StrUtil.CaseIgnoreCmp)) fmt = ImageFormat.Icon;

                img.Save(strFile, fmt);
            }
            catch (Exception ex)
            {
                MessageService.ShowWarning(ex.Message);
            }
        }
Beispiel #3
0
        internal static Image GetIcon(PwDatabase pd, PwUuid pwUuid)
        {
            if (pd == null)
            {
                Debug.Assert(false); return(null);
            }
            if (pwUuid == null)
            {
                Debug.Assert(false); return(null);
            }

            int w = ScaleIntX(16);
            int h = ScaleIntY(16);

            return(pd.GetCustomIcon(pwUuid, w, h));
        }
Beispiel #4
0
        private Image GetImage(PwDatabase database, PwUuid customIconId, PwIcon iconId)
        {
            Image image = null;

            if (!customIconId.Equals(PwUuid.Zero))
            {
                image = database.GetCustomIcon(customIconId, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16));
            }
            if (image == null)
            {
                try { image = mMainForm.ClientIcons.Images[(int)iconId]; }
                catch (Exception) { Debug.Assert(false); }
            }

            return(image);
        }
        private Image GetEntryImage(PwEntry pe, PwDatabase pwDatabase)
        {
            if (pwDatabase != null)
            {
                if (!pe.CustomIconUuid.Equals(PwUuid.Zero))
                {
                    int w = DpiUtil.ScaleIntX(16);
                    int h = DpiUtil.ScaleIntY(16);

                    return(pwDatabase.GetCustomIcon(pe.CustomIconUuid, w, h));
                }
                var iconId = (int)pe.IconId;
                if (PluginHost.MainWindow.ClientIcons != null &&
                    PluginHost.MainWindow.ClientIcons.Images != null &&
                    PluginHost.MainWindow.ClientIcons.Images.Count > iconId)
                {
                    return(PluginHost.MainWindow.ClientIcons.Images[iconId]);
                }
            }

            return(Resources.TOTP_Key);
        }
Beispiel #6
0
        private static void AddItem(PwEntry pe)
        {
            if (pe == null)
            {
                Debug.Assert(false); return;
            }

            string strText = StrUtil.EncodeMenuText(pe.Strings.ReadSafe(
                                                        PwDefs.TitleField));
            ToolStripMenuItem tsmi = new ToolStripMenuItem(strText);

            tsmi.Tag    = pe;
            tsmi.Click += OnMenuExecute;

            Image      img = null;
            PwDatabase pd  = Program.MainForm.DocumentManager.SafeFindContainerOf(pe);

            if (pd != null)
            {
                if (!pe.CustomIconUuid.Equals(PwUuid.Zero))
                {
                    img = pd.GetCustomIcon(pe.CustomIconUuid);
                }
                if (img == null)
                {
                    try { img = Program.MainForm.ClientIcons.Images[(int)pe.IconId]; }
                    catch (Exception) { Debug.Assert(false); }
                }
            }
            if (img == null)
            {
                img = Properties.Resources.B16x16_KGPG_Key1;
            }
            tsmi.Image = img;

            m_btnItemsHost.DropDownItems.Add(tsmi);
            m_vToolStripItems.Add(tsmi);
        }
Beispiel #7
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pwGroup != null); if (m_pwGroup == null)
            {
                throw new InvalidOperationException();
            }
            Debug.Assert(m_pwDatabase != null); if (m_pwDatabase == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            m_bannerImage.Image = BannerFactory.CreateBanner(m_bannerImage.Width,
                                                             m_bannerImage.Height, BannerStyle.Default,
                                                             Properties.Resources.B48x48_Folder_Txt, KPRes.EditGroup,
                                                             KPRes.EditGroupDesc);
            this.Icon = Properties.Resources.KeePass;

            UIUtil.SetButtonImage(m_btnAutoTypeEdit,
                                  Properties.Resources.B16x16_Wizard, true);

            m_dtExpires.CustomFormat = DateTimeFormatInfo.CurrentInfo.ShortDatePattern +
                                       " " + DateTimeFormatInfo.CurrentInfo.LongTimePattern;

            m_pwIconIndex    = m_pwGroup.IconId;
            m_pwCustomIconID = m_pwGroup.CustomIconUuid;

            m_tbName.Text  = m_pwGroup.Name;
            m_tbNotes.Text = m_pwGroup.Notes;

            if (m_pwCustomIconID != PwUuid.Zero)
            {
                UIUtil.SetButtonImage(m_btnIcon, m_pwDatabase.GetCustomIcon(
                                          m_pwCustomIconID), true);
            }
            else
            {
                UIUtil.SetButtonImage(m_btnIcon, m_ilClientIcons.Images[
                                          (int)m_pwIconIndex], true);
            }

            if (m_pwGroup.Expires)
            {
                m_dtExpires.Value   = m_pwGroup.ExpiryTime;
                m_cbExpires.Checked = true;
            }
            else             // Does not expire
            {
                m_dtExpires.Value   = DateTime.Now;
                m_cbExpires.Checked = false;
            }

            UIUtil.MakeInheritableBoolComboBox(m_cmbEnableAutoType,
                                               m_pwGroup.EnableAutoType, m_pwGroup.GetAutoTypeEnabledInherited());
            UIUtil.MakeInheritableBoolComboBox(m_cmbEnableSearching,
                                               m_pwGroup.EnableSearching, m_pwGroup.GetSearchingEnabledInherited());

            m_tbDefaultAutoTypeSeq.Text = m_pwGroup.GetAutoTypeSequenceInherited();

            if (m_pwGroup.DefaultAutoTypeSequence.Length == 0)
            {
                m_rbAutoTypeInherit.Checked = true;
            }
            else
            {
                m_rbAutoTypeOverride.Checked = true;
            }

            CustomizeForScreenReader();
            EnableControlsEx();
        }
Beispiel #8
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pwGroup != null); if (m_pwGroup == null)
            {
                throw new InvalidOperationException();
            }
            Debug.Assert(m_pwDatabase != null); if (m_pwDatabase == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            string strTitle = (m_bCreatingNew ? KPRes.AddGroup : KPRes.EditGroup);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_Folder_Txt, strTitle,
                                         (m_bCreatingNew ? KPRes.AddGroupDesc : KPRes.EditGroupDesc));
            this.Icon = Properties.Resources.KeePass;
            this.Text = strTitle;

            UIUtil.SetButtonImage(m_btnAutoTypeEdit,
                                  Properties.Resources.B16x16_Wizard, true);

            m_pwIconIndex    = m_pwGroup.IconId;
            m_pwCustomIconID = m_pwGroup.CustomIconUuid;

            m_tbName.Text = m_pwGroup.Name;
            UIUtil.SetMultilineText(m_tbNotes, m_pwGroup.Notes);

            if (!m_pwCustomIconID.Equals(PwUuid.Zero))
            {
                UIUtil.SetButtonImage(m_btnIcon, m_pwDatabase.GetCustomIcon(
                                          m_pwCustomIconID), true);
            }
            else
            {
                UIUtil.SetButtonImage(m_btnIcon, m_ilClientIcons.Images[
                                          (int)m_pwIconIndex], true);
            }

            if (m_pwGroup.Expires)
            {
                m_dtExpires.Value   = m_pwGroup.ExpiryTime;
                m_cbExpires.Checked = true;
            }
            else             // Does not expire
            {
                m_dtExpires.Value   = DateTime.Now.Date;
                m_cbExpires.Checked = false;
            }
            m_cgExpiry.Attach(m_cbExpires, m_dtExpires);

            PwGroup pgParent        = m_pwGroup.ParentGroup;
            bool    bParentAutoType = ((pgParent != null) ?
                                       pgParent.GetAutoTypeEnabledInherited() :
                                       PwGroup.DefaultAutoTypeEnabled);

            UIUtil.MakeInheritableBoolComboBox(m_cmbEnableAutoType,
                                               m_pwGroup.EnableAutoType, bParentAutoType);
            bool bParentSearching = ((pgParent != null) ?
                                     pgParent.GetSearchingEnabledInherited() :
                                     PwGroup.DefaultSearchingEnabled);

            UIUtil.MakeInheritableBoolComboBox(m_cmbEnableSearching,
                                               m_pwGroup.EnableSearching, bParentSearching);

            m_tbDefaultAutoTypeSeq.Text = m_pwGroup.GetAutoTypeSequenceInherited();

            if (m_pwGroup.DefaultAutoTypeSequence.Length == 0)
            {
                m_rbAutoTypeInherit.Checked = true;
            }
            else
            {
                m_rbAutoTypeOverride.Checked = true;
            }

            CustomizeForScreenReader();
            EnableControlsEx();
            UIUtil.SetFocus(m_tbName, this);
        }
Beispiel #9
0
        private static void ExportGroup(StringBuilder sb, PwGroup pg, uint uIndent,
                                        PwDatabase pd)
        {
            ExportData(sb, uIndent, "<DT><H3", null, false, null, false);
            ExportTimes(sb, pg);
            ExportData(sb, 0, ">", pg.Name, true, "</H3>", true);
            ExportData(sb, uIndent, "<DL><p>", null, false, null, true);

            foreach (PwGroup pgSub in pg.Groups)
            {
                ExportGroup(sb, pgSub, uIndent + 1, pd);
            }

#if DEBUG
            List <string> l = new List <string>();
            l.Add("Tag 1");
            l.Add("Tag 2");
            Debug.Assert(StrUtil.TagsToString(l, false) == "Tag 1;Tag 2");
#endif

            foreach (PwEntry pe in pg.Entries)
            {
                string strUrl = pe.Strings.ReadSafe(PwDefs.UrlField);
                if (strUrl.Length == 0)
                {
                    continue;
                }

                // Encode only when really required; '&' does not need
                // to be encoded
                bool bEncUrl = (strUrl.IndexOfAny(new char[] {
                    '\"', '<', '>'
                }) >= 0);

                ExportData(sb, uIndent + 1, "<DT><A HREF=\"", strUrl, bEncUrl,
                           "\"", false);

                ExportTimes(sb, pe);

                if (!pe.CustomIconUuid.Equals(PwUuid.Zero) && (pd != null))
                {
                    try
                    {
                        Image imgIcon = pd.GetCustomIcon(pe.CustomIconUuid, 16, 16);
                        if (imgIcon != null)
                        {
                            using (MemoryStream msIcon = new MemoryStream())
                            {
                                imgIcon.Save(msIcon, ImageFormat.Png);
                                byte[] pbIcon  = msIcon.ToArray();
                                string strIcon = StrUtil.DataToDataUri(pbIcon,
                                                                       "image/png");

                                ExportData(sb, 0, " ICON=\"", strIcon, false,
                                           "\"", false);
                            }
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                    }
                    catch (Exception) { Debug.Assert(false); }
                }

                if (pe.Tags.Count > 0)
                {
                    string strTags = StrUtil.TagsToString(pe.Tags, false);
                    strTags = strTags.Replace(';', ',');                     // Without space

                    ExportData(sb, 0, " TAGS=\"", strTags, true, "\"", false);
                }

                string strTitle = pe.Strings.ReadSafe(PwDefs.TitleField);
                if (strTitle.Length == 0)
                {
                    strTitle = strUrl;
                }

                ExportData(sb, 0, ">", strTitle, true, "</A>", true);

                string strNotes = pe.Strings.ReadSafe(PwDefs.NotesField);
                if (strNotes.Length > 0)
                {
                    ExportData(sb, uIndent + 1, "<DD>", strNotes, true, null, true);
                }
            }

            ExportData(sb, uIndent, "</DL><p>", null, false, null, true);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
0
 private static Image GetCustomIcon(PwDatabase database, PwUuid customIconId)
 {
     return(database.GetCustomIcon(customIconId, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16)));
 }