Beispiel #1
0
 public Drawable GetIconDrawable(Resources res, PwDatabase db, PwIcon icon, PwUuid customIconId)
 {
     if (!customIconId.Equals(PwUuid.Zero)) {
         return GetIconDrawable (res, db, customIconId);
     }
     return GetIconDrawable (res, icon);
 }
Beispiel #2
0
 private PwEntry GetConfigEntry(PwDatabase db)
 {
     var kphe = new KeePassHttpExt();
     var root = db.RootGroup;
     var uuid = new PwUuid(kphe.KEEPASSHTTP_UUID);
     var entry = root.FindEntry(uuid, false);
     return entry;
 }
Beispiel #3
0
		private void OnFormLoad(object sender, EventArgs e)
		{
			Debug.Assert(m_pwGroup != null); if(m_pwGroup == null) throw new InvalidOperationException();
			Debug.Assert(m_pwDatabase != null); if(m_pwDatabase == null) throw new InvalidOperationException();

			GlobalWindowManager.AddWindow(this);

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

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

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

			m_pwIconIndex = m_pwGroup.IconId;
			m_pwCustomIconID = m_pwGroup.CustomIconUuid;
			
			m_tbName.Text = m_pwGroup.Name;
			m_tbNotes.Text = m_pwGroup.Notes;

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

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

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

			m_tbDefaultAutoTypeSeq.Text = m_pwGroup.GetAutoTypeSequenceInherited();

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

			CustomizeForScreenReader();
			EnableControlsEx();
		}
Beispiel #4
0
		public void InitEx(ImageList ilIcons, uint uNumberOfStandardIcons,
			PwDatabase pwDatabase, uint uDefaultIcon, PwUuid pwCustomIconUuid)
		{
			m_ilIcons = ilIcons;
			m_uNumberOfStandardIcons = uNumberOfStandardIcons;
			m_pwDatabase = pwDatabase;
			m_uDefaultIcon = uDefaultIcon;
			m_pwDefaultCustomIcon = pwCustomIconUuid;
		}
		public EcasEventType Find(PwUuid uuid)
		{
			if(uuid == null) throw new ArgumentNullException("uuid");

			foreach(EcasEventType t in m_events)
			{
				if(t.Type.Equals(uuid)) return t;
			}

			return null;
		}
        public EcasActionType Find(PwUuid uuid)
        {
            if(uuid == null) throw new ArgumentNullException("uuid");

            foreach(EcasActionType t in m_actions)
            {
                if(t.Type.EqualsValue(uuid)) return t;
            }

            return null;
        }
Beispiel #7
0
 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];
     }
 }
		public bool IsSupported(PwUuid uuidType)
		{
			if(uuidType == null) throw new ArgumentNullException("uuidType");

			foreach(EcasConditionType t in m_conditions)
			{
				if(t.Type.EqualsValue(uuidType))
					return true;
			}

			return false;
		}
Beispiel #9
0
        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);
        }
Beispiel #10
0
		public bool IsSupported(PwUuid uuidType)
		{
			if(uuidType == null) throw new ArgumentNullException("uuidType");

			foreach(EcasEventType t in m_events)
			{
				if(t.Type.Equals(uuidType))
					return true;
			}

			return false;
		}
Beispiel #11
0
        public static bool RemoveFactory(PwUuid u)
        {
            if(u == null) { Debug.Assert(false); return false; }

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

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

            return (l.Count != cInitial);
        }
Beispiel #12
0
		public static string GetCacheDirectory(PwUuid pwPluginUuid, bool bEnsureExists)
		{
			string strPlgID = Convert.ToBase64String(pwPluginUuid.UuidBytes,
				Base64FormattingOptions.None);
			strPlgID = StrUtil.AlphaNumericOnly(strPlgID);
			if(strPlgID.Length > 16) strPlgID = strPlgID.Substring(0, 16);

			string strDir = GetCacheRoot() + Path.DirectorySeparatorChar +
				strPlgID + "_" + GetAppID();

			if(bEnsureExists && !Directory.Exists(strDir))
				Directory.CreateDirectory(strDir);

			return strDir;
		}
Beispiel #13
0
        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);
        }
