コード例 #1
0
ファイル: DrawableFactory.cs プロジェクト: pythe/wristpass
 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);
 }
コード例 #2
0
ファイル: Icons.cs プロジェクト: pythe/wristpass
 public static int IconToResId(PwIcon iconId)
 {
     BuildList();
     int resId;
     if (_icons.TryGetValue(iconId, out resId))
         return resId;
     return Resource.Drawable.ic99_blank;
 }
コード例 #3
0
ファイル: GroupForm.cs プロジェクト: ComradeP/KeePass-2.x
		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();
		}
コード例 #4
0
ファイル: Util.cs プロジェクト: nein23/KeePassContext
 public static Image getIcon(PwDatabase db, ImageList imageList, PwUuid customIconId, PwIcon iconId)
 {
     if (!PwUuid.Zero.Equals(customIconId))
     {
         return db.GetCustomIcon(customIconId, 16, 16);
     }
     else
     {
         return imageList.Images[(int)iconId];
     }
 }
コード例 #5
0
ファイル: EditGroup.cs プロジェクト: pythe/wristpass
        public EditGroup(Context ctx, IKp2aApp app, String name, PwIcon iconid, PwUuid customIconId, PwGroup group, OnFinish finish)
            : base(finish)
        {
            _ctx = ctx;
            _name = name;
            _iconId = iconid;
            Group = group;
            _customIconId = customIconId;
            _app = app;

            _onFinishToRun = new AfterEdit(this, OnFinishToRun);
        }
コード例 #6
0
ファイル: DrawableFactory.cs プロジェクト: pythe/wristpass
        public Drawable GetIconDrawable(Resources res, PwIcon icon)
        {
            int resId = Icons.IconToResId (icon);

            Drawable draw;
            if (!_standardIconMap.TryGetValue(resId, out draw))
            {
                draw = res.GetDrawable(resId);
                _standardIconMap[resId] = draw;
            }

            return draw;
        }
コード例 #7
0
ファイル: EcasEventType.cs プロジェクト: ashwingj/keepass2
        public EcasEventType(PwUuid uuidType, string strName, PwIcon pwIcon,
            EcasParameter[] vParams, EcasEventCompare f)
        {
            if((uuidType == null) || (uuidType.EqualsValue(PwUuid.Zero)))
                throw new ArgumentNullException("uuidType");
            if(strName == null) throw new ArgumentNullException("strName");
            // if(vParams == null) throw new ArgumentNullException("vParams");
            // if(f == null) throw new ArgumentNullException("f");

            m_type = uuidType;
            m_strName = strName;
            m_pwIcon = pwIcon;
            m_vParams = (vParams ?? EcasParameter.EmptyArray);
            m_fn = (f ?? EcasEventCompareTrue);
        }
コード例 #8
0
		public EcasConditionType(PwUuid uuidType, string strName, PwIcon pwIcon,
			EcasParameter[] vParams, EcasConditionEvaluate f)
		{
			if((uuidType == null) || PwUuid.Zero.Equals(uuidType))
				throw new ArgumentNullException("uuidType");
			if(strName == null) throw new ArgumentNullException("strName");
			// if(vParams == null) throw new ArgumentNullException("vParams");
			// if(f == null) throw new ArgumentNullException("f");

			m_type = uuidType;
			m_strName = strName;
			m_pwIcon = pwIcon;
			m_vParams = (vParams ?? EcasParameter.EmptyArray);
			m_fn = (f ?? EcasConditionEvaluateTrue);
		}
コード例 #9
0
ファイル: PwEntry.cs プロジェクト: andrxs/KeePass2.x
        /// <summary>
        /// Assign properties to the current entry based on a template entry.
        /// </summary>
        /// <param name="peTemplate">Template entry. Must not be <c>null</c>.</param>
        /// <param name="bOnlyIfNewer">Only set the properties of the template entry
        /// if it is newer than the current one.</param>
        /// <param name="bIncludeHistory">If <c>true</c>, the history will be
        /// copied, too.</param>
        /// <param name="bAssignLocationChanged">If <c>true</c>, the
        /// <c>LocationChanged</c> property is copied, otherwise not.</param>
        public void AssignProperties(PwEntry peTemplate, bool bOnlyIfNewer,
                                     bool bIncludeHistory, bool bAssignLocationChanged)
        {
            Debug.Assert(peTemplate != null); if (peTemplate == null)
            {
                throw new ArgumentNullException("peTemplate");
            }

            if (bOnlyIfNewer && (TimeUtil.Compare(peTemplate.m_tLastMod, m_tLastMod,
                                                  true) < 0))
            {
                return;
            }

            // Template UUID should be the same as the current one
            Debug.Assert(m_uuid.Equals(peTemplate.m_uuid));
            m_uuid = peTemplate.m_uuid;

            if (bAssignLocationChanged)
            {
                m_tParentGroupLastMod = peTemplate.m_tParentGroupLastMod;
            }

            m_listStrings  = peTemplate.m_listStrings;
            m_listBinaries = peTemplate.m_listBinaries;
            m_listAutoType = peTemplate.m_listAutoType;
            if (bIncludeHistory)
            {
                m_listHistory = peTemplate.m_listHistory;
            }

            m_pwIcon         = peTemplate.m_pwIcon;
            m_pwCustomIconID = peTemplate.m_pwCustomIconID;             // Immutable

            m_clrForeground = peTemplate.m_clrForeground;
            m_clrBackground = peTemplate.m_clrBackground;

            m_tCreation   = peTemplate.m_tCreation;
            m_tLastMod    = peTemplate.m_tLastMod;
            m_tLastAccess = peTemplate.m_tLastAccess;
            m_tExpire     = peTemplate.m_tExpire;
            m_bExpires    = peTemplate.m_bExpires;
            m_uUsageCount = peTemplate.m_uUsageCount;

            m_strOverrideUrl = peTemplate.m_strOverrideUrl;

            m_vTags = new List <string>(peTemplate.m_vTags);
        }
コード例 #10
0
ファイル: DrawableFactory.cs プロジェクト: 77rusa/README
        public Drawable GetIconDrawable(Context context, PwIcon icon, bool forGroup)
        {
            //int resId = DefaultIcons.IconToResId (icon, forGroup);
            int dictKey = GetDictionaryKey(icon, forGroup);

            Drawable draw;

            if (!_standardIconMap.TryGetValue(dictKey, out draw))
            {
                string packageName = PreferenceManager.GetDefaultSharedPreferences(Application.Context).GetString("IconSetKey", context.PackageName);

                Resources res;
                try
                {
                    res = context.PackageManager.GetResourcesForApplication(packageName);
                }
                catch (Exception)
                {
                    //can happen after uninstalling icons
                    packageName = context.PackageName;
                    res         = context.PackageManager.GetResourcesForApplication(packageName);
                    PreferenceManager.GetDefaultSharedPreferences(Application.Context)
                    .Edit()
                    .PutString("IconSetKey", packageName)
                    .Commit();
                }

                try
                {
                    int resId = GetResourceId(res, dictKey, packageName);
                    if (resId == 0)
                    {
                        draw = context.Resources.GetDrawable(Resource.Drawable.ic99_blank);
                    }
                    else
                    {
                        draw = res.GetDrawable(resId);
                    }
                }
                catch (System.Exception e)
                {
                    Kp2aLog.LogUnexpectedError(e);
                    draw = context.Resources.GetDrawable(Resource.Drawable.ic99_blank);
                }
            }
            _standardIconMap[dictKey] = draw;
            return(draw);
        }
コード例 #11
0
ファイル: SearchWindow.cs プロジェクト: amnore/AutoTypeSearch
        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);
        }
コード例 #12
0
            private bool SaveEntryStatus(ListViewItem Item, PwIcon icon, string text)
            {
                PwListItem pli = (((ListViewItem)Item).Tag as PwListItem);

                if (pli == null)
                {
                    Debug.Assert(false); return(false);
                }
                PwEntry pe = pli.Entry;

                pe = m_host.Database.RootGroup.FindEntry(pe.Uuid, true);

                var protString = pe.Strings.Get(PwDefs.PasswordField);

                if (protString != null && !protString.IsEmpty)
                {
                    return(false);
                }

                PwEntry peInit = pe.CloneDeep();

                pe.CreateBackup(null);
                pe.Touch(true, false); // Touch *after* backup


                pe.IconId       = icon;
                Item.ImageIndex = (int)icon;

                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(false, text));
                Item.SubItems[getSubitemOfField(KeePass.App.Configuration.AceColumnType.UserName)].Text = text;

                PwCompareOptions cmpOpt = (PwCompareOptions.IgnoreLastMod | PwCompareOptions.IgnoreLastAccess | PwCompareOptions.IgnoreLastBackup);

                if (pe.EqualsEntry(peInit, cmpOpt, MemProtCmpMode.None))
                {
                    pe.LastModificationTime = peInit.LastModificationTime;

                    pe.History.Remove(pe.History.GetAt(pe.History.UCount - 1)); // Undo backup

                    return(false);
                }
                else
                {
                    return(true);
                }
            }
