Beispiel #1
0
 public Drawable GetIconDrawable(Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId)
 {
     if (!customIconId.Equals(PwUuid.Zero)) {
         return GetIconDrawable (res, db, customIconId);
     }
     return GetIconDrawable (res, icon);
 }
Beispiel #2
0
        public PwCustomIcon(PwUuid pwUuid, byte[] pbImageDataPng)
        {
            Debug.Assert(pwUuid != null);
            if(pwUuid == null) throw new ArgumentNullException("pwUuid");
            Debug.Assert(!pwUuid.Equals(PwUuid.Zero));
            if(pwUuid.Equals(PwUuid.Zero)) throw new ArgumentException("pwUuid == 0");

            Debug.Assert(pbImageDataPng != null);
            if(pbImageDataPng == null) throw new ArgumentNullException("pbImageDataPng");

            m_pwUuid = pwUuid;
            m_pbImageDataPng = pbImageDataPng;

            #if !KeePassLibSD
            // MemoryStream ms = new MemoryStream(m_pbImageDataPng, false);
            // m_pCachedImage = Image.FromStream(ms);
            // ms.Close();
            m_pCachedImage = GfxUtil.LoadImage(m_pbImageDataPng);
            #else
            m_pCachedImage = null;
            #endif
        }
Beispiel #3
0
        public PwCustomIcon(PwUuid pwUuid, byte[] pbImageDataPng)
        {
            Debug.Assert(pwUuid != null);
            if(pwUuid == null) throw new ArgumentNullException("pwUuid");
            Debug.Assert(!pwUuid.Equals(PwUuid.Zero));
            if(pwUuid.Equals(PwUuid.Zero)) throw new ArgumentException("pwUuid == 0.");
            Debug.Assert(pbImageDataPng != null);
            if(pbImageDataPng == null) throw new ArgumentNullException("pbImageDataPng");

            m_pwUuid = pwUuid;
            m_pbImageDataPng = pbImageDataPng;

            // MemoryStream ms = new MemoryStream(m_pbImageDataPng, false);
            // m_imgOrg = Image.FromStream(ms);
            // ms.Close();
            try { m_imgOrg = GfxUtil.LoadImage(m_pbImageDataPng); }
            catch(Exception) { Debug.Assert(false); }

            if(m_imgOrg != null)
                m_dImageCache[GetID(m_imgOrg.Width, m_imgOrg.Height)] =
                    m_imgOrg;
        }
Beispiel #4
0
        public static bool RemoveFactory(PwUuid u)
        {
            if(u == null) { Debug.Assert(false); return false; }

            List<TsrFactory> l = TsrPool.Factories;
            int cInitial = l.Count;

            for(int i = l.Count - 1; i >= g_nStdFac; --i)
            {
                if(u.Equals(l[i].Uuid)) l.RemoveAt(i);
            }

            return (l.Count != cInitial);
        }