Beispiel #14
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);
		}
 public SyncSource(PwEntry entry, PwDatabase dest)
 {
     m_sourceEntryUuid = entry.Uuid;
     string location = entry.Strings.ReadSafe( KeeShare.SourcePathField);
     if (IOConnectionInfo.FromPath(location).CanProbablyAccess())
     {
         m_location = location;
     }
     Key = CreateKeyFor( entry );
     m_destinationDB = dest;
     m_watcher.Changed += new FileSystemEventHandler( OnChanged );
     m_watcher.Path = Path.GetDirectoryName(m_location);
     m_watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime;
     m_watcher.Filter = Path.GetFileName(m_location);
 }
Beispiel #16
0
        private PwEntry GetConfigEntry(PwDatabase db)
        {
            var kphe = new KeePassHttpExt();
            var root = db.RootGroup;

            // Get stored RootGroup from config if any
            if (_config.RootGroup != "")
            {
                var GroupUuid = new PwUuid(StringToByteArray(_config.RootGroupUuid));
                root = root.FindGroup(GroupUuid, true);
            }

            var uuid = new PwUuid(kphe.KEEPASSHTTP_UUID);
            var entry = root.FindEntry(uuid, false);
            return entry;
        }
		internal static void RemoveCustomIconUuid(PwEntry pe, List<PwUuid> vToDelete)
		{
			PwUuid uuidThis = pe.CustomIconUuid;
			if(uuidThis.EqualsValue(PwUuid.Zero)) return;

			foreach(PwUuid uuidDelete in vToDelete)
			{
				if(uuidThis.EqualsValue(uuidDelete))
				{
					pe.CustomIconUuid = PwUuid.Zero;
					break;
				}
			}

			foreach(PwEntry peHistory in pe.History)
				RemoveCustomIconUuid(peHistory, vToDelete);
		}
Beispiel #18
0
        /// <summary>
        /// Get the index of a custom icon.
        /// </summary>
        /// <param name="pwIconId">ID of the icon.</param>
        /// <returns>Index of the icon.</returns>
        public int GetCustomIconIndex(PwUuid pwIconId)
        {
            int nIndex = 0;

            foreach (PwCustomIcon pwci in m_vCustomIcons)
            {
                if (pwci.Uuid.EqualsValue(pwIconId))
                {
                    return(nIndex);
                }

                ++nIndex;
            }

            // Debug.Assert(false); // Do not assert
            return(-1);
        }
