Exemplo n.º 1
0
        /// <summary>
        ///     Creates actual extension association key in registry for the specified extension and supplied attributes.
        /// </summary>
        /// <param name="progId">Name of expected handling program.</param>
        /// <param name="perceivedType"><see cref="PerceivedTypes" />PerceivedType of file type.</param>
        /// <param name="contentType">MIME type of file type.</param>
        /// <param name="openwithList"></param>
        /// <returns>FileAssociationInfo instance referring to specified extension.</returns>
        public FileAssociationInfo Create(string progId, PerceivedTypes perceivedType, string contentType,
                                          string[] openwithList)
        {
            var fai = new FileAssociationInfo(_extension);

            if (fai.Exists)
            {
                fai.Delete();
            }

            fai.Create();
            fai.ProgId = progId;

            if (perceivedType != PerceivedTypes.None)
            {
                fai.PerceivedType = perceivedType;
            }

            if (contentType != string.Empty)
            {
                fai.ContentType = contentType;
            }

            if (openwithList != null)
            {
                fai.OpenWithList = openwithList;
            }

            return(fai);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets or value that determines the <see cref="PerceivedType"/>PerceivedType of the file.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
        /// <returns><see cref="PerceivedTypes"/> that specifies Perceived Type of extension.</returns>
        protected PerceivedTypes GetPerceivedType(FileAssociationInfo file)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            object         val        = registryWrapper.Read(file.extension, "PerceivedType");
            PerceivedTypes actualType = PerceivedTypes.None;

            if (val == null)
            {
                return(actualType);
            }

            try
            {
                actualType = (PerceivedTypes)Enum.Parse(typeof(PerceivedTypes), val.ToString(), true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }


            return(actualType);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Sets a value that determines the <see cref="PerceivedType" />PerceivedType of the file.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo" /> that provides specifics of the extension to be changed.</param>
        /// <param name="type"><see cref="PerceivedTypes" /> to be set that specifies Perceived Type of extension.</param>
        protected void SetPerceivedType(FileAssociationInfo file, PerceivedTypes type)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            _registryWrapper.Write(file._extension, "PerceivedType", type.ToString());

            ShellNotification.NotifyOfChange();
        }
Exemplo n.º 4
0
        private static void AssociateMain(string ProgID, string Ext, PerceivedTypes PerceivedType, string ContentType)
        {
            FileAssociationInfo a = new FileAssociationInfo(Ext);

            if (!a.Exists)
            {
                a.Create();
            }
            a.PerceivedType     = PerceivedType;
            a.ContentType       = ContentType;
            a.PersistentHandler = new Guid("{897fe156-ccc2-4992-8144-abb654ea92b9}");
            a.ProgID            = ProgID;
        }
Exemplo n.º 5
0
      /// <summary>
      /// Sets a value that determines the <see cref="PerceivedType"/>PerceivedType of the file.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <param name="type"><see cref="PerceivedTypes"/> to be set that specifies Perceived Type of extension.</param>
      protected void SetPerceivedType(FileAssociationInfo file, PerceivedTypes type)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         registryWrapper.Write(file.extension, "PerceivedType", type.ToString());

         ShellNotification.NotifyOfChange();
      }
Exemplo n.º 6
0
      /// <summary>
      /// Creates actual extension association key in registry for the specified extension and supplied attributes.
      /// </summary>
      /// <param name="progId">Name of expected handling program.</param>
      /// <param name="perceivedType"><see cref="PerceivedTypes"/>PerceivedType of file type.</param>
      /// <param name="contentType">MIME type of file type.</param>
      /// <param name="openwithList"></param>
      /// <returns>FileAssociationInfo instance referring to specified extension.</returns>
      public FileAssociationInfo Create(string progId, PerceivedTypes perceivedType, string contentType, string[] openwithList)
      {
         FileAssociationInfo fai = new FileAssociationInfo(extension);

         if (fai.Exists)
         {
            fai.Delete();
         }

         fai.Create();
         fai.ProgID = progId;

         if (perceivedType != PerceivedTypes.None)
            fai.PerceivedType = perceivedType;

         if (contentType != string.Empty)
            fai.ContentType = contentType;

         if (openwithList != null)
            fai.OpenWithList = openwithList;

         return fai;
      }
Exemplo n.º 7
0
 /// <summary>
 /// Creates actual extension association key in registry for the specified extension and supplied attributes.
 /// </summary>
 /// <param name="progId">Name of expected handling program.</param>
 /// <param name="perceivedType"><see cref="PerceivedTypes"/>PerceivedType of file type.</param>
 /// <param name="contentType">MIME type of file type.</param>
 /// <returns>FileAssociationInfo instance referring to specified extension.</returns>
 public FileAssociationInfo Create(string progId, PerceivedTypes perceivedType, string contentType)
 {
    return Create(progId, PerceivedTypes.None, contentType, null);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates actual extension association key in registry for the specified extension and supplied attributes.
 /// </summary>
 /// <param name="progId">Name of expected handling program.</param>
 /// <param name="perceivedType"><see cref="PerceivedTypes"/>PerceivedType of file type.</param>
 /// <returns>FileAssociationInfo instance referring to specified extension.</returns>
 public FileAssociationInfo Create(string progId, PerceivedTypes perceivedType)
 {
    return Create(progId, perceivedType, string.Empty, null);
 }
Exemplo n.º 9
0
 /// <summary>
 ///     Creates actual extension association key in registry for the specified extension and supplied attributes.
 /// </summary>
 /// <param name="progId">Name of expected handling program.</param>
 /// <param name="perceivedType"><see cref="PerceivedTypes" />PerceivedType of file type.</param>
 /// <param name="contentType">MIME type of file type.</param>
 /// <returns>FileAssociationInfo instance referring to specified extension.</returns>
 public FileAssociationInfo Create(string progId, PerceivedTypes perceivedType, string contentType)
 {
     return(Create(progId, PerceivedTypes.None, contentType, null));
 }
Exemplo n.º 10
0
 /// <summary>
 ///     Creates actual extension association key in registry for the specified extension and supplied attributes.
 /// </summary>
 /// <param name="progId">Name of expected handling program.</param>
 /// <param name="perceivedType"><see cref="PerceivedTypes" />PerceivedType of file type.</param>
 /// <returns>FileAssociationInfo instance referring to specified extension.</returns>
 public FileAssociationInfo Create(string progId, PerceivedTypes perceivedType)
 {
     return(Create(progId, perceivedType, string.Empty, null));
 }