Beispiel #5
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, DpiUtil.GetIcon(
                    m_pwDatabase, 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 #6
0
        private void InitEntryTab()
        {
            m_pwEntryIcon = m_pwEntry.IconId;
            m_pwCustomIconID = m_pwEntry.CustomIconUuid;

            if(!m_pwCustomIconID.Equals(PwUuid.Zero))
            {
                // int nInx = (int)PwIcon.Count + m_pwDatabase.GetCustomIconIndex(m_pwCustomIconID);
                // if((nInx > -1) && (nInx < m_ilIcons.Images.Count))
                //	m_btnIcon.Image = m_ilIcons.Images[nInx];
                // else m_btnIcon.Image = m_ilIcons.Images[(int)m_pwEntryIcon];

                Image imgCustom = m_pwDatabase.GetCustomIcon(m_pwCustomIconID);
                // m_btnIcon.Image = (imgCustom ?? m_ilIcons.Images[(int)m_pwEntryIcon]);
                UIUtil.SetButtonImage(m_btnIcon, (imgCustom ?? m_ilIcons.Images[
                    (int)m_pwEntryIcon]), true);
            }
            else
            {
                // m_btnIcon.Image = m_ilIcons.Images[(int)m_pwEntryIcon];
                UIUtil.SetButtonImage(m_btnIcon, m_ilIcons.Images[
                    (int)m_pwEntryIcon], true);
            }

            bool bHideInitial = m_cbHidePassword.Checked;
            m_icgPassword.Attach(m_tbPassword, m_cbHidePassword, m_lblPasswordRepeat,
                m_tbRepeatPassword, m_lblQuality, m_pbQuality, m_lblQualityInfo,
                m_ttRect, this, bHideInitial, false);

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

            if(m_pwEditMode == PwEditMode.ViewReadOnlyEntry)
            {
                m_tbTitle.ReadOnly = m_tbUserName.ReadOnly = m_tbPassword.ReadOnly =
                    m_tbRepeatPassword.ReadOnly = m_tbUrl.ReadOnly =
                    m_rtNotes.ReadOnly = true;

                m_btnIcon.Enabled = m_btnGenPw.Enabled = m_cbExpires.Enabled =
                    m_dtExpireDateTime.Enabled =
                    m_btnStandardExpires.Enabled = false;

                m_rtNotes.SelectAll();
                m_rtNotes.BackColor = m_rtNotes.SelectionBackColor =
                    AppDefs.ColorControlDisabled;
                m_rtNotes.DeselectAll();

                m_ctxToolsUrlSelApp.Enabled = m_ctxToolsUrlSelDoc.Enabled = false;
                m_ctxToolsFieldRefsInTitle.Enabled = m_ctxToolsFieldRefsInUserName.Enabled =
                    m_ctxToolsFieldRefsInPassword.Enabled = m_ctxToolsFieldRefsInUrl.Enabled =
                    m_ctxToolsFieldRefsInNotes.Enabled = false;
                m_ctxToolsFieldRefs.Enabled = false;

                m_btnOK.Enabled = false;
            }

            // Show URL in blue, if it's black in the current visual theme
            if(m_tbUrl.ForeColor.ToArgb() == Color.Black.ToArgb())
                m_tbUrl.ForeColor = Color.Blue;
        }
Beispiel #7
0
		private static TsrFactory GetFactory(PwUuid u)
		{
			if(u == null) { Debug.Assert(false); return null; }

			foreach(TsrFactory f in TsrPool.Factories)
			{
				if(u.Equals(f.Uuid)) return f;
			}

			return null;
		}
Beispiel #8
0
        public Drawable GetIconDrawable(Resources res, PwDatabase db, PwUuid icon)
        {
            InitBlank (res);
            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;
                }

                bitmap = resize (bitmap);

                draw = new BitmapDrawable(res, bitmap);
                _customIconMap[icon] = draw;
            }

            return draw;
        }
Beispiel #9
0
        private static int MenuGetImageIndex(PwDocument ds, PwIcon pwID,
			PwUuid pwCustomID)
        {
            if(!pwCustomID.Equals(PwUuid.Zero) && (ds ==
                Program.MainForm.DocumentManager.ActiveDocument))
            {
                return (int)PwIcon.Count +
                    Program.MainForm.DocumentManager.ActiveDatabase.GetCustomIconIndex(
                    pwCustomID);
            }

            if((int)pwID < (int)PwIcon.Count) return (int)pwID;

            return (int)PwIcon.Key;
        }