Beispiel #19
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>
        /// <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 && (peTemplate.m_tLastMod < m_tLastMod))
            {
                return;
            }

            // Template UUID should be the same as the current one
            Debug.Assert(m_uuid.EqualsValue(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;
        }
Beispiel #20
0
        /// <summary>
        /// Compare this UUID with another.
        /// </summary>
        /// <param name="uuid">Second UUID object.</param>
        /// <returns>Returns <c>true</c> if both PwUuid object contain the same
        /// value, otherwise <c>false</c> is returned.</returns>
        public bool EqualsValue(PwUuid uuid)
        {
            Debug.Assert(uuid != null);
            if (uuid == null)
            {
                throw new ArgumentNullException("uuid");
            }

            for (int i = 0; i < UuidSize; ++i)
            {
                if (m_pbUuid[i] != uuid.m_pbUuid[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #21
0
        public PwCustomIcon(PwUuid pu, byte[] pbImageDataPng)
        {
            if (pu == null)
            {
                Debug.Assert(false); throw new ArgumentNullException("pu");
            }
            if (pu.Equals(PwUuid.Zero))
            {
                Debug.Assert(false); throw new ArgumentOutOfRangeException("pu");
            }
            if (pbImageDataPng == null)
            {
                Debug.Assert(false); throw new ArgumentNullException("pbImageDataPng");
            }

            m_uuid           = pu;
            m_pbImageDataPng = pbImageDataPng;
        }
Beispiel #22
0
        public PwEntry(PwGroup pwParentGroup, bool bCreateNewUuid, bool bSetTimes)
        {
            m_pParentGroup = pwParentGroup;

            if (bCreateNewUuid)
            {
                m_uuid = new PwUuid(true);
            }

            if (bSetTimes)
            {
                DateTime dtNow = DateTime.UtcNow;
                m_tCreation           = dtNow;
                m_tLastMod            = dtNow;
                m_tLastAccess         = dtNow;
                m_tParentGroupLastMod = dtNow;
            }
        }
		public bool DeleteCustomIcons(List<PwUuid> vUuidsToDelete)
		{
			Debug.Assert(vUuidsToDelete != null);
			if(vUuidsToDelete == null) throw new ArgumentNullException("vUuidsToDelete");
			if(vUuidsToDelete.Count <= 0) return true;

			GroupHandler gh = delegate(PwGroup pg)
			{
				PwUuid uuidThis = pg.CustomIconUuid;
				if(uuidThis.EqualsValue(PwUuid.Zero)) return true;

				foreach(PwUuid uuidDelete in vUuidsToDelete)
				{
					if(uuidThis.EqualsValue(uuidDelete))
					{
						pg.CustomIconUuid = PwUuid.Zero;
						break;
					}
				}

				return true;
			};

			EntryHandler eh = delegate(PwEntry pe)
			{
				RemoveCustomIconUuid(pe, vUuidsToDelete);
				return true;
			};

			gh(m_pgRootGroup);
			if(!m_pgRootGroup.TraverseTree(TraversalMethod.PreOrder, gh, eh))
			{
				Debug.Assert(false);
				return false;
			}

			foreach(PwUuid pwUuid in vUuidsToDelete)
			{
				int nIndex = GetCustomIconIndex(pwUuid);
				if(nIndex >= 0) m_vCustomIcons.RemoveAt(nIndex);
			}

			return true;
		}
 public static Dictionary<String, String> get_template_title_to_field_dict(IPluginHost m_host, String template_uuid)
 {
     Dictionary<String, String> ret = new Dictionary<string, string>();
     PwUuid par_uuid = new PwUuid(KeePassLib.Utility.MemUtil.HexStringToByteArray(template_uuid));
     PwEntry par_template = m_host.Database.RootGroup.FindEntry(par_uuid, true);
     if (par_template == null)
         return ret;
     if (par_template.Strings.Get("_etm_template") == null)
         return ret;
     List<EntryTemplate> cur = parse_entry(par_template.Strings);
     foreach (EntryTemplate tmp in cur) {
         if (tmp.type == "Divider")
             continue;
         if (tmp.fieldName.Length < 1 || tmp.fieldName[0] == '@')
             continue;
         ret[tmp.title] = tmp.fieldName;
     }
     return ret;
 }
Beispiel #25
0
        /// <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;
        }
		internal void Clear()
		{
			m_pgRootGroup = null;
			m_vDeletedObjects = new PwObjectList<PwDeletedObject>();

			m_uuidDataCipher = StandardAesEngine.AesUuid;
			m_caCompression = PwCompressionAlgorithm.GZip;
			m_uKeyEncryptionRounds = PwDefs.DefaultKeyEncryptionRounds;

			m_pwUserKey = null;
			m_memProtConfig = new MemoryProtectionConfig();

			m_vCustomIcons = new List<PwCustomIcon>();
			m_bUINeedsIconUpdate = true;

			m_strName = string.Empty;
			m_dtNameChanged = PwDefs.DtDefaultNow;
			m_strDesc = string.Empty;
			m_dtDescChanged = PwDefs.DtDefaultNow;
			m_strDefaultUserName = string.Empty;
			m_dtDefaultUserChanged = PwDefs.DtDefaultNow;
			m_uMntncHistoryDays = 365;

			m_ioSource = new IOConnectionInfo();
			m_bDatabaseOpened = false;
			m_bModified = false;

			m_pwLastSelectedGroup = PwUuid.Zero;
			m_pwLastTopVisibleGroup = PwUuid.Zero;

			m_bUseRecycleBin = true;
			m_pwRecycleBin = PwUuid.Zero;
			m_dtRecycleBinChanged = PwDefs.DtDefaultNow;
			m_pwEntryTemplatesGroup = PwUuid.Zero;
			m_dtEntryTemplatesChanged = PwDefs.DtDefaultNow;

			m_vCustomData = new StringDictionaryEx();

			m_pbHashOfFileOnDisk = null;
			m_pbHashOfLastIO = null;

			m_bUseFileTransactions = false;
		}
		internal static void GetNeighborItems(List<IStructureItem> vItems,
			PwUuid pwPivot, Queue<PwUuid> qBefore, Queue<PwUuid> qAfter)
		{
			qBefore.Clear();
			qAfter.Clear();

			// Checks after clearing the queues
			if(vItems == null) { Debug.Assert(false); return; } // No throw

			bool bBefore = true;
			for(int i = 0; i < vItems.Count; ++i)
			{
				PwUuid pw = vItems[i].Uuid;

				if(pw.EqualsValue(pwPivot)) bBefore = false;
				else if(bBefore) qBefore.Enqueue(pw);
				else qAfter.Enqueue(pw);
			}
			Debug.Assert(bBefore == false);
		}
Beispiel #28
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>
		/// <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)
		{
			if(peTemplate == null) { Debug.Assert(false); 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.CloneDeep();
			m_listBinaries = peTemplate.m_listBinaries.CloneDeep();
			m_listAutoType = peTemplate.m_listAutoType.CloneDeep();
			if(bIncludeHistory)
				m_listHistory = peTemplate.m_listHistory.CloneDeep();

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

			m_dCustomData = peTemplate.m_dCustomData.CloneDeep();
		}
Beispiel #29
0
        public PwCustomIcon(PwUuid pwUuid, byte[] pbImageDataPng)
        {
            Debug.Assert(pwUuid != null);
            if(pwUuid == null) throw new ArgumentNullException("pwUuid");
            Debug.Assert(pwUuid != PwUuid.Zero);
            if(pwUuid == PwUuid.Zero) throw new ArgumentException("pwUuid == 0");

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

            m_pwUuid = pwUuid;
            m_pbImageDataPng = pbImageDataPng;

            #if !KeePassLibSD
            MemoryStream ms = new MemoryStream(m_pbImageDataPng, false);
            m_pCachedImage = Image.FromStream(ms);
            ms.Close();
            #else
            m_pCachedImage = null;
            #endif
        }
Beispiel #30
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;
        }
Beispiel #31
0
        public PwCustomIcon(PwUuid pwUuid, byte[] pbImageDataPng)
        {
            Debug.Assert(pwUuid != null);
            if(pwUuid == null) throw new ArgumentNullException("pwUuid");
            Debug.Assert(!pwUuid.Equals(PwUuid.Zero));
            if(pwUuid.Equals(PwUuid.Zero)) throw new ArgumentException("pwUuid == 0.");
            Debug.Assert(pbImageDataPng != null);
            if(pbImageDataPng == null) throw new ArgumentNullException("pbImageDataPng");

            m_pwUuid = pwUuid;
            m_pbImageDataPng = pbImageDataPng;

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

            if(m_imgOrg != null)
                m_dImageCache[GetID(m_imgOrg.Width, m_imgOrg.Height)] =
                    m_imgOrg;
        }
Beispiel #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PwCustomIcon"/> class.
        /// </summary>
        /// <param name="pwUuid">
        /// The pw uuid.
        /// </param>
        /// <param name="pbImageDataPng">
        /// The pb image data png.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// </exception>
        /// <exception cref="ArgumentException">
        /// </exception>
        public PwCustomIcon(PwUuid pwUuid, byte[] pbImageDataPng)
        {
            Debug.Assert(pwUuid != null);
            if (pwUuid == null)
            {
                throw new ArgumentNullException("pwUuid");
            }

            Debug.Assert(!pwUuid.Equals(PwUuid.Zero));
            if (pwUuid.Equals(PwUuid.Zero))
            {
                throw new ArgumentException("pwUuid == 0");
            }

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

            this.m_pwUuid         = pwUuid;
            this.m_pbImageDataPng = pbImageDataPng;
        }
Beispiel #33
0
        /// <summary>
        /// Find an object.
        /// </summary>
        /// <param name="uuid">UUID of the object to find.</param>
        /// <param name="bRecursive">Specifies whether to search recursively.</param>
        /// <param name="bEntries">If <c>null</c>, groups and entries are
        /// searched. If <c>true</c>, only entries are searched. If <c>false</c>,
        /// only groups are searched.</param>
        /// <returns>Reference to the object, if found. Otherwise <c>null</c>.</returns>
        public IStructureItem FindObject(PwUuid uuid, bool bRecursive,
                                         bool?bEntries)
        {
            if (bEntries.HasValue)
            {
                if (bEntries.Value)
                {
                    return(FindEntry(uuid, bRecursive));
                }
                else
                {
                    return(FindGroup(uuid, bRecursive));
                }
            }

            PwGroup pg = FindGroup(uuid, bRecursive);

            if (pg != null)
            {
                return(pg);
            }
            return(FindEntry(uuid, bRecursive));
        }
		// Public for plugins
		public void EnsureVisibleEntry(PwUuid uuid)
		{
			ListViewItem lvi = GuiFindEntry(uuid);
			if(lvi == null) { Debug.Assert(false); return; }

			m_lvEntries.EnsureVisible(lvi.Index);
		}
Beispiel #35
0
		private bool SaveChosenIcon()
		{
			if(m_radioStandard.Checked)
			{
				ListView.SelectedIndexCollection lvsi = m_lvIcons.SelectedIndices;
				if(lvsi.Count != 1) return false;

				m_uChosenImageID = (uint)lvsi[0];
			}
			else // Custom icon
			{
				ListView.SelectedListViewItemCollection lvsic = m_lvCustomIcons.SelectedItems;
				if(lvsic.Count != 1) return false;

				m_pwChosenCustomImageUuid = (PwUuid)lvsic[0].Tag;
			}

			return true;
		}
Beispiel #36
0
        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];
                }
            }
        }
