Exemple #1
0
        public static bool IsCustomAttributeSet(this StringDictionaryEx dict, KeeShare.AttributeFlags attribute)
        {
            string value = dict.Get(KeeShare.CustomDataKey);

            if (null == value)
            {
                return(false);
            }
            return(value.IsFlagSet(attribute));
        }
Exemple #2
0
        public static bool IsFlagSet(this string aString, KeeShare.AttributeFlags flag)
        {
            uint setValue;

            if (KeePassLib.Utility.StrUtil.TryParseUInt(aString, out setValue))
            {
                KeeShare.AttributeFlags setFlags = (KeeShare.AttributeFlags)setValue;
                return(setFlags.HasFlag(flag));
            }
            return(false);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
0
 public static bool IsCustomAttributeSet(this PwDatabase db, KeeShare.AttributeFlags attribute)
 {
     return(db.CustomData.IsCustomAttributeSet(attribute));
 }
Exemple #7
0
 public static void SetCustomAttribute(this PwDatabase db, KeeShare.AttributeFlags attribute, bool set)
 {
     db.CustomData.SetCustomAttribute(attribute, set);
 }
Exemple #8
0
 public static void SetCustomAttribute(this PwGroup group, KeeShare.AttributeFlags attribute, bool set)
 {
     group.CustomData.SetCustomAttribute(attribute, set);
 }
Exemple #9
0
 public static bool IsCustomAttributeSet(this PwGroup group, KeeShare.AttributeFlags attribute)
 {
     return(group.CustomData.IsCustomAttributeSet(attribute));
 }
Exemple #10
0
 public static void SetCustomAttribute(this PwEntry entry, KeeShare.AttributeFlags attribute, bool set)
 {
     entry.CustomData.SetCustomAttribute(attribute, set);
 }
Exemple #11
0
 public static bool IsCustomAttributeSet(this PwEntry entry, KeeShare.AttributeFlags attribute)
 {
     return(entry.CustomData.IsCustomAttributeSet(attribute));
 }