コード例 #13
0
ファイル: KeePassXXml041.cs プロジェクト: t00/KeePassCore
        private static PwIcon ReadIcon(XmlNode xmlChild, PwIcon pwDefault)
        {
            int nIcon;

            if (StrUtil.TryParseInt(XmlUtil.SafeInnerText(xmlChild), out nIcon))
            {
                if ((nIcon >= 0) && (nIcon < (int)PwIcon.Count))
                {
                    return((PwIcon)nIcon);
                }
            }
            else
            {
                Debug.Assert(false);
            }

            return(pwDefault);
        }
コード例 #14
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);
        }
コード例 #15
0
        /// <summary>
        /// Assign properties to the current entry based on a template entry.
        /// </summary>
        /// <param name="peTemplate">Template entry. Must not be <c>null</c>.</param>
        /// <param name="bOnlyIfNewer">Only set the properties of the template entry
        /// if it is newer than the current one.</param>
        /// <param name="bIncludeHistory">If <c>true</c>, the history will be
        /// copied, too.</param>
        public void AssignProperties(PwEntry peTemplate, bool bOnlyIfNewer,
                                     bool bIncludeHistory)
        {
            Debug.Assert(peTemplate != null); if (peTemplate == null)
            {
                throw new ArgumentNullException("peTemplate");
            }

            // Template UUID should be the same as the current one
            Debug.Assert(m_uuid.EqualsValue(peTemplate.m_uuid));
            m_uuid = peTemplate.m_uuid;

            if (bOnlyIfNewer)
            {
                if (peTemplate.m_tLastMod < this.m_tLastMod)
                {
                    return;
                }
            }

            m_listStrings  = peTemplate.m_listStrings;
            m_listBinaries = peTemplate.m_listBinaries;
            m_listAutoType = peTemplate.m_listAutoType;

            if (bIncludeHistory)
            {
                m_listHistory = peTemplate.m_listHistory;
            }

            m_pwIcon         = peTemplate.m_pwIcon;
            m_pwCustomIconID = peTemplate.m_pwCustomIconID;

            m_clrForeground = peTemplate.m_clrForeground;
            m_clrBackground = peTemplate.m_clrBackground;

            m_tCreation   = peTemplate.m_tCreation;
            m_tLastMod    = peTemplate.m_tLastMod;
            m_tLastAccess = peTemplate.m_tLastAccess;
            m_tExpire     = peTemplate.m_tExpire;
            m_bExpires    = peTemplate.m_bExpires;
            m_uUsageCount = peTemplate.m_uUsageCount;

            m_strOverrideUrl = peTemplate.m_strOverrideUrl;
        }
コード例 #16
0
        // Strangely, there doesn't appear to already exist a helper to get an image for a group. If one appears, then that should be used instead of this custom one.
        private Image GetImage(PwUuid customIconId, PwIcon iconId)
        {
            Image image = null;

            if (Database != null)
            {
                if (!customIconId.EqualsValue(PwUuid.Zero))
                {
                    image = Database.GetCustomIcon(customIconId);
                }
                if (image == null)
                {
                    try { image = mMainForm.ClientIcons.Images[(int)iconId]; }
                    catch (Exception) { Debug.Assert(false); }
                }
            }

            return(image);
        }
コード例 #17
0
ファイル: PwGroup.cs プロジェクト: jonbride/strengthreport
        /// <summary>
        /// Construct a new group.
        /// </summary>
        /// <param name="bCreateNewUuid">Create a new UUID for this group.</param>
        /// <param name="bSetTimes">Set creation, last access and last modification times to the current time.</param>
        /// <param name="strName">Name of the new group.</param>
        /// <param name="pwIcon">Icon of the new group.</param>
        public PwGroup(bool bCreateNewUuid, bool bSetTimes, string strName, PwIcon pwIcon)
        {
            if (bCreateNewUuid)
            {
                m_uuid = new PwUuid(true);
            }

            if (bSetTimes)
            {
                m_tCreation = m_tLastMod = m_tLastAccess = DateTime.Now;
            }

            if (strName != null)
            {
                m_strName = strName;
            }

            m_pwIcon = pwIcon;
        }
コード例 #18
0
        public EcasConditionType(PwUuid uuidType, string strName, PwIcon pwIcon,
                                 EcasParameter[] vParams, EcasConditionEvaluate f)
        {
            if ((uuidType == null) || PwUuid.Zero.Equals(uuidType))
            {
                throw new ArgumentNullException("uuidType");
            }
            if (strName == null)
            {
                throw new ArgumentNullException("strName");
            }
            // if(vParams == null) throw new ArgumentNullException("vParams");
            // if(f == null) throw new ArgumentNullException("f");

            m_type    = uuidType;
            m_strName = strName;
            m_pwIcon  = pwIcon;
            m_vParams = (vParams ?? EcasParameter.EmptyArray);
            m_fn      = (f ?? EcasConditionEvaluateTrue);
        }
コード例 #19
0
            public SplashIdMapping(string strTypeName, PwIcon pwIcon, string[] vFieldNames)
            {
                Debug.Assert(strTypeName != null);
                if (strTypeName == null)
                {
                    throw new ArgumentNullException("strTypeName");
                }

                Debug.Assert(vFieldNames != null);
                if (vFieldNames == null)
                {
                    throw new ArgumentNullException("vFieldNames");
                }

                m_strTypeName = strTypeName;
                m_pwIcon      = pwIcon;

                for (int i = 0; i < Math.Min(m_vFieldNames.Length, vFieldNames.Length); ++i)
                {
                    m_vFieldNames[i] = vFieldNames[i];
                }
            }
コード例 #20
0
ファイル: PwDefs.cs プロジェクト: kkato233/KeePass
        internal static PwIcon GroupIconToEntryIcon(PwIcon i)
        {
            PwIcon r = i;             // Inherit by default

            switch (i)
            {
            case PwIcon.Folder:
            case PwIcon.FolderOpen:
            case PwIcon.FolderPackage:
                Debug.Assert((new PwEntry(false, false)).IconId == PwIcon.Key);
                r = PwIcon.Key;
                break;

            case PwIcon.EMailBox:
                r = PwIcon.EMail;
                break;

            default: break;
            }

            return(r);
        }
コード例 #21
0
ファイル: GroupForm.cs プロジェクト: ComradeP/KeePass-2.x
        private void OnBtnIcon(object sender, EventArgs e)
        {
            IconPickerForm ipf = new IconPickerForm();

            ipf.InitEx(m_ilClientIcons, (uint)PwIcon.Count, m_pwDatabase,
                       (uint)m_pwIconIndex, m_pwCustomIconID);
            ipf.ShowDialog();

            if (ipf.ChosenCustomIconUuid != PwUuid.Zero)            // Custom icon
            {
                m_pwCustomIconID = ipf.ChosenCustomIconUuid;
                UIUtil.SetButtonImage(m_btnIcon, m_pwDatabase.GetCustomIcon(
                                          m_pwCustomIconID), true);
            }
            else             // Standard icon
            {
                m_pwIconIndex    = (PwIcon)ipf.ChosenIconId;
                m_pwCustomIconID = PwUuid.Zero;
                UIUtil.SetButtonImage(m_btnIcon, m_ilClientIcons.Images[
                                          (int)m_pwIconIndex], true);
            }
        }
コード例 #22
0
        /// <summary>
        /// Assign properties to the current group based on a template group.
        /// </summary>
        /// <param name="pgTemplate">Template group. Must not be <c>null</c>.</param>
        /// <param name="bOnlyIfNewer">Only set the properties of the template group
        /// if it is newer than the current one.</param>
        /// <param name="bAssignLocationChanged">If <c>true</c>, the
        /// <c>LocationChanged</c> property is copied, otherwise not.</param>
        public void AssignProperties(PwGroup pgTemplate, bool bOnlyIfNewer,
                                     bool bAssignLocationChanged)
        {
            Debug.Assert(pgTemplate != null); if (pgTemplate == null)
            {
                throw new ArgumentNullException("pgTemplate");
            }

            if (bOnlyIfNewer && (pgTemplate.m_tLastMod < m_tLastMod))
            {
                return;
            }

            // Template UUID should be the same as the current one
            Debug.Assert(m_uuid.EqualsValue(pgTemplate.m_uuid));
            m_uuid = pgTemplate.m_uuid;

            if (bAssignLocationChanged)
            {
                m_tParentGroupLastMod = pgTemplate.m_tParentGroupLastMod;
            }

            m_strName  = pgTemplate.m_strName;
            m_strNotes = pgTemplate.m_strNotes;

            m_pwIcon         = pgTemplate.m_pwIcon;
            m_pwCustomIconID = pgTemplate.m_pwCustomIconID;

            m_tCreation   = pgTemplate.m_tCreation;
            m_tLastMod    = pgTemplate.m_tLastMod;
            m_tLastAccess = pgTemplate.m_tLastAccess;
            m_tExpire     = pgTemplate.m_tExpire;
            m_bExpires    = pgTemplate.m_bExpires;
            m_uUsageCount = pgTemplate.m_uUsageCount;

            m_strDefaultAutoTypeSequence = pgTemplate.m_strDefaultAutoTypeSequence;

            m_pwLastTopVisibleEntry = pgTemplate.m_pwLastTopVisibleEntry;
        }
