Пример #1
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_dStrings    = peTemplate.m_dStrings.CloneDeep();
            m_dBinaries   = peTemplate.m_dBinaries.CloneDeep();
            m_cfgAutoType = peTemplate.m_cfgAutoType.CloneDeep();
            if (bIncludeHistory)
            {
                m_lHistory = peTemplate.m_lHistory.CloneDeep();
            }

            m_pwIcon       = peTemplate.m_pwIcon;
            m_puCustomIcon = peTemplate.m_puCustomIcon;             // 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_lTags = new List <string>(peTemplate.m_lTags);

            m_dCustomData = peTemplate.m_dCustomData.CloneDeep();
        }
Пример #2
0
        public static bool SetCustomAttribute(this StringDictionaryEx dict, KeeShare.AttributeFlags attribute, bool set)
        {
            string value = dict.Get(KeeShare.CustomDataKey);

            if (null == value)
            {
                if (!set)
                {
                    return(false); // no data
                }
                value = attribute.ToString("d");
                dict.Set(KeeShare.CustomDataKey, attribute.ToString("d"));
                return(true); // set and return;
            }

            KeeShare.AttributeFlags flags;
            uint shortValue = 0;

            if (KeePassLib.Utility.StrUtil.TryParseUInt(value, out shortValue))
            {
                Debug.Assert(false);
            }
            flags = (KeeShare.AttributeFlags)shortValue;
            if (set)
            {
                flags &= attribute;
            }
            else
            {
                flags ^= attribute;
            }
            string newValue = flags.ToString();

            if (newValue != value)
            {
                if (flags == 0)
                {
                    dict.Remove(KeeShare.CustomDataKey);
                }
                else
                {
                    dict.Set(KeeShare.CustomDataKey, newValue);
                }
                return(true);
            }
            return(false);
        }
Пример #3
0
        private void WriteList(string name, StringDictionaryEx value)
        {
            Debug.Assert(name != null);
            Debug.Assert(value != null); if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            m_xmlWriter.WriteStartElement(name);

            foreach (KeyValuePair <string, string> kvp in value)
            {
                WriteObject(ElemStringDictExItem, ElemKey, ElemValue, kvp);
            }

            m_xmlWriter.WriteEndElement();
        }
Пример #4
0
		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;
		}
Пример #5
0
        public static void SetFileEventFlags(PwDatabase db,
                                             string key, FileEventFlags reason)
        {
            if (db == null || !db.IsOpen || db.CustomData == null)
            {
                return;
            }

            // Record only locking & exit events.
            StringDictionaryEx props = db.CustomData;

            reason &= FileEventFlags.Exiting | FileEventFlags.Locking;
            if (reason != FileEventFlags.None)
            {
                props.Set(key, reason.ToString("G"));
            }
            else if (props.Exists(key))
            {
                props.Remove(key);
            }
        }
		private void OnFormLoad(object sender, EventArgs e)
		{
			Debug.Assert(m_pwDatabase != null); if(m_pwDatabase == null) throw new InvalidOperationException();

			GlobalWindowManager.AddWindow(this, this);

			BannerFactory.CreateBannerEx(this, m_bannerImage,
				Properties.Resources.B48x48_Package_Settings, KPRes.DatabaseMaintenance,
				KPRes.DatabaseMaintenanceDesc);
			this.Icon = Properties.Resources.KeePass;
			this.Text = KPRes.DatabaseMaintenance;

			m_numHistoryDays.Value = m_pwDatabase.MaintenanceHistoryDays;

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

			m_pbStatus.Visible = false;
			EnableControlsEx();
		}
Пример #7
0
        public static PluginEntryFactory Create(string title,
                                                string driveScope, string clientId, ProtectedString clientSecret,
                                                string folder, bool useLegacyCreds, bool dontSaveAuthToken)
        {
            PwEntry entry = new PwEntry(true, true);
            ProtectedStringDictionary strings = entry.Strings;

            strings.Set(PwDefs.TitleField,
                        new ProtectedString(false, title));
            strings.Set(PwDefs.NotesField,
                        new ProtectedString(false,
                                            Resources.GetFormat("Msg_NewEntryNotesFmt",
                                                                GdsDefs.ProductName)));
            strings.Set(PwDefs.UrlField,
                        new ProtectedString(false, GdsDefs.AccountSearchString));

            StringDictionaryEx data = entry.CustomData;

            if (useLegacyCreds)
            {
                data.Set(SyncConfiguration.EntryDriveScopeKey, driveScope);
                data.Set(SyncConfiguration.EntryClientIdKey, clientId);
                data.Set(SyncConfiguration.EntryClientSecretKey,
                         clientSecret == null ?
                         string.Empty : clientSecret.ReadString());
            }
            data.Set(SyncConfiguration.EntryActiveAppFolderKey, folder);
            data.Set(SyncConfiguration.EntryActiveAccountKey,
                     SyncConfiguration.EntryActiveAccountTrueKey);
            data.Set(SyncConfiguration.EntryUseLegacyCredsKey, useLegacyCreds ?
                     GdsDefs.ConfigTrue : GdsDefs.ConfigFalse);
            data.Set(SyncConfiguration.EntryDontCacheAuthTokenKey,
                     dontSaveAuthToken ?
                     GdsDefs.ConfigTrue : GdsDefs.ConfigFalse);
            data.Set(SyncConfiguration.EntryVersionKey,
                     SyncConfiguration.CurrentVersion.ToString(2));

            entry.IconId = PwIcon.WorldComputer;
            return(new PluginEntryFactory(entry));
        }
Пример #8
0
        private void WriteList(string name, StringDictionaryEx value)
        {
            Debug.Assert(name != null);
            Debug.Assert(value != null); if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            m_xmlWriter.WriteStartElement(name);

            foreach (KeyValuePair <string, string> kvp in value)
            {
                DateTime?odtLastMod = null;
                if (m_uFileVersion >= FileVersion32_4_1)
                {
                    odtLastMod = value.GetLastModificationTime(kvp.Key);
                }

                WriteObject(ElemStringDictExItem, ElemKey, ElemValue, kvp, odtLastMod);
            }

            m_xmlWriter.WriteEndElement();
        }
Пример #9
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pwDatabase != null); if (m_pwDatabase == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this, this);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_Package_Settings, KPRes.DatabaseMaintenance,
                                         KPRes.DatabaseMaintenanceDesc);
            this.Icon = AppIcons.Default;
            this.Text = KPRes.DatabaseMaintenance;

            m_numHistoryDays.Value = m_pwDatabase.MaintenanceHistoryDays;

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

            m_pbStatus.Visible = false;
            EnableControlsEx();
        }
Пример #10
0
        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;
            }
        }
Пример #11
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 = AppIcons.Default;
            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   = 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);

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

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

            CustomizeForScreenReader();
            EnableControlsEx();
            UIUtil.SetFocus(m_tbName, this);
        }
Пример #12
0
 public StringDictionaryExBuffer()
 {
     mStringDictionaryEx = new StringDictionaryEx();
 }
Пример #13
0
 public StringDictionaryExBuffer(StringDictionaryEx stringDictionaryEx)
 {
     mStringDictionaryEx = stringDictionaryEx;
 }
Пример #14
0
        private void WriteList(string name, StringDictionaryEx value)
        {
            Debug.Assert(name != null);
            Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value");

            m_xmlWriter.WriteStartElement(name);

            foreach(KeyValuePair<string, string> kvp in value)
                WriteObject(ElemStringDictExItem, ElemKey, ElemValue, kvp);

            m_xmlWriter.WriteEndElement();
        }