Exemplo n.º 1
0
        internal static Guid GetUUID(this KnownFolderType FolderType)
        {
            var type       = typeof(KnownFolderType);
            var memInfo    = type.GetMember($"{FolderType}");
            var attributes = memInfo[0].GetCustomAttributes(typeof(UUIDAttribute), false);

            return(((UUIDAttribute)attributes[0]).UUID);
        }
Exemplo n.º 2
0
        // ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the <see cref="Guid"/> with which the <see cref="KnownFolderType"/> enumeration member has been
        /// decorated.
        /// </summary>
        /// <param name="value">The decorated <see cref="KnownFolderType"/> enumeration member.</param>
        /// <returns>The <see cref="Guid"/> of the <see cref="KnownFolderType"/>.</returns>
        internal static Guid GetGuid(this KnownFolderType value)
        {
            FieldInfo member = typeof(KnownFolderType).GetField(value.ToString());

            object[] attributes = member.GetCustomAttributes(typeof(KnownFolderGuidAttribute), false);
            KnownFolderGuidAttribute guidAttribute = (KnownFolderGuidAttribute)attributes[0];

            return(guidAttribute.Guid);
        }
Exemplo n.º 3
0
        // ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the <see cref="Guid"/> with which the <see cref="KnownFolderType"/> enumeration member has been
        /// decorated.
        /// </summary>
        /// <param name="Value">The decorated <see cref="KnownFolderType"/> enumeration member.</param>
        /// <returns>The <see cref="Guid"/> of the <see cref="KnownFolderType"/>.</returns>
        internal static Guid GetGuid(this KnownFolderType Value)
        {
            FieldInfo Member = typeof(KnownFolderType).GetField(Value.ToString());

            object[] Attributes = Member.GetCustomAttributes(typeof(KnownFolderGuidAttribute), false);
            KnownFolderGuidAttribute GuidAttribute = (KnownFolderGuidAttribute)Attributes[0];

            return(GuidAttribute.Guid);
        }
Exemplo n.º 4
0
        // ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------

        private static KnownFolder GetInstance(KnownFolderType Type)
        {
            // Check if the caching directory exists yet.
            if (_knownFolderInstances == null)
            {
                _knownFolderInstances = new Dictionary <KnownFolderType, KnownFolder>();
            }

            // Get a KnownFolder instance out of the cache dictionary or create it when not cached yet.
            if (!_knownFolderInstances.TryGetValue(Type, out KnownFolder KnownFolder))
            {
                KnownFolder = new KnownFolder(Type);
                _knownFolderInstances.Add(Type, KnownFolder);
            }
            return(KnownFolder);
        }
Exemplo n.º 5
0
        public KnownFolder(KnownFolderType FolderType)
        {
            this.FolderType = FolderType;

            //get the current user's identity
            var identity = WindowsIdentity.GetCurrent();

            //set the flags for the path
            var flags = KnownFolderFlag.DefaultPath | KnownFolderFlag.DontVerify;

            IntPtr path;
            var    res = MarshalledKnownFolders.SHGetKnownFolderPath(FolderType.GetUUID(), (UInt32)flags, identity.Token, out path);

            if (res == HRESULT.OK)
            {
                //load the path
                Directory = new DirectoryInfo(Marshal.PtrToStringUni(path));
            }
        }
Exemplo n.º 6
0
        private static KnownFolder GetInstance(KnownFolderType type)
        {
            // Check if the caching directory exists yet.
            if (_knownFolderInstances == null)
            {
                _knownFolderInstances = new ConcurrentDictionary <KnownFolderType, KnownFolder>();
            }

            // Get a KnownFolder instance out of the cache dictionary or create it when not cached yet.
            if (!_knownFolderInstances.TryGetValue(type, out KnownFolder knownFolder))
            {
                knownFolder = new KnownFolder(type);
                if (_knownFolderInstances.TryAdd(type, knownFolder))
                {
                    return(knownFolder);
                }
                return(_knownFolderInstances[type]);
            }
            return(knownFolder);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="KnownFolder"/> class for the folder of the given type. It
 /// provides the values for the given impersonated user.
 /// </summary>
 /// <param name="type">The <see cref="KnownFolderType"/> of the known folder to represent.</param>
 /// <param name="identity">The <see cref="WindowsIdentity"/> of the impersonated user which values will be
 /// provided.</param>
 public KnownFolder(KnownFolderType type, WindowsIdentity identity)
 {
     Type     = type;
     Identity = identity;
 }
        // ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="KnownFolder"/> class for the folder of the given type. It
        /// provides the values for the current user.
        /// </summary>
        /// <param name="type">The <see cref="KnownFolderType"/> of the known folder to represent.</param>
        public KnownFolder(KnownFolderType type) : this(type, WindowsIdentity.GetCurrent())
        {
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KnownFolder"/> class for the folder of the given type. It
 /// provides the values for the given impersonated user.
 /// </summary>
 /// <param name="Type">The <see cref="KnownFolderType"/> of the known folder to represent.</param>
 /// <param name="Identity">The <see cref="WindowsIdentity"/> of the impersonated user which values will be
 /// provided.</param>
 public KnownFolder(KnownFolderType Type, WindowsIdentity Identity)
 {
     this.Type     = Type;
     this.Identity = Identity;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KnownFolder"/> class for the folder of the given type. It
 /// provides the values for the given impersonated user.
 /// </summary>
 /// <param name="type">The <see cref="KnownFolderType"/> of the known folder to represent.</param>
 /// <param name="identity">The <see cref="WindowsIdentity"/> of the impersonated user which values will be
 /// provided.</param>
 internal KnownFolder(KnownFolderType type, WindowsIdentity identity)
 {
     Type     = type;
     Identity = identity;
 }
Exemplo n.º 11
0
 /// <summary>Creates a <see cref="DirectoryInfo"/> from a given <see cref="KnownFolderType"/> by constructing a new <see cref="KnownFolder"/>. </summary>
 /// <param name="KnownFolderType">The known folder type.</param>
 /// <returns><see cref="DirectoryInfo"/></returns>
 public static DirectoryInfo GetDirectoryInfo(this KnownFolderType KnownFolderType) => new KnownFolder(KnownFolderType).GetDirectoryInfo();