コード例 #23
0
 public void AssignDrawableTo(ImageView iv, Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId, bool forGroup)
 {
 }
コード例 #24
0
ファイル: GroupForm.cs プロジェクト: ComradeP/KeePass-2.x
        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();
        }
コード例 #25
0
ファイル: GroupForm.cs プロジェクト: haro-freezd/KeePass
        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);
        }
        /// <summary>
        /// The main routine, called when import is selected
        /// </summary>
        /// <param name="pwStorage"></param>
        /// <param name="sInput"></param>
        /// <param name="slLogger"></param>
        public override void Import(PwDatabase pwStorage, System.IO.Stream sInput, KeePassLib.Interfaces.IStatusLogger slLogger)
        {
            try
            {
                Form1 form = new Form1();

                form.Initialise(pwStorage);

                if (form.ShowDialog() == DialogResult.OK)
                {
                    // return;
                    bool   overwritePassword = form.Overwrite;
                    bool   searchWeb         = form.GetTitles;
                    bool   checkMatches      = form.Merge;
                    string masterPassword    = form.Password;

                    bool   addAutoType = form.AddAutoType;
                    PwIcon iconId      = (PwIcon)Enum.Parse(typeof(PwIcon), form.IconName);

                    string profilePath = form.ProfilePath;

                    if (String.IsNullOrEmpty(profilePath))
                    {
                        MessageBox.Show("No Profile Selected. Use Load More Profiles", "Profile Required", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Import(pwStorage, sInput, slLogger); // bit of a hack!
                        return;
                    }

                    PwGroup group = form.Group;

                    if (group == null)
                    {
                        group = pwStorage.RootGroup;
                    }

                    //     return;

                    try
                    {
                        InternetAccessor internetAccessor = new InternetAccessor();

                        slLogger.StartLogging("Importing Firefox Passwords", false);

                        slLogger.SetText("Logging In", LogStatusType.Info);

                        FirefoxProfile profile = new FirefoxProfile(profilePath);

                        profile.Login(masterPassword);

                        slLogger.SetText("Reading Signon file", LogStatusType.Info);


                        FirefoxSignonsFile signonsFile = profile.GetSignonsFile(masterPassword);


                        slLogger.SetText("Processing Passwords", LogStatusType.Info);

                        int count = signonsFile.SignonSites.Count;
                        int pos   = 0;

                        //  return;

                        // Loop each entry and add it to KeePass
                        foreach (FirefoxSignonSite signonSite in signonsFile.SignonSites)
                        {
                            // keep the user informed of progress
                            pos++;

                            foreach (FirefoxSignon signon in signonSite.Signons)
                            {
                                if (!slLogger.ContinueWork()) // Check if process has been cancelled by the user
                                {
                                    break;
                                }


                                slLogger.SetProgress((uint)(100 * ((double)pos) / ((double)count)));


                                string notes = String.Empty;

                                if (form.IncludeImportNotes)
                                {
                                    notes += "Imported from FireFox by the Web Site Advantage FireFox to KeePass Importer" + Environment.NewLine;
                                }

                                // gather the data to import

                                string title = signonSite.Site;

                                // PATCH: supplied by Sarel Botha
                                // remove protocol from site so that it works with new KeepassHTTP
                                if (title.StartsWith("http://"))
                                {
                                    title = title.Substring(7);
                                }
                                if (title.StartsWith("https://"))
                                {
                                    title = title.Substring(8);
                                }

                                // remove port number if the title contains it so that it will work with new KeepassHTTP
                                if (title.Contains(":"))
                                {
                                    title = title.Substring(0, title.IndexOf(':'));
                                }
                                // PATCH END

                                string url = signonSite.Site;

                                if (!String.IsNullOrEmpty(signon.LoginFormDomain))
                                {
                                    title = signon.LoginFormDomain;
                                    url   = signon.LoginFormDomain;
                                }

                                string host = url;
                                try
                                {
                                    Uri uri = new Uri(url);
                                    host = uri.Host;
                                }
                                catch { }

                                slLogger.SetText(title, LogStatusType.Info);


                                string username = signon.UserName;

                                bool newEntry = true;

                                PwEntry pe = null;

                                if (checkMatches)
                                {
                                    pe = KeePassHelper.FindMatchingEntry(pwStorage.RootGroup, url, username);
                                }

                                if (pe == null)
                                {
                                    // create a new entry

                                    pe = new PwEntry(true, true);
                                    group.AddEntry(pe, true);
                                    slLogger.SetText("Created new entry", LogStatusType.AdditionalInfo);
                                }
                                else
                                {
                                    newEntry = false;
                                    slLogger.SetText("Found matching entry", LogStatusType.AdditionalInfo);
                                }

                                if (newEntry || overwritePassword)
                                {
                                    // set the password
                                    pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pwStorage.MemoryProtection.ProtectPassword, signon.Password));
                                }

                                if (newEntry)
                                {
                                    // set all fields
                                    pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pwStorage.MemoryProtection.ProtectTitle, title));
                                    pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pwStorage.MemoryProtection.ProtectUserName, username));
                                    pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pwStorage.MemoryProtection.ProtectUrl, url));
                                    if (!String.IsNullOrEmpty(notes))
                                    {
                                        pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pwStorage.MemoryProtection.ProtectNotes, notes));
                                    }
                                    pe.Expires = false;
                                    pe.IconId  = iconId;

                                    // Gatter any extra information...

                                    if (!String.IsNullOrEmpty(signon.UserNameField))
                                    {
                                        pe.Strings.Set("UserNameField", new ProtectedString(false, signon.UserNameField));
                                    }

                                    if (!String.IsNullOrEmpty(signon.PasswordField))
                                    {
                                        pe.Strings.Set("PasswordField", new ProtectedString(false, signon.PasswordField));
                                    }

                                    if (!String.IsNullOrEmpty(signon.LoginFormDomain))
                                    {
                                        pe.Strings.Set("LoginFormDomain", new ProtectedString(false, signon.LoginFormDomain));
                                    }
                                }

                                string webTitle = null;

                                // if new or the title is the same as the url then we should try and get the title
                                if (searchWeb)
                                {
                                    // test if new or entry has url as title
                                    if ((newEntry || pe.Strings.Get(PwDefs.TitleField).ReadString() == pe.Strings.Get(PwDefs.UrlField).ReadString()))
                                    {
                                        // get the pages title
                                        slLogger.SetText("Accessing website for title", LogStatusType.AdditionalInfo);

                                        webTitle = internetAccessor.ScrapeTitle(url);

                                        if (!String.IsNullOrEmpty(webTitle))
                                        {
                                            slLogger.SetText("Title set from internet to " + webTitle, LogStatusType.AdditionalInfo);


                                            pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pwStorage.MemoryProtection.ProtectTitle, webTitle));
                                        }
                                    }
                                    //else
                                    //{
                                    //    // Entry has a good title, keep it incase there are other ones for this site
                                    //    title = pe.Strings.Get(PwDefs.TitleField).ReadString();
                                    //}
                                }
                                // return;


                                if (addAutoType)
                                {
                                    KeePassHelper.InsertAutoType(pe, "*" + host + "*", KeePassUtilities.AutoTypeSequence());
                                }

                                // return;

                                if (webTitle != null && addAutoType)
                                {
                                    KeePassHelper.InsertAutoType(pe, KeePassUtilities.AutoTypeWindow(webTitle), KeePassUtilities.AutoTypeSequence());
                                }
                            }
                        }
                    }
                    finally
                    {
                        slLogger.EndLogging();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Failed to Validate Password"))
                {
                    MessageBox.Show(ex.Message, "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    ErrorMessage.ShowErrorMessage("Importer", "Import Failed", ex);
                }
            }
        }
コード例 #27
0
			public SplashIdMapping(string strTypeName, PwIcon pwIcon, string[] vFieldNames)
			{
				Debug.Assert(strTypeName != null);
				if(strTypeName == null) throw new ArgumentNullException("strTypeName");

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

				m_strTypeName = strTypeName;
				m_pwIcon = pwIcon;

				for(int i = 0; i < Math.Min(m_vFieldNames.Length, vFieldNames.Length); ++i)
					m_vFieldNames[i] = vFieldNames[i];
			}