Beispiel #10
0
        public bool EqualsEntry(PwEntry pe, PwCompareOptions pwOpt,
                                MemProtCmpMode mpCmpStr)
        {
            if (pe == null)
            {
                Debug.Assert(false); return(false);
            }

            bool bNeEqStd = ((pwOpt & PwCompareOptions.NullEmptyEquivStd) !=
                             PwCompareOptions.None);
            bool bIgnoreLastAccess = ((pwOpt & PwCompareOptions.IgnoreLastAccess) !=
                                      PwCompareOptions.None);
            bool bIgnoreLastMod = ((pwOpt & PwCompareOptions.IgnoreLastMod) !=
                                   PwCompareOptions.None);

            if (!m_uuid.Equals(pe.m_uuid))
            {
                return(false);
            }
            if ((pwOpt & PwCompareOptions.IgnoreParentGroup) == PwCompareOptions.None)
            {
                if (m_pParentGroup != pe.m_pParentGroup)
                {
                    return(false);
                }
                if (!bIgnoreLastMod && (m_tParentGroupLastMod != pe.m_tParentGroupLastMod))
                {
                    return(false);
                }
            }

            if (!m_listStrings.EqualsDictionary(pe.m_listStrings, pwOpt, mpCmpStr))
            {
                return(false);
            }
            if (!m_listBinaries.EqualsDictionary(pe.m_listBinaries))
            {
                return(false);
            }

            if (!m_listAutoType.Equals(pe.m_listAutoType))
            {
                return(false);
            }

            if ((pwOpt & PwCompareOptions.IgnoreHistory) == PwCompareOptions.None)
            {
                bool bIgnoreLastBackup = ((pwOpt & PwCompareOptions.IgnoreLastBackup) !=
                                          PwCompareOptions.None);

                if (!bIgnoreLastBackup && (m_listHistory.UCount != pe.m_listHistory.UCount))
                {
                    return(false);
                }
                if (bIgnoreLastBackup && (m_listHistory.UCount == 0))
                {
                    Debug.Assert(false);
                    return(false);
                }
                if (bIgnoreLastBackup && ((m_listHistory.UCount - 1) != pe.m_listHistory.UCount))
                {
                    return(false);
                }

                PwCompareOptions cmpSub = PwCompareOptions.IgnoreParentGroup;
                if (bNeEqStd)
                {
                    cmpSub |= PwCompareOptions.NullEmptyEquivStd;
                }
                if (bIgnoreLastMod)
                {
                    cmpSub |= PwCompareOptions.IgnoreLastMod;
                }
                if (bIgnoreLastAccess)
                {
                    cmpSub |= PwCompareOptions.IgnoreLastAccess;
                }

                for (uint uHist = 0; uHist < pe.m_listHistory.UCount; ++uHist)
                {
                    if (!m_listHistory.GetAt(uHist).EqualsEntry(pe.m_listHistory.GetAt(
                                                                    uHist), cmpSub, MemProtCmpMode.None))
                    {
                        return(false);
                    }
                }
            }

            if (m_pwIcon != pe.m_pwIcon)
            {
                return(false);
            }
            if (!m_pwCustomIconID.Equals(pe.m_pwCustomIconID))
            {
                return(false);
            }

            if (m_clrForeground != pe.m_clrForeground)
            {
                return(false);
            }
            if (m_clrBackground != pe.m_clrBackground)
            {
                return(false);
            }

            if (m_tCreation != pe.m_tCreation)
            {
                return(false);
            }
            if (!bIgnoreLastMod && (m_tLastMod != pe.m_tLastMod))
            {
                return(false);
            }
            if (!bIgnoreLastAccess && (m_tLastAccess != pe.m_tLastAccess))
            {
                return(false);
            }
            if (m_tExpire != pe.m_tExpire)
            {
                return(false);
            }
            if (m_bExpires != pe.m_bExpires)
            {
                return(false);
            }
            if (!bIgnoreLastAccess && (m_uUsageCount != pe.m_uUsageCount))
            {
                return(false);
            }

            if (m_strOverrideUrl != pe.m_strOverrideUrl)
            {
                return(false);
            }

            if (m_vTags.Count != pe.m_vTags.Count)
            {
                return(false);
            }
            for (int iTag = 0; iTag < m_vTags.Count; ++iTag)
            {
                if (m_vTags[iTag] != pe.m_vTags[iTag])
                {
                    return(false);
                }
            }

            if (!m_dCustomData.Equals(pe.m_dCustomData))
            {
                return(false);
            }

            return(true);
        }