Beispiel #37
0
        private void PrepareSave()
        {
            m_trl.Properties.Application = PwDefs.ProductName;
            m_trl.Properties.ApplicationVersion = PwDefs.VersionString;
            m_trl.Properties.Generator = "TrlUtil";

            PwUuid pwUuid = new PwUuid(true);
            m_trl.Properties.FileUuid = pwUuid.ToHexString();

            m_trl.Properties.LastModified = DateTime.Now.ToString("u");

            m_trl.UnusedText = m_rtbUnusedText.Text;

            try { Validate3Dots(); }
            catch(Exception) { Debug.Assert(false); }

            try
            {
                string strAccel = AccelKeysCheck.Validate(m_trl);
                if(strAccel != null)
                {
                    MessageService.ShowWarning("Warning! The following accelerator keys collide:",
                        strAccel, "Click OK to continue saving.");
                }
            }
            catch(Exception) { Debug.Assert(false); }
        }
        private static void ImportIcon(XmlNode xn, PwEntry pe, PwDatabase pd)
        {
            XmlNode xnIcon = xn.Attributes.GetNamedItem("ICON");
            if(xnIcon == null) return;

            string strIcon = xnIcon.Value;
            if(!StrUtil.IsDataUri(strIcon)) { Debug.Assert(false); return; }

            try
            {
                byte[] pbImage = StrUtil.DataUriToData(strIcon);
                if((pbImage == null) || (pbImage.Length == 0)) { Debug.Assert(false); return; }

                Image img = GfxUtil.LoadImage(pbImage);
                if(img == null) { Debug.Assert(false); return; }

                byte[] pbPng;
                int wMax = PwCustomIcon.MaxWidth;
                int hMax = PwCustomIcon.MaxHeight;
                if((img.Width <= wMax) && (img.Height <= hMax))
                {
                    MemoryStream msPng = new MemoryStream();
                    img.Save(msPng, ImageFormat.Png);
                    pbPng = msPng.ToArray();
                    msPng.Close();
                }
                else
                {
                    Image imgSc = GfxUtil.ScaleImage(img, wMax, hMax);

                    MemoryStream msPng = new MemoryStream();
                    imgSc.Save(msPng, ImageFormat.Png);
                    pbPng = msPng.ToArray();
                    msPng.Close();

                    imgSc.Dispose();
                }
                img.Dispose();

                PwUuid pwUuid = null;
                int iEx = pd.GetCustomIconIndex(pbPng);
                if(iEx >= 0) pwUuid = pd.CustomIcons[iEx].Uuid;
                else
                {
                    pwUuid = new PwUuid(true);
                    pd.CustomIcons.Add(new PwCustomIcon(pwUuid, pbPng));
                    pd.UINeedsIconUpdate = true;
                    pd.Modified = true;
                }
                pe.CustomIconUuid = pwUuid;
            }
            catch(Exception) { Debug.Assert(false); }
        }