コード例 #28
0
        private static void ProcessCsvLine(string[] vLine, PwDatabase pwStorage,
                                           SortedDictionary <string, PwGroup> dictGroups)
        {
            string strType = ParseCsvWord(vLine[0]);

            string strGroupName = ParseCsvWord(vLine[12]);             // + " - " + strType;

            if (strGroupName.Length == 0)
            {
                strGroupName = strType;
            }

            SplashIdMapping mp = null;

            foreach (SplashIdMapping mpFind in SplashIdCsv402.SplashIdMappings)
            {
                if (mpFind.TypeName == strType)
                {
                    mp = mpFind;
                    break;
                }
            }

            PwIcon pwIcon = ((mp != null) ? mp.Icon : PwIcon.Key);

            PwGroup pg = null;

            if (dictGroups.ContainsKey(strGroupName))
            {
                pg = dictGroups[strGroupName];
            }
            else
            {
                // PwIcon pwGroupIcon = ((pwIcon == PwIcon.Key) ?
                //	PwIcon.FolderOpen : pwIcon);
                // pg = new PwGroup(true, true, strGroupName, pwGroupIcon);

                pg      = new PwGroup(true, true);
                pg.Name = strGroupName;

                pwStorage.RootGroup.AddGroup(pg, true);
                dictGroups[strGroupName] = pg;
            }

            PwEntry pe = new PwEntry(true, true);

            pg.AddEntry(pe, true);

            pe.IconId = pwIcon;

            StrUtil.AddTags(pe.Tags, StrUtil.StringToTags(strType));

            for (int iField = 0; iField < 9; ++iField)
            {
                string strData = ParseCsvWord(vLine[iField + 1]);
                if (strData.Length == 0)
                {
                    continue;
                }

                string strLookup = ((mp != null) ? mp.FieldNames[iField] :
                                    null);
                string strField = (strLookup ?? ("Field " + (iField + 1).ToString()));

                ImportUtil.AppendToField(pe, strField, strData, pwStorage);
            }

            ImportUtil.AppendToField(pe, PwDefs.NotesField, ParseCsvWord(vLine[11]),
                                     pwStorage);

            DateTime?odt = TimeUtil.ParseUSTextDate(ParseCsvWord(vLine[10]),
                                                    DateTimeKind.Local);

            if (odt.HasValue)
            {
                DateTime dt = TimeUtil.ToUtc(odt.Value, false);
                pe.LastAccessTime       = dt;
                pe.LastModificationTime = dt;
            }
        }
コード例 #29
0
ファイル: PwEntryForm.cs プロジェクト: rdealexb/keepass
        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;
        }
コード例 #30
0
        public static Icon MapPwIconToIcon(PwIcon value)
        {
            switch (value)
            {
            case PwIcon.Key: return(Icon.Permissions);

            case PwIcon.WorldSocket:
            case PwIcon.World: return(Icon.World);

            case PwIcon.Warning: return(Icon.Important);

            case PwIcon.WorldComputer:
            case PwIcon.Drive:
            case PwIcon.DriveWindows:
            case PwIcon.NetworkServer: return(Icon.MapDrive);

            case PwIcon.MarkedDirectory: return(Icon.Map);

            case PwIcon.UserCommunication: return(Icon.ContactInfo);

            case PwIcon.Parts: return(Icon.ViewAll);

            case PwIcon.Notepad: return(Icon.Document);

            case PwIcon.Identity: return(Icon.Contact);

            case PwIcon.PaperReady: return(Icon.SyncFolder);

            case PwIcon.Digicam: return(Icon.Camera);

            case PwIcon.IRCommunication: return(Icon.View);

            case PwIcon.Energy: return(Icon.ZeroBars);

            case PwIcon.Scanner: return(Icon.Scan);

            case PwIcon.CDRom: return(Icon.Rotate);

            case PwIcon.Monitor: return(Icon.Caption);

            case PwIcon.EMailBox:
            case PwIcon.EMail: return(Icon.Mail);

            case PwIcon.Configuration: return(Icon.Setting);

            case PwIcon.ClipboardReady: return(Icon.Paste);

            case PwIcon.PaperNew: return(Icon.Page);

            case PwIcon.Screen: return(Icon.GoToStart);

            case PwIcon.EnergyCareful: return(Icon.FourBars);

            case PwIcon.Disk: return(Icon.Save);

            case PwIcon.Console: return(Icon.SlideShow);

            case PwIcon.Printer: return(Icon.Scan);

            case PwIcon.ProgramIcons: return(Icon.GoToStart);

            case PwIcon.Settings:
            case PwIcon.Tool: return(Icon.Repair);

            case PwIcon.Archive: return(Icon.Crop);

            case PwIcon.Count: return(Icon.Calculator);

            case PwIcon.Clock: return(Icon.Clock);

            case PwIcon.EMailSearch: return(Icon.Find);

            case PwIcon.PaperFlag: return(Icon.Flag);

            case PwIcon.TrashBin: return(Icon.Delete);

            case PwIcon.Expired: return(Icon.ReportHacked);

            case PwIcon.Info: return(Icon.Help);

            case PwIcon.Folder:
            case PwIcon.FolderOpen:
            case PwIcon.FolderPackage: return(Icon.Folder);

            case PwIcon.PaperLocked: return(Icon.ProtectedDocument);

            case PwIcon.Checked: return(Icon.Accept);

            case PwIcon.Pen: return(Icon.Edit);

            case PwIcon.Thumbnail: return(Icon.BrowsePhotos);

            case PwIcon.Book: return(Icon.Library);

            case PwIcon.List: return(Icon.List);

            case PwIcon.UserKey: return(Icon.ContactPresence);

            case PwIcon.Home: return(Icon.Home);

            case PwIcon.Star: return(Icon.OutlineStar);

            case PwIcon.Money: return(Icon.Shop);

            case PwIcon.Certificate: return(Icon.PreviewLink);

            case PwIcon.BlackBerry: return(Icon.CellPhone);

            default: return(Icon.Stop);
            }
        }
コード例 #31
0
        private static void ProcessCsvLine(string strLine, PwDatabase pwStorage,
                                           SortedDictionary <string, PwGroup> dictGroups)
        {
            if (strLine == StrHeader)
            {
                return;                                  // Skip header
            }
            List <string> list = ImportUtil.SplitCsvLine(strLine, ",");

            Debug.Assert(list.Count == 13);
            if (list.Count != 13)
            {
                return;
            }

            string strType      = ParseCsvWord(list[0]);
            string strGroupName = ParseCsvWord(list[12]) + " - " + strType;

            SplashIdMapping mp = null;

            foreach (SplashIdMapping mpFind in SplashIdMappings)
            {
                if (mpFind.TypeName == strType)
                {
                    mp = mpFind;
                    break;
                }
            }

            PwIcon pwIcon = ((mp != null) ? mp.Icon : PwIcon.Key);

            PwGroup pg = null;

            if (dictGroups.ContainsKey(strGroupName))
            {
                pg = dictGroups[strGroupName];
            }
            else
            {
                PwIcon pwGroupIcon = ((pwIcon == PwIcon.Key) ?
                                      PwIcon.FolderOpen : pwIcon);

                pg = new PwGroup(true, true, strGroupName, pwGroupIcon);
                pwStorage.RootGroup.AddGroup(pg, true);
                dictGroups.Add(strGroupName, pg);
            }

            PwEntry pe = new PwEntry(true, true);

            pg.AddEntry(pe, true);

            pe.IconId = pwIcon;

            for (int iField = 0; iField < 9; ++iField)
            {
                string strData = ParseCsvWord(list[iField + 1]);
                if (strData.Length == 0)
                {
                    continue;
                }

                string strLookup = ((mp != null) ? mp.FieldNames[iField] :
                                    null);
                string strField = (strLookup ?? ("Field " + (iField + 1).ToString()));

                pe.Strings.Set(strField, new ProtectedString(false,
                                                             strData));
            }

            pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
                               pwStorage.MemoryProtection.ProtectNotes,
                               ParseCsvWord(list[11])));
        }