Beispiel #11
0
        public bool EqualsEntry(PwEntry pe, PwCompareOptions pwOpt,
                                MemProtCmpMode mpCmpStr)
        {
            if (pe == null)
            {
                Debug.Assert(false); return(false);
            }

            bool bNeEqStd = ((pwOpt & PwCompareOptions.NullEmptyEquivStd) !=
                             PwCompareOptions.None);
            bool bIgnoreLastAccess = ((pwOpt & PwCompareOptions.IgnoreLastAccess) !=
                                      PwCompareOptions.None);
            bool bIgnoreLastMod = ((pwOpt & PwCompareOptions.IgnoreLastMod) !=
                                   PwCompareOptions.None);

            if (!m_uuid.Equals(pe.m_uuid))
            {
                return(false);
            }
            if ((pwOpt & PwCompareOptions.IgnoreParentGroup) == PwCompareOptions.None)
            {
                if (m_pParentGroup != pe.m_pParentGroup)
                {
                    return(false);
                }
                if (!bIgnoreLastMod && (m_tParentGroupLastMod != pe.m_tParentGroupLastMod))
                {
                    return(false);
                }
                if (!m_puPrevParentGroup.Equals(pe.m_puPrevParentGroup))
                {
                    return(false);
                }
            }

            if (!m_dStrings.EqualsDictionary(pe.m_dStrings, pwOpt, mpCmpStr))
            {
                return(false);
            }
            if (!m_dBinaries.EqualsDictionary(pe.m_dBinaries))
            {
                return(false);
            }

            if (!m_cfgAutoType.Equals(pe.m_cfgAutoType))
            {
                return(false);
            }

            if ((pwOpt & PwCompareOptions.IgnoreHistory) == PwCompareOptions.None)
            {
                bool bIgnoreLastBackup = ((pwOpt & PwCompareOptions.IgnoreLastBackup) !=
                                          PwCompareOptions.None);

                if (!bIgnoreLastBackup && (m_lHistory.UCount != pe.m_lHistory.UCount))
                {
                    return(false);
                }
                if (bIgnoreLastBackup && (m_lHistory.UCount == 0))
                {
                    Debug.Assert(false);
                    return(false);
                }
                if (bIgnoreLastBackup && ((m_lHistory.UCount - 1) != pe.m_lHistory.UCount))
                {
                    return(false);
                }

                PwCompareOptions cmpSub = PwCompareOptions.IgnoreParentGroup;
                if (bNeEqStd)
                {
                    cmpSub |= PwCompareOptions.NullEmptyEquivStd;
                }
                if (bIgnoreLastMod)
                {
                    cmpSub |= PwCompareOptions.IgnoreLastMod;
                }
                if (bIgnoreLastAccess)
                {
                    cmpSub |= PwCompareOptions.IgnoreLastAccess;
                }

                for (uint uHist = 0; uHist < pe.m_lHistory.UCount; ++uHist)
                {
                    if (!m_lHistory.GetAt(uHist).EqualsEntry(pe.m_lHistory.GetAt(
                                                                 uHist), cmpSub, MemProtCmpMode.None))
                    {
                        return(false);
                    }
                }
            }

            if (m_pwIcon != pe.m_pwIcon)
            {
                return(false);
            }
            if (!m_puCustomIcon.Equals(pe.m_puCustomIcon))
            {
                return(false);
            }

            if (m_clrForeground != pe.m_clrForeground)
            {
                return(false);
            }
            if (m_clrBackground != pe.m_clrBackground)
            {
                return(false);
            }

            if (m_tCreation != pe.m_tCreation)
            {
                return(false);
            }
            if (!bIgnoreLastMod && (m_tLastMod != pe.m_tLastMod))
            {
                return(false);
            }
            if (!bIgnoreLastAccess && (m_tLastAccess != pe.m_tLastAccess))
            {
                return(false);
            }
            if (m_tExpire != pe.m_tExpire)
            {
                return(false);
            }
            if (m_bExpires != pe.m_bExpires)
            {
                return(false);
            }
            if (!bIgnoreLastAccess && (m_uUsageCount != pe.m_uUsageCount))
            {
                return(false);
            }

            if (m_strOverrideUrl != pe.m_strOverrideUrl)
            {
                return(false);
            }
            if (m_bQualityCheck != pe.m_bQualityCheck)
            {
                return(false);
            }

            // The Tags property normalizes
            if (!MemUtil.ListsEqual <string>(this.Tags, pe.Tags))
            {
                return(false);
            }

            if (!m_dCustomData.Equals(pe.m_dCustomData))
            {
                return(false);
            }

            return(true);
        }