Beispiel #39
0
        private void SelectCustomGenerator(string strUuid, string strCustomOptions)
        {
            try
            {
                if(string.IsNullOrEmpty(strUuid)) throw new ArgumentException();

                PwUuid uuid = new PwUuid(Convert.FromBase64String(strUuid));
                CustomPwGenerator pwg = Program.PwGeneratorPool.Find(uuid);
                if(pwg == null) throw new ArgumentException();

                bool bSet = false;
                for(int i = 0; i < m_cmbCustomAlgo.Items.Count; ++i)
                {
                    if((m_cmbCustomAlgo.Items[i] as string) == pwg.Name)
                    {
                        m_cmbCustomAlgo.SelectedIndex = i;

                        if(strCustomOptions != null)
                            m_dictCustomOptions[pwg] = strCustomOptions;

                        bSet = true;
                        break;
                    }
                }

                if(!bSet) throw new ArgumentException();
            }
            catch(Exception) { m_cmbCustomAlgo.SelectedIndex = 0; }
        }
Beispiel #40
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pwGroup != null); if(m_pwGroup == null) throw new InvalidOperationException();
            Debug.Assert(m_pwDatabase != null); if(m_pwDatabase == null) throw new InvalidOperationException();

            GlobalWindowManager.AddWindow(this);

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

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

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

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

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

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

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

            m_tbDefaultAutoTypeSeq.Text = m_pwGroup.GetAutoTypeSequenceInherited();

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

            CustomizeForScreenReader();
            EnableControlsEx();
            UIUtil.SetFocus(m_tbName, this);
        }