コード例 #32
0
ファイル: PwEntryForm.cs プロジェクト: amiryal/keepass2
        private void InitEntryTab()
        {
            m_pwEntryIcon = m_pwEntry.IconId;
            m_pwCustomIconID = m_pwEntry.CustomIconUuid;

            if(m_pwCustomIconID != 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_secPassword.Attach(m_tbPassword, ProcessTextChangedPassword, bHideInitial);
            m_secRepeat.Attach(m_tbRepeatPassword, ProcessTextChangedRepeatPw, bHideInitial);

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

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

            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_tbRepeatPassword.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;
        }
コード例 #33
0
 public void AssignDrawableTo(ImageView iv, Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId)
 {
 }
コード例 #34
0
 public Drawable GetIconDrawable(Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId)
 {
     return res.GetDrawable(Resource.Drawable.Icon);
 }
コード例 #35
0
ファイル: DrawableFactory.cs プロジェクト: pythe/wristpass
 public void AssignDrawableTo(ImageView iv, Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId)
 {
     Drawable draw = GetIconDrawable (res, db, icon, customIconId);
     iv.SetImageDrawable (draw);
 }
        /// <summary>
        /// The main routine, called when import is selected
        /// </summary>
        /// <param name="pwStorage"></param>
        /// <param name="sInput"></param>
        /// <param name="slLogger"></param>
        public override void Import(PwDatabase pwStorage, System.IO.Stream sInput, KeePassLib.Interfaces.IStatusLogger slLogger)
        {
            try
            {
                FormXml form = new FormXml();

                form.Initialise(pwStorage);

                //	form.GroupName = pwStorage.RootGroup.Name;

                //if (pwStorage.LastSelectedGroup != null)
                //{
                //    form.GroupName = pwStorage.RootGroup.FindGroup(pwStorage.LastSelectedGroup, true).Name;
                //}

                if (form.ShowDialog() == DialogResult.OK)
                {
                    bool overwritePassword = form.Overwrite;
                    bool searchWeb         = form.GetTitles;
                    bool checkMatches      = form.Merge;

                    bool addAutoType = form.AddAutoType;

                    PwIcon iconId = (PwIcon)Enum.Parse(typeof(PwIcon), form.IconName);

                    PwGroup group = form.Group;

                    if (group == null)
                    {
                        group = pwStorage.RootGroup;
                    }

                    try
                    {
                        InternetAccessor internetAccessor = new InternetAccessor();

                        slLogger.StartLogging("Importing Firefox File", false);

                        slLogger.SetText("Reading File", LogStatusType.Info);

                        // Load in the supplied xml document
                        XmlDocument       fireFoxDocument = new XmlDocument();
                        XmlReaderSettings settings        = new XmlReaderSettings();
                        settings.CheckCharacters = false;
                        settings.ValidationType  = ValidationType.None;

                        XmlReader reader = XmlTextReader.Create(sInput, settings);
                        try
                        {
                            fireFoxDocument.Load(reader);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Failed to load the password file. " + Environment.NewLine +
                                                "This may be due to the presence of foreign characters in the data. " + Environment.NewLine +
                                                "Please check the website for help" + Environment.NewLine + Environment.NewLine + ex.Message, ex);
                        }
                        finally
                        {
                            reader.Close();
                        }

                        // Get a collection of nodes that represent each password
                        XmlNodeList fireFoxEntryNodes = fireFoxDocument.SelectNodes("xml/entries/entry");

                        int count = fireFoxEntryNodes.Count;
                        int pos   = 0;

                        // Loop each entry and add it to KeePass
                        foreach (XmlElement fireFoxEntryElement in fireFoxEntryNodes)
                        {
                            if (!slLogger.ContinueWork()) // Check if process has been cancelled by the user
                            {
                                break;
                            }

                            // keep the user informed of progress
                            pos++;
                            slLogger.SetProgress((uint)(100 * ((double)pos) / ((double)count)));

                            // gather the data to import
                            string title = "HOST";

                            XmlNode hostNode          = fireFoxEntryElement.SelectSingleNode("@host");
                            XmlNode formSubmitURLNode = fireFoxEntryElement.SelectSingleNode("@formSubmitURL");
                            XmlNode userNode          = fireFoxEntryElement.SelectSingleNode("@user");
                            XmlNode passwordNode      = fireFoxEntryElement.SelectSingleNode("@password");

                            if (hostNode != null)
                            {
                                title = hostNode.InnerText;
                            }

                            slLogger.SetText(title, LogStatusType.Info);


                            string notes = String.Empty;

                            if (form.IncludeImportNotes)
                            {
                                notes += "Imported from FireFox by the Web Site Advantage FireFox to KeePass Importer" + Environment.NewLine;
                            }

                            string url = String.Empty;

                            if (hostNode != null)
                            {
                                url = hostNode.InnerText;
                            }

                            string formSubmitURL = String.Empty;

                            if (formSubmitURLNode != null)
                            {
                                formSubmitURL = formSubmitURLNode.InnerText;
                            }

                            if (!String.IsNullOrEmpty(formSubmitURL))
                            {
                                url = formSubmitURL;
                            }

                            string host = url;
                            try
                            {
                                Uri uri = new Uri(url);
                                host = uri.Host;
                            }
                            catch { }

                            string username = String.Empty;

                            if (userNode != null)
                            {
                                username = userNode.InnerText;
                            }

                            bool newEntry = true;

                            PwEntry pe = null;

                            if (checkMatches)
                            {
                                pe = KeePassHelper.FindMatchingEntry(pwStorage.RootGroup, url, username);
                            }

                            if (pe == null)
                            {
                                // create a new entry
                                pe = new PwEntry(true, true);
                                group.AddEntry(pe, true);
                                slLogger.SetText("Created new entry", LogStatusType.AdditionalInfo);
                            }
                            else
                            {
                                newEntry = false;
                                slLogger.SetText("Found matching entry", LogStatusType.AdditionalInfo);
                            }

                            if (newEntry || overwritePassword)
                            {
                                // set the password
                                if (passwordNode != null)
                                {
                                    pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pwStorage.MemoryProtection.ProtectPassword, passwordNode.InnerText));
                                }
                            }

                            if (newEntry)
                            {
                                // set all fields
                                pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pwStorage.MemoryProtection.ProtectTitle, title));
                                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pwStorage.MemoryProtection.ProtectUserName, username));
                                pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pwStorage.MemoryProtection.ProtectUrl, url));
                                if (!String.IsNullOrEmpty(notes))
                                {
                                    pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pwStorage.MemoryProtection.ProtectNotes, notes));
                                }
                                pe.Expires = false;
                                pe.IconId  = iconId;

                                // Gatter any extra information...

                                if (fireFoxEntryElement.HasAttribute("userFieldName") && fireFoxEntryElement.GetAttribute("userFieldName").Length > 0)
                                {
                                    pe.Strings.Set("UserNameField", new ProtectedString(false, fireFoxEntryElement.GetAttribute("userFieldName")));
                                }

                                if (fireFoxEntryElement.HasAttribute("usernameField") && fireFoxEntryElement.GetAttribute("usernameField").Length > 0)
                                {
                                    pe.Strings.Set("UserNameField", new ProtectedString(false, fireFoxEntryElement.GetAttribute("usernameField")));
                                }

                                if (fireFoxEntryElement.HasAttribute("passFieldName") && fireFoxEntryElement.GetAttribute("passFieldName").Length > 0)
                                {
                                    pe.Strings.Set("PasswordField", new ProtectedString(false, fireFoxEntryElement.GetAttribute("passFieldName")));
                                }

                                if (fireFoxEntryElement.HasAttribute("passwordField") && fireFoxEntryElement.GetAttribute("passwordField").Length > 0)
                                {
                                    pe.Strings.Set("PasswordField", new ProtectedString(false, fireFoxEntryElement.GetAttribute("passwordField")));
                                }

                                if (fireFoxEntryElement.HasAttribute("httpRealm") && fireFoxEntryElement.GetAttribute("httpRealm").Length > 0)
                                {
                                    pe.Strings.Set("HttpRealm", new ProtectedString(false, fireFoxEntryElement.GetAttribute("httpRealm")));
                                }

                                if (fireFoxEntryElement.HasAttribute("formSubmitURL") && fireFoxEntryElement.GetAttribute("formSubmitURL").Length > 0)
                                {
                                    pe.Strings.Set("LoginFormDomain", new ProtectedString(false, fireFoxEntryElement.GetAttribute("formSubmitURL")));
                                }
                            }

                            string webTitle = null;
                            // if new or the title is the same as the url then we should try and get the title
                            if (searchWeb)
                            {
                                // test if new or entry has url as title
                                if ((newEntry || pe.Strings.Get(PwDefs.TitleField).ReadString() == pe.Strings.Get(PwDefs.UrlField).ReadString()))
                                {
                                    // get the pages title
                                    slLogger.SetText("Accessing website for title", LogStatusType.AdditionalInfo);

                                    webTitle = internetAccessor.ScrapeTitle(url);

                                    if (!String.IsNullOrEmpty(webTitle))
                                    {
                                        // PATCH: supplied by Sarel Botha
                                        // remove protocol from site so that it works with new KeepassHTTP
                                        if (webTitle.StartsWith("http://"))
                                        {
                                            webTitle = webTitle.Substring(7);
                                        }
                                        if (webTitle.StartsWith("https://"))
                                        {
                                            webTitle = webTitle.Substring(8);
                                        }

                                        // remove port number if the title contains it so that it will work with new KeepassHTTP
                                        if (webTitle.Contains(":"))
                                        {
                                            webTitle = webTitle.Substring(0, webTitle.IndexOf(':'));
                                        }
                                        // PATCH END

                                        slLogger.SetText("Title set from internet to " + webTitle, LogStatusType.AdditionalInfo);

                                        pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pwStorage.MemoryProtection.ProtectTitle, webTitle));
                                    }
                                }
                            }

                            if (addAutoType)
                            {
                                KeePassHelper.InsertAutoType(pe, "*" + host + "*", KeePassUtilities.AutoTypeSequence());
                            }

                            if (webTitle != null && addAutoType)
                            {
                                KeePassHelper.InsertAutoType(pe, KeePassUtilities.AutoTypeWindow(webTitle), KeePassUtilities.AutoTypeSequence());
                            }
                        }
                    }
                    finally
                    {
                        slLogger.EndLogging();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Failed to Validate Password"))
                {
                    MessageBox.Show(ex.Message, "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    ErrorMessage.ShowErrorMessage("Importer Xml", "Import Failed", ex);
                }
            }
        }
コード例 #37
0
		private static PwIcon ReadIcon(XmlNode xmlChild, PwIcon pwDefault)
		{
			uint uIcon;
			if(StrUtil.TryParseUInt(XmlUtil.SafeInnerText(xmlChild), out uIcon))
			{
				if(uIcon < (uint)PwIcon.Count) return (PwIcon)uIcon;
			}
			else { Debug.Assert(false); }

			return pwDefault;
		}
コード例 #38
0
ファイル: PwEntryForm.cs プロジェクト: jonbws/strengthreport
        private void InitEntryTab()
        {
            m_pwEntryIcon = m_pwEntry.IconId;
            m_pwCustomIconID = m_pwEntry.CustomIconUuid;

            if(m_pwCustomIconID != 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];
            }
            else m_btnIcon.Image = m_ilIcons.Images[(int)m_pwEntryIcon];

            bool bHideInitial = m_cbHidePassword.Checked;
            m_secPassword.Attach(m_tbPassword, ProcessTextChangedPassword, bHideInitial);
            m_secRepeat.Attach(m_tbRepeatPassword, ProcessTextChangedRepeatPw, bHideInitial);

            m_tbTitle.Text = m_vStrings.ReadSafe(PwDefs.TitleField);
            m_tbUserName.Text = m_vStrings.ReadSafe(PwDefs.UserNameField);

            byte[] pb = m_vStrings.GetSafe(PwDefs.PasswordField).ReadUtf8();
            m_secPassword.SetPassword(pb);
            m_secRepeat.SetPassword(pb);
            MemUtil.ZeroByteArray(pb);

            m_tbUrl.Text = m_vStrings.ReadSafe(PwDefs.UrlField);
            m_rtNotes.Text = m_vStrings.ReadSafe(PwDefs.NotesField);

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

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

            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_tbRepeatPassword.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_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;
        }