Beispiel #41
0
        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);
        }
Beispiel #42
0
        private static void OpenEntryUrl(IpcParamEx ip, MainForm mf)
        {
            string strUuid = ip.Param0;
            if(string.IsNullOrEmpty(strUuid)) return; // No assert (user data)

            byte[] pbUuid = MemUtil.HexStringToByteArray(strUuid);
            if((pbUuid == null) || (pbUuid.Length != PwUuid.UuidSize)) return;
            PwUuid pwUuid = new PwUuid(pbUuid);

            List<PwDocument> lDocs = new List<PwDocument>(mf.DocumentManager.Documents);
            PwDocument pwDocActive = mf.DocumentManager.ActiveDocument;
            for(int i = 1; i < lDocs.Count; ++i)
            {
                if(object.ReferenceEquals(lDocs[i], pwDocActive))
                {
                    lDocs.RemoveAt(i);
                    lDocs.Insert(0, pwDocActive);
                    break;
                }
            }

            foreach(PwDocument pwDoc in lDocs)
            {
                if(pwDoc == null) { Debug.Assert(false); continue; }

                PwDatabase pdb = pwDoc.Database;
                if((pdb == null) || !pdb.IsOpen) continue;

                PwEntry pe = pdb.RootGroup.FindEntry(pwUuid, true);
                if(pe == null) continue;

                mf.PerformDefaultUrlAction(new PwEntry[]{ pe }, true);
                break;
            }
        }
Beispiel #43
0
 private PwEntry GetConfigEntry(bool create)
 {
     var root = host.Database.RootGroup;
     var uuid = new PwUuid(KEEPASSHTTP_UUID);
     var entry = root.FindEntry(uuid, false);
     if (entry == null && create)
     {
         entry = new PwEntry(false, true);
         entry.Uuid = uuid;
         entry.Strings.Set(PwDefs.TitleField, new ProtectedString(false, KEEPASSHTTP_NAME));
         root.AddEntry(entry, true);
         UpdateUI(null);
     }
     return entry;
 }
		private void SetTopVisibleEntry(PwUuid uuidEntry)
		{
			ListViewItem lviTop = GuiFindEntry(uuidEntry);
			if(lviTop != null)
				UIUtil.SetTopVisibleItem(m_lvEntries, lviTop.Index, false);
		}