コード例 #39
0
ファイル: EntryMenu.cs プロジェクト: ashwingj/keepass2
        private static int MenuGetImageIndex(PwDocument ds, PwIcon pwID,
            PwUuid pwCustomID)
        {
            if((pwCustomID != 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;
        }
コード例 #40
0
ファイル: KeePassRPCService.cs プロジェクト: krbvroc1/KeeFox
        /// <summary>
        /// extract the current icon information for this entry
        /// </summary>
        /// <param name="customIconUUID"></param>
        /// <param name="iconId"></param>
        /// <returns></returns>
        private string iconToBase64(PwUuid customIconUUID, PwIcon iconId)
        {
            Image icon = null;
            PwUuid uuid = null;

            string imageData = "";
            if (customIconUUID != PwUuid.Zero)
            {
                string cachedBase64 = DataExchangeModel.IconCache.GetIconEncoding(customIconUUID);
                if (string.IsNullOrEmpty(cachedBase64))
                {
                    object[] delParams = { customIconUUID };
                    object invokeResult = host.MainWindow.Invoke(
                        new KeePassRPCExt.GetCustomIconDelegate(
                            KeePassRPCPlugin.GetCustomIcon), delParams);
                    if (invokeResult != null)
                    {
                        icon = (Image)invokeResult;
                    }
                    if (icon != null)
                    {
                        uuid = customIconUUID;
                    }
                } else
                {
                    return cachedBase64;
                }
            }

            // this happens if we didn't want to or couldn't find a custom icon
            if (icon == null)
            {
                int iconIdInt = (int)iconId;
                uuid = new PwUuid( new byte[]{
                    (byte)(iconIdInt & 0xFF), (byte)(iconIdInt & 0xFF),
                    (byte)(iconIdInt & 0xFF), (byte)(iconIdInt & 0xFF),
                    (byte)(iconIdInt >> 8 & 0xFF), (byte)(iconIdInt >> 8 & 0xFF),
                    (byte)(iconIdInt >> 8 & 0xFF), (byte)(iconIdInt >> 8 & 0xFF),
                    (byte)(iconIdInt >> 16 & 0xFF), (byte)(iconIdInt >> 16 & 0xFF),
                    (byte)(iconIdInt >> 16 & 0xFF), (byte)(iconIdInt >> 16 & 0xFF),
                    (byte)(iconIdInt >> 24 & 0xFF), (byte)(iconIdInt >> 24 & 0xFF),
                    (byte)(iconIdInt >> 24 & 0xFF), (byte)(iconIdInt >> 24 & 0xFF)
                } );

                string cachedBase64 = DataExchangeModel.IconCache.GetIconEncoding(uuid);
                if (string.IsNullOrEmpty(cachedBase64))
                {
                    object[] delParams = { (int)iconId };
                    object invokeResult = host.MainWindow.Invoke(
                        new KeePassRPCExt.GetIconDelegate(
                            KeePassRPCPlugin.GetIcon), delParams);
                    if (invokeResult != null)
                    {
                        icon = (Image)invokeResult;
                    }
                } else
                {
                    return cachedBase64;
                }
            }

            if (icon != null)
            {
                // we found an icon but it wasn't in the cache so lets
                // calculate its base64 encoding and then add it to the cache
                MemoryStream ms = new MemoryStream();
                icon.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                imageData = Convert.ToBase64String(ms.ToArray());
                DataExchangeModel.IconCache.AddIcon(uuid, imageData);
            }

            return imageData;
        }
コード例 #41
0
 public Drawable GetIconDrawable(Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId, bool forGroup)
 {
     return(res.GetDrawable(Resource.Drawable.Icon));
 }
コード例 #42
0
ファイル: PrintForm.cs プロジェクト: knut0815/KeePass2
        private static string MakeIconImg(PwIcon i, PwUuid ci, ITimeLogger tl, PfOptions p)
        {
            if (p.ClientIcons == null)
            {
                return(string.Empty);
            }

            Image img = null;

            if ((tl != null) && tl.Expires && (tl.ExpiryTime <= p.Now))
            {
                i  = PwIcon.Expired;
                ci = null;
            }

            PwDatabase pd = p.Database;

            if ((ci != null) && !ci.Equals(PwUuid.Zero) && (pd != null))
            {
                int cix = pd.GetCustomIconIndex(ci);
                if (cix >= 0)
                {
                    cix += (int)PwIcon.Count;
                    if (cix < p.ClientIcons.Images.Count)
                    {
                        img = p.ClientIcons.Images[cix];
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            int ix = (int)i;

            if ((img == null) && (ix >= 0) && (ix < p.ClientIcons.Images.Count))
            {
                img = p.ClientIcons.Images[ix];
            }

            string strData = GfxUtil.ImageToDataUri(img);

            if (string.IsNullOrEmpty(strData))
            {
                Debug.Assert(false); return(string.Empty);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<img src=\"");
            sb.Append(strData);
            sb.AppendLine("\"");
            sb.Append("class=\"icon_cli\" alt=\"\" />&nbsp;");

            return(sb.ToString());
        }
コード例 #43
0
ファイル: GroupForm.cs プロジェクト: sinelaw/keepass
        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);
        }
コード例 #44
0
        public static PwGroup FindOrCreateGroupWithAttribute(this PwDatabase database, KeeShare.AttributeFlags attribute, string name, PwIcon icon = PwIcon.Folder)
        {
            foreach (PwGroup aGroup in database.RootGroup.GetGroups(true))
            {
                if (aGroup.IsCustomAttributeSet(attribute))
                {
                    return(aGroup);
                }
            }
            //if we cant find the group yet, we create a new one and add it to the rootGroup
            PwGroup group = new PwGroup(true, true, name, icon);

            group.SetCustomAttribute(attribute, true);
            group.SetParent(database.RootGroup);
            Debug.Assert(null != group, "group for " + attribute + " - " + name + " is 'null' but should not!");
            return(group);
        }
コード例 #45
0
ファイル: GroupForm.cs プロジェクト: 0xfeeddeadbeef/KeePass
        private void OnFormLoad(object sender, EventArgs e)
        {
            if (m_pwGroup == null)
            {
                Debug.Assert(false); throw new InvalidOperationException();
            }
            if (m_pwDatabase == null)
            {
                Debug.Assert(false); 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 = AppIcons.Default;
            this.Text = strTitle;

            UIUtil.ConfigureToolTip(m_ttRect);
            UIUtil.SetToolTip(m_ttRect, m_btnIcon, KPRes.SelectIcon, true);
            UIUtil.SetToolTip(m_ttRect, m_btnAutoTypeEdit, KPRes.ConfigureKeystrokeSeq, true);

            UIUtil.AccSetName(m_dtExpires, m_cbExpires);
            UIUtil.AccSetName(m_tbDefaultAutoTypeSeq, m_rbAutoTypeOverride);

            m_tbName.Text = m_pwGroup.Name;

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

            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);
            }

            UIUtil.SetMultilineText(m_tbNotes, m_pwGroup.Notes);

            if (m_pwGroup.Expires)
            {
                m_dtExpires.Value   = TimeUtil.ToLocal(m_pwGroup.ExpiryTime, true);
                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);

            TagUtil.MakeInheritedTagsLink(m_linkTagsInh, m_pwGroup.ParentGroup, this);
            m_tbTags.Text = StrUtil.TagsToString(m_pwGroup.Tags, true);
            TagUtil.MakeTagsButton(m_btnTags, m_tbTags, m_ttRect, m_pwGroup.ParentGroup,
                                   ((m_pwDatabase != null) ? m_pwDatabase.RootGroup : null));

            m_tbUuid.Text = m_pwGroup.Uuid.ToHexString() + ", " +
                            Convert.ToBase64String(m_pwGroup.Uuid.UuidBytes);

            PwGroup pgParent = m_pwGroup.ParentGroup;

            bool bParentSearching = ((pgParent != null) ?
                                     pgParent.GetSearchingEnabledInherited() :
                                     PwGroup.DefaultSearchingEnabled);

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

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

            UIUtil.MakeInheritableBoolComboBox(m_cmbEnableAutoType,
                                               m_pwGroup.EnableAutoType, bParentAutoType);

            m_tbDefaultAutoTypeSeq.Text = m_pwGroup.GetAutoTypeSequenceInherited();

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

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

            m_sdCustomData = m_pwGroup.CustomData.CloneDeep();
            UIUtil.StrDictListInit(m_lvCustomData);
            UIUtil.StrDictListUpdate(m_lvCustomData, m_sdCustomData, false);

            EnableControlsEx();

            ThreadPool.QueueUserWorkItem(delegate(object state)
            {
                try
                {
                    string[] vSeq = m_pwDatabase.RootGroup.GetAutoTypeSequences(true);
                    // Do not append, because long suggestions hide the start
                    UIUtil.EnableAutoCompletion(m_tbDefaultAutoTypeSeq,
                                                false, vSeq); // Invokes
                }
                catch (Exception) { Debug.Assert(false); }
            });

            UIUtil.SetFocus(m_tbName, this);

            switch (m_gftInit)
            {
            case GroupFormTab.Properties:
                m_tabMain.SelectedTab = m_tabProperties; break;

            case GroupFormTab.AutoType:
                m_tabMain.SelectedTab = m_tabAutoType; break;

            case GroupFormTab.CustomData:
                m_tabMain.SelectedTab = m_tabCustomData; break;

            default: break;
            }
        }
コード例 #46
0
        public static PwGroup FindOrCreateGroupWithAttribute(this PwDatabase database, KeeShare.AttributeFlags attribute, string name, PwGroup parent, PwIcon icon = PwIcon.Folder)
        {
            PwGroup group = database.FindOrCreateGroupWithAttribute(attribute, name, icon);

            if (group.ParentGroup != parent)
            {
                group.MoveToParent(parent);
            }
            return(group);
        }
コード例 #47
0
ファイル: GroupForm.cs プロジェクト: haro-freezd/KeePass
        private void OnBtnIcon(object sender, EventArgs e)
        {
            IconPickerForm ipf = new IconPickerForm();
            ipf.InitEx(m_ilClientIcons, (uint)PwIcon.Count, m_pwDatabase,
                (uint)m_pwIconIndex, m_pwCustomIconID);

            if(ipf.ShowDialog() == DialogResult.OK)
            {
                if(!ipf.ChosenCustomIconUuid.Equals(PwUuid.Zero)) // Custom icon
                {
                    m_pwCustomIconID = ipf.ChosenCustomIconUuid;
                    UIUtil.SetButtonImage(m_btnIcon, DpiUtil.GetIcon(
                        m_pwDatabase, m_pwCustomIconID), true);
                }
                else // Standard icon
                {
                    m_pwIconIndex = (PwIcon)ipf.ChosenIconId;
                    m_pwCustomIconID = PwUuid.Zero;
                    UIUtil.SetButtonImage(m_btnIcon, m_ilClientIcons.Images[
                        (int)m_pwIconIndex], true);
                }
            }

            UIUtil.DestroyForm(ipf);
        }
コード例 #48
0
 public static PwGroup FindCreateGroup(this PwDatabase database, string tag, string name, PwGroup parent, PwIcon icon = PwIcon.Folder)
 {
     PwGroup group = database.FindCreateGroup(tag, name, icon);
     if( group.ParentGroup != parent)
     {
         group.MoveToParent(parent);
     }
     return group;
 }
コード例 #49
0
 public static PwGroup FindCreateGroup(this PwDatabase database, string tag, string name, PwIcon icon = PwIcon.Folder)
 {
     foreach (PwGroup rootGroup in database.RootGroup.GetGroups(true))
     {
         if (rootGroup.Notes.Contains(tag))
         {
             return rootGroup;
         }
     }
     //if we cant find the group yet, we create a new one and add it to the rootGroup
     PwGroup group = new PwGroup(true, true, name, icon);
     group.Notes = tag;
     group.SetParent(database.RootGroup);
     Debug.Assert(null != group, "group for " + tag + " - " + name + " is 'null' but should not!");
     return group;
 }
コード例 #50
0
        /// <summary>
        /// extract the current icon information for this entry
        /// </summary>
        /// <param name="customIconUUID"></param>
        /// <param name="iconId"></param>
        /// <returns></returns>
        public string iconToBase64(PwUuid customIconUUID, PwIcon iconId)
        {
            Image  icon = null;
            PwUuid uuid = null;

            string imageData = "";

            if (customIconUUID != PwUuid.Zero)
            {
                string cachedBase64 = DataExchangeModel.IconCache <PwUuid> .GetIconEncoding(customIconUUID);

                if (string.IsNullOrEmpty(cachedBase64))
                {
                    object[] delParams    = { customIconUUID };
                    object   invokeResult = host.MainWindow.Invoke(
                        new KeePassRPCExt.GetCustomIconDelegate(
                            KeePassRPCPlugin.GetCustomIcon), delParams);
                    if (invokeResult != null)
                    {
                        icon = (Image)invokeResult;
                    }
                    if (icon != null)
                    {
                        uuid = customIconUUID;
                    }
                }
                else
                {
                    return(cachedBase64);
                }
            }

            // this happens if we didn't want to or couldn't find a custom icon
            if (icon == null)
            {
                int iconIdInt = (int)iconId;
                uuid = new PwUuid(new byte[] {
                    (byte)(iconIdInt & 0xFF), (byte)(iconIdInt & 0xFF),
                    (byte)(iconIdInt & 0xFF), (byte)(iconIdInt & 0xFF),
                    (byte)(iconIdInt >> 8 & 0xFF), (byte)(iconIdInt >> 8 & 0xFF),
                    (byte)(iconIdInt >> 8 & 0xFF), (byte)(iconIdInt >> 8 & 0xFF),
                    (byte)(iconIdInt >> 16 & 0xFF), (byte)(iconIdInt >> 16 & 0xFF),
                    (byte)(iconIdInt >> 16 & 0xFF), (byte)(iconIdInt >> 16 & 0xFF),
                    (byte)(iconIdInt >> 24 & 0xFF), (byte)(iconIdInt >> 24 & 0xFF),
                    (byte)(iconIdInt >> 24 & 0xFF), (byte)(iconIdInt >> 24 & 0xFF)
                });

                string cachedBase64 = DataExchangeModel.IconCache <PwUuid> .GetIconEncoding(uuid);

                if (string.IsNullOrEmpty(cachedBase64))
                {
                    object[] delParams    = { (int)iconId };
                    object   invokeResult = host.MainWindow.Invoke(
                        new KeePassRPCExt.GetIconDelegate(
                            KeePassRPCPlugin.GetIcon), delParams);
                    if (invokeResult != null)
                    {
                        icon = (Image)invokeResult;
                    }
                }
                else
                {
                    return(cachedBase64);
                }
            }


            if (icon != null)
            {
                // we found an icon but it wasn't in the cache so lets
                // calculate its base64 encoding and then add it to the cache
                using (MemoryStream ms = new MemoryStream())
                {
                    lock (iconSavingLock)
                    {
                        icon.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    }
                    imageData = Convert.ToBase64String(ms.ToArray());
                }
                DataExchangeModel.IconCache <PwUuid> .AddIcon(uuid, imageData);
            }

            return(imageData);
        }
コード例 #51
0
        private static PwIcon ReadIcon(XmlNode xmlChild, PwIcon pwDefault)
        {
            int nIcon;
            if(StrUtil.TryParseInt(XmlUtil.SafeInnerText(xmlChild), out nIcon))
            {
                if((nIcon >= 0) && (nIcon < (int)PwIcon.Count)) return (PwIcon)nIcon;
            }
            else { Debug.Assert(false); }

            return pwDefault;
        }
コード例 #52
0
        public static string GetIconPath(PwIcon iconId)
        {
            string path = ICON_PATH_BASE;

            switch (iconId)
            {
            case PwIcon.Key:
                path += "C00_Password.png";
                break;

            case PwIcon.World:
                path += "C01_Package_Network.png";
                break;

            case PwIcon.Warning:
                path += "C02_MessageBox_Warning.png";
                break;

            case PwIcon.NetworkServer:
                path += "C03_Server.png";
                break;

            case PwIcon.MarkedDirectory:
                path += "C04_Klipper.png";
                break;

            case PwIcon.UserCommunication:
                path += "C05_Edu_Languages.png";
                break;

            case PwIcon.Parts:
                path += "C06_KCMDF.png";
                break;

            case PwIcon.Notepad:
                path += "C07_Kate.png";
                break;

            case PwIcon.WorldSocket:
                path += "C08_Socket.png";
                break;

            case PwIcon.Identity:
                path += "C09_Identity.png";
                break;

            case PwIcon.PaperReady:
                path += "C10_Kontact.png";
                break;

            case PwIcon.Digicam:
                path += "C11_Camera.png";
                break;

            case PwIcon.IRCommunication:
                path += "C12_IRKickFlash.png";
                break;

            case PwIcon.MultiKeys:
                path += "C13_KGPG_Key3.png";
                break;

            case PwIcon.Energy:
                path += "C14_Laptop_Power.png";
                break;

            case PwIcon.Scanner:
                path += "C15_Scanner.png";
                break;

            case PwIcon.WorldStar:
                path += "C16_Mozilla_Firebird.png";
                break;

            case PwIcon.CDRom:
                path += "C17_CDROM_Unmount.png";
                break;

            case PwIcon.Monitor:
                path += "C18_Display.png";
                break;

            case PwIcon.EMail:
                path += "C19_Mail_Generic.png";
                break;

            case PwIcon.Configuration:
                path += "C20_Misc.png";
                break;

            case PwIcon.ClipboardReady:
                path += "C21_KOrganizer.png";
                break;

            case PwIcon.PaperNew:
                path += "C22_ASCII.png";
                break;

            case PwIcon.Screen:
                path += "C23_Icons.png";
                break;

            case PwIcon.EnergyCareful:
                path += "C24_Connect_Established.png";
                break;

            case PwIcon.EMailBox:
                path += "C25_Folder_Mail.png";
                break;

            case PwIcon.Disk:
                path += "C26_FileSave.png";
                break;

            case PwIcon.Drive:
                path += "C27_NFS_Unmount.png";
                break;

            case PwIcon.PaperQ:
                path += "C28_Message.png";
                break;

            case PwIcon.TerminalEncrypted:
                path += "C29_KGPG_Term.png";
                break;

            case PwIcon.Console:
                path += "C30_Konsole.png";
                break;

            case PwIcon.Printer:
                path += "C31_FilePrint.png";
                break;

            case PwIcon.ProgramIcons:
                path += "C32_FSView.png";
                break;

            case PwIcon.Run:
                path += "C33_Run.png";
                break;

            case PwIcon.Settings:
                path += "C34_Configure.png";
                break;

            case PwIcon.WorldComputer:
                path += "C35_KRFB.png";
                break;

            case PwIcon.Archive:
                path += "C36_Ark.png";
                break;

            case PwIcon.Homebanking:
                path += "C37_KPercentage.png";
                break;

            case PwIcon.DriveWindows:
                path += "C38_Samba_Unmount.png";
                break;

            case PwIcon.Clock:
                path += "C39_History.png";
                break;

            case PwIcon.EMailSearch:
                path += "C40_Mail_Find.png";
                break;

            case PwIcon.PaperFlag:
                path += "C41_VectorGfx.png";
                break;

            case PwIcon.Memory:
                path += "C42_KCMMemory.png";
                break;

            case PwIcon.TrashBin:
                path += "C43_Trashcan_Full.png";
                break;

            case PwIcon.Note:
                path += "C44_KNotes.png";
                break;

            case PwIcon.Expired:
                path += "C45_Cancel.png";
                break;

            case PwIcon.Info:
                path += "C46_Help.png";
                break;

            case PwIcon.Package:
                path += "C47_KPackage.png";
                break;

            case PwIcon.Folder:
                path += "C48_Folder.png";
                break;

            case PwIcon.FolderOpen:
                path += "C49_Folder_Blue_Open.png";
                break;

            case PwIcon.FolderPackage:
                path += "C50_Folder_Tar.png";
                break;

            case PwIcon.LockOpen:
                path += "C51_Decrypted.png";
                break;

            case PwIcon.PaperLocked:
                path += "C52_Encrypted.png";
                break;

            case PwIcon.Checked:
                path += "C53_Apply.png";
                break;

            case PwIcon.Pen:
                path += "C54_Signature.png";
                break;

            case PwIcon.Thumbnail:
                path += "C55_Thumbnail.png";
                break;

            case PwIcon.Book:
                path += "C56_KAddressBook.png";
                break;

            case PwIcon.List:
                path += "C57_View_Text.png";
                break;

            case PwIcon.UserKey:
                path += "C58_KGPG.png";
                break;

            case PwIcon.Tool:
                path += "C59_Package_Development.png";
                break;

            case PwIcon.Home:
                path += "C60_KFM_Home.png";
                break;

            case PwIcon.Star:
                path += "C61_Services.png";
                break;

            case PwIcon.Tux:
                path += "C62_Tux.png";
                break;

            case PwIcon.Feather:
                path += "C63_Feather.png";
                break;

            case PwIcon.Apple:
                path += "C64_Apple.png";
                break;

            case PwIcon.Wiki:
                path += "C65_W.png";
                break;

            case PwIcon.Money:
                path += "C66_Money.png";
                break;

            case PwIcon.Certificate:
                path += "C67_Certificate.png";
                break;

            case PwIcon.BlackBerry:
                path += "C68_Smartphone.png";
                break;

            default:
                path = String.Empty;
                break;
            }

            return(path);
        }
コード例 #53
0
ファイル: GroupForm.cs プロジェクト: jonbws/strengthreport
        private void OnBtnIcon(object sender, EventArgs e)
        {
            IconPickerForm ipf = new IconPickerForm();
            ipf.InitEx(m_ilClientIcons, (uint)PwIcon.Count, m_pwDatabase,
                (uint)m_pwIconIndex, m_pwCustomIconID);

            if(ipf.ShowDialog() == DialogResult.OK)
            {
                if(ipf.ChosenCustomIconUuid != PwUuid.Zero) // Custom icon
                {
                    m_pwCustomIconID = ipf.ChosenCustomIconUuid;
                    m_btnIcon.Image = m_pwDatabase.GetCustomIcon(m_pwCustomIconID);
                }
                else // Standard icon
                {
                    m_pwIconIndex = (PwIcon)ipf.ChosenIconId;
                    m_pwCustomIconID = PwUuid.Zero;
                    m_btnIcon.Image = m_ilClientIcons.Images[(int)m_pwIconIndex];
                }
            }
        }
コード例 #54
0
ファイル: PwEntryForm.cs プロジェクト: rdealexb/keepass
        private void OnBtnPickIcon(object sender, EventArgs e)
        {
            if(m_pwEditMode == PwEditMode.ViewReadOnlyEntry) return;

            IconPickerForm ipf = new IconPickerForm();
            ipf.InitEx(m_ilIcons, (uint)PwIcon.Count, m_pwDatabase,
                (uint)m_pwEntryIcon, m_pwCustomIconID);

            if(ipf.ShowDialog() == DialogResult.OK)
            {
                if(!ipf.ChosenCustomIconUuid.Equals(PwUuid.Zero)) // Custom icon
                {
                    m_pwCustomIconID = ipf.ChosenCustomIconUuid;
                    UIUtil.SetButtonImage(m_btnIcon, m_pwDatabase.GetCustomIcon(
                        m_pwCustomIconID), true);
                }
                else // Standard icon
                {
                    m_pwEntryIcon = (PwIcon)ipf.ChosenIconId;
                    m_pwCustomIconID = PwUuid.Zero;
                    UIUtil.SetButtonImage(m_btnIcon, m_ilIcons.Images[
                        (int)m_pwEntryIcon], true);
                }
            }

            UIUtil.DestroyForm(ipf);
        }
コード例 #55
0
ファイル: KeePassRPCService.cs プロジェクト: krbvroc1/KeeFox
        /// <summary>
        /// converts a string to the relevant icon for this entry
        /// </summary>
        /// <param name="imageData">base64 representation of the image</param>
        /// <param name="customIconUUID">UUID of the generated custom icon; may be Zero</param>
        /// <param name="iconId">PwIcon of the matched standard icon; ignore if customIconUUID != Zero</param>
        /// <returns>true if the supplied imageData was converted into a customIcon 
        /// or matched with a standard icon.</returns>
        private bool base64ToIcon(string imageData, ref PwUuid customIconUUID, ref PwIcon iconId)
        {
            iconId = PwIcon.Key;
            customIconUUID = PwUuid.Zero;

            for (int i = 0; i < _standardIconsBase64.Length; i++)
            {
                string item = _standardIconsBase64[i];
                if (item == imageData)
                {
                    iconId = (PwIcon)i;
                    return true;
                }
            }

            try
            {
                //MemoryStream id = new MemoryStream();
                //icon.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                Image img = KeePass.UI.UIUtil.LoadImage(Convert.FromBase64String(imageData));

                Image imgNew = new Bitmap(img, new Size(16, 16));

                MemoryStream ms = new MemoryStream();
                imgNew.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                byte[] msByteArray = ms.ToArray();

                foreach (PwCustomIcon item in host.Database.CustomIcons)
                {
                    // re-use existing custom icon if it's already in the database
                    // (This will probably fail if database is used on
                    // both 32 bit and 64 bit machines - not sure why...)
                    if (KeePassLib.Utility.MemUtil.ArraysEqual(msByteArray, item.ImageDataPng))
                    {
                        customIconUUID = item.Uuid;
                        host.Database.UINeedsIconUpdate = true;
                        return true;
                    }
                }

                PwCustomIcon pwci = new PwCustomIcon(new PwUuid(true),
                    msByteArray);
                host.Database.CustomIcons.Add(pwci);

                customIconUUID = pwci.Uuid;
                host.Database.UINeedsIconUpdate = true;

                return true;
            }
            catch
            {
                return false;
            }
        }
コード例 #56
0
 private int GetDictionaryKey(PwIcon icon, bool forGroup)
 {
     return(((int)icon) + (forGroup ? FolderOffset : 0));
 }