Example #1
0
        private static void checkWYZFileAssociation()
        {
            if (Properties.Settings.Default.CheckFileAssociation)
            {
                FileAssociationInfo fai = new FileAssociationInfo(".wyz");

                bool refreshAssociation = !fai.Exists;
                if (!refreshAssociation)
                {
                    ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);
                    refreshAssociation = (!pai.Exists ||
                        pai.Verbs.Length == 0 ||
                        !pai.Verbs[0].Command.ToLower().Contains(Application.ExecutablePath.ToLower()));
                }

                if (refreshAssociation)
                {
                    DlgFileAssociationCheck dlgFileAssocCheck = new DlgFileAssociationCheck();
                    if (dlgFileAssocCheck.ShowDialog() == DialogResult.Yes)
                    {
                        Process newProcess = new Process();
                        newProcess.StartInfo.FileName = Application.ExecutablePath;
                        newProcess.StartInfo.Verb = "runas";
                        newProcess.StartInfo.Arguments = CREATE_ASSOC_PARAM;
                        newProcess.Start();
                        newProcess.WaitForExit();
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Sets array of containing program file names which should be displayed in the Open With List.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
        /// <param name="programList">Program file names</param>
        protected void SetOpenWithList(FileAssociationInfo file, string[] programList)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            RegistryKey root = Registry.ClassesRoot;

            RegistryKey key = root.OpenSubKey(file.extension, true);

            RegistryKey tmpkey = key.OpenSubKey("OpenWithList", true);

            if (tmpkey != null)
            {
                key.DeleteSubKeyTree("OpenWithList");
            }

            key = key.CreateSubKey("OpenWithList");

            foreach (string s in programList)
            {
                key.CreateSubKey(s);
            }

            ShellNotification.NotifyOfChange();
        }
Example #3
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);
        }
Example #4
0
		public static void RemoveAssociation(string extension)
		{
			var fai = new FileAssociationInfo(extension);

			if (fai.Exists)
				fai.Delete();
		}
Example #5
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);
        }
Example #6
0
        private static void createWYZFileAssociation()
        {
            FileAssociationInfo fai = new FileAssociationInfo(".wyz");
            if (!fai.Exists)
            {
                fai.Create("WYZTracker");
                fai.ContentType = "application/wyz-song-file";
                fai.OpenWithList = new string[] {
                        "WYZTracker.exe"
                    };
            }

            ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);
            if (!pai.Exists ||
                pai.Verbs.Length == 0 ||
                !pai.Verbs[0].Command.ToLower().Contains(Application.ExecutablePath.ToLower()))
            {
                pai.Create(
                    WYZTracker.Properties.Resources.WYZFileDesc,
                    new ProgramVerb(
                        WYZTracker.Properties.Resources.OpenVerb,
                        string.Format("\"{0}\" \"%1\"", Application.ExecutablePath)
                        )
                    );
                pai.DefaultIcon = new ProgramIcon(Application.ExecutablePath);
            }
        }
Example #7
0
        /// <summary>
        /// Deletes actual file extension entry in registry.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> instance that contains specifics on extension to be deleted.</param>
        protected void Delete(FileAssociationInfo file)
        {
            if (!file.Exists)
            {
                throw new Exception("Key not found.");
            }

            RegistryKey root = Registry.ClassesRoot;
        }
Example #8
0
        public static void RemoveAssociation(string extension)
        {
            var fai = new FileAssociationInfo(extension);

            if (fai.Exists)
            {
                fai.Delete();
            }
        }
Example #9
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();
        }
Example #10
0
        /// <summary>
        /// Set a value that indicates the name of the associated application with the behavior to handle this extension.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
        /// <param name="progId">Associated Program ID of handling program.</param>
        protected void SetProgID(FileAssociationInfo file, string progId)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            registryWrapper.Write(file.extension, string.Empty, progId);

            ShellNotification.NotifyOfChange();
        }
Example #11
0
        /// <summary>
        /// Creates actual file extension entry in registry.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> instance that contains specifics on extension to be created.</param>
        protected void Create(FileAssociationInfo file)
        {
            if (file.Exists)
            {
                file.Delete();
            }

            RegistryKey root = Registry.ClassesRoot;

            root.CreateSubKey(file.extension);
        }
        /// <summary>
        /// Deletes actual file extension entry in registry.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> instance that contains specifics on extension to be deleted.</param>
        protected void Delete(FileAssociationInfo file)
        {
            if (!file.Exists)
            {
                throw new Exception("Key not found.");
            }

            RegistryKey root = RegistryWrapper.ClassesRoot;

            root.DeleteSubKeyTree(file.extension);
        }
Example #13
0
        /// <summary>
        /// Sets a value that determines the MIME type of the file.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
        /// <param name="type">MIME content type of extension.</param>
        protected void SetContentType(FileAssociationInfo file, string type)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            registryWrapper.Write(file.extension, "Content Type", type);

            ShellNotification.NotifyOfChange();
        }
Example #14
0
        /// <summary>
        /// Associates an already existing program id with a list of extensions.
        /// </summary>
        /// <param name="progId">The program id to associate extensions with.</param>
        /// <param name="extensions">String array of extensions to associate with program id.</param>
        public void Associate(string progId, params string[] extensions)
        {
            foreach (string s in extensions)
             {
            FileAssociationInfo fai = new FileAssociationInfo(s);

            if (!fai.Exists)
               fai.Create(progId);

            fai.ProgID = progId;
             }
        }
Example #15
0
        /// <summary>
        /// Associates an already existing program id with a list of extensions.
        /// </summary>
        /// <param name="progId">The program id to associate extensions with.</param>
        /// <param name="extensions">String array of extensions to associate with program id.</param>
        public void Associate(string progId, params string[] extensions)
        {
            foreach (string s in extensions)
            {
                FileAssociationInfo fai = new FileAssociationInfo(s);

                if (!fai.Exists)
                {
                    fai.Create(progId);
                }

                fai.ProgID = progId;
            }
        }
      /// <summary>
      /// Determines of the list of extensions are associated with the specified program id.
      /// </summary>
      /// <param name="progId">Program id to check against.</param>
      /// <param name="extensions">String array of extensions to check against the program id.</param>
      /// <returns>String array of extensions that were not associated with the program id.</returns>
      public string[] CheckAssociation(string progId, params string[] extensions)
      {
         List<string> notAssociated = new List<string>();

         foreach (string s in extensions)
         {
            FileAssociationInfo fai = new FileAssociationInfo(s);

            if (!fai.Exists || fai.ProgID != progId)
               notAssociated.Add(s);
         }

         return notAssociated.ToArray();

      }
Example #17
0
 private static void AssociateTorrents(string installationPath)
 {
     var path = Path.Combine(installationPath, "Patchy.exe");
     var torrent = new FileAssociationInfo(".torrent");
     torrent.Create("Patchy");
     torrent.ContentType = "application/x-bittorrent";
     torrent.OpenWithList = new[] { "patchy.exe" };
     var program = new ProgramAssociationInfo(torrent.ProgID);
     if (!program.Exists)
     {
         program.Create("Patchy Torrent File", new ProgramVerb("Open", string.Format(
             "\"{0}\" \"%1\"", path)));
         program.DefaultIcon = new ProgramIcon(path);
     }
 }
Example #18
0
        /// <summary>
        /// Sets a value that indicates the filter component that is used to search for text within documents of this type.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
        /// <param name="persistentHandler">Guid of filter component.</param>
        protected void SetPersistentHandler(FileAssociationInfo file, Guid persistentHandler)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            if (persistentHandler == Guid.Empty)
            {
                return;
            }

            this.registryWrapper.Write(file.extension + "\\" + PersistentHandler, string.Empty, persistentHandler);

            ShellNotification.NotifyOfChange();
        }
Example #19
0
        /// <summary>
        /// Determines of the list of extensions are associated with the specified program id.
        /// </summary>
        /// <param name="progId">Program id to check against.</param>
        /// <param name="extensions">String array of extensions to check against the program id.</param>
        /// <returns>String array of extensions that were not associated with the program id.</returns>
        public string[] CheckAssociation(string progId, params string[] extensions)
        {
            List <string> notAssociated = new List <string>();

            foreach (string s in extensions)
            {
                FileAssociationInfo fai = new FileAssociationInfo(s);

                if (!fai.Exists || fai.ProgID != progId)
                {
                    notAssociated.Add(s);
                }
            }

            return(notAssociated.ToArray());
        }
Example #20
0
        /// <summary>
        /// Gets a value that indicates the name of the associated application with the behavior to handle this extension.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
        /// <returns>Associated Program ID of handling program.</returns>
        protected string GetProgID(FileAssociationInfo file)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            object val = registryWrapper.Read(file.extension, string.Empty);

            if (val == null)
            {
                return(string.Empty);
            }

            return(val.ToString());
        }
Example #21
0
        /// <summary>
        /// Verifies that given extension exists and is associated with given program id
        /// </summary>
        /// <param name="extension">Extension to be checked for.</param>
        /// <param name="progId">progId to be checked for.</param>
        /// <returns>True if association exists, false if it does not.</returns>
        public bool IsValid(string extension, string progId)
        {
            FileAssociationInfo fai = new FileAssociationInfo(extension);

            if (!fai.Exists)
            {
                return(false);
            }

            if (progId != fai.ProgID)
            {
                return(false);
            }

            return(true);
        }
Example #22
0
        /// <summary>
        /// Gets a value that indicates the filter component that is used to search for text within documents of this type.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
        /// <returns>Guid of filter component.</returns>
        protected Guid GetPersistentHandler(FileAssociationInfo file)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            object val = registryWrapper.Read(file.extension + "\\PersistentHandler", string.Empty);

            if (val == null)
            {
                return(new Guid());
            }
            else
            {
                return(new Guid(val.ToString()));
            }
        }
Example #23
0
 public static void Run()
 {
     FileAssociationInfo associate = new FileAssociationInfo(".plist");
     if (!associate.Exists)
     {
         associate.Create();
     }
     associate.ContentType = "Application/PList";
     associate.ProgID = "ProperityList";
     ////if (associate.OpenWithList == null)
     //{
     //    associate.OpenWithList = new string[]{
     //        args
     //    };
     //}
     //else if(!associate.OpenWithList.Contains("args"))
     //{
     //    List<string> list = new List<string>();
     //    list.Add(args);
     //    list.AddRange(associate.OpenWithList);
     //    associate.OpenWithList = list.ToArray();
     //}
     string args = Path.GetFullPath(Path.Combine(Application.StartupPath, "IPATools.PlistEditor.exe")) + " \"%1\"";
     string ico = Path.Combine(Application.StartupPath, "file.ico");
     ProgramVerb open = new ProgramVerb("Open", args);
     ProgramAssociationInfo pai = new ProgramAssociationInfo(associate.ProgID);
     if (!pai.Exists)
     {
         pai.Create("ProperityList", open);
     }
     else
     {
         for (int i = 0; i < pai.Verbs.Length; i++)
         {
             if (pai.Verbs[i].Name.Equals("open", StringComparison.OrdinalIgnoreCase))
             {
                 pai.RemoveVerb(pai.Verbs[i]);
                 pai.AddVerb(open);
                 break;
             }
         }
     }
     pai.DefaultIcon = new ProgramIcon(ico);
 }
Example #24
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            TRE_Explorer.Properties.Settings.Default.OpenFolder = this.textBoxOpenFolder.Text;
              TRE_Explorer.Properties.Settings.Default.SaveFolder = this.textBoxSaveFolder.Text;

              switch (this.comboBoxDefaultView.SelectedItem.ToString()) {
            case "Large Icons":
              TRE_Explorer.Properties.Settings.Default.DefaultView = View.LargeIcon;
              break;

            case "Small Icons":
              TRE_Explorer.Properties.Settings.Default.DefaultView = View.SmallIcon;
              break;

            case "List":
              TRE_Explorer.Properties.Settings.Default.DefaultView = View.List;
              break;

            case "Details":
              TRE_Explorer.Properties.Settings.Default.DefaultView = View.Details;
              break;
              }
              TRE_Explorer.Properties.Settings.Default.DetailsDisplaysFullPath = this.checkBoxDetailsPanePathDisplay.Checked;
              TRE_Explorer.Properties.Settings.Default.PromptForUpdates = this.checkBoxPromptForUpdates.Checked;
              TRE_Explorer.Properties.Settings.Default.DisplayNotifyIcon = this.checkBoxDisplayNotifyIcon.Checked;
              TRE_Explorer.Properties.Settings.Default.Save();

              for (Int32 index = 0; index < this.checkedListBoxFileTypes.Items.Count; index++) {
            FileAssociationInfo fileAssociationInfo = new FileAssociationInfo("." + this.checkedListBoxFileTypes.Items[index].ToString().ToLower());
            if (this.checkedListBoxFileTypes.GetItemChecked(index)) {
              if (!fileAssociationInfo.Exists) {
            fileAssociationInfo.Create("TRE Explorer");
              } else {
            fileAssociationInfo.ProgID = "TRE Explorer";
              }
            } else {
              if ((fileAssociationInfo.Exists) && (fileAssociationInfo.ProgID == "TRE Explorer")) {
            fileAssociationInfo.Delete();
              }
            }
              }

              this.DialogResult = DialogResult.OK;
        }
Example #25
0
        /// <summary>
        /// Associates a single executable with a list of extensions.
        /// </summary>
        /// <param name="progId">Name of program id</param>
        /// <param name="executablePath">Path to executable to start including arguments.</param>
        /// <param name="extensions">String array of extensions to associate with program id.</param>
        /// <example>progId = "MyTextFile"
        /// executablePath = "notepad.exe %1"
        /// extensions = ".txt", ".text"</example>
        public void Associate(string progId, string executablePath, params string[] extensions )
        {
            foreach (string s in extensions)
             {
            FileAssociationInfo fai = new FileAssociationInfo(s);

            if (!fai.Exists)
               fai.Create(progId);

            fai.ProgID = progId;
             }

             ProgramAssociationInfo pai = new ProgramAssociationInfo(progId);

             if (!pai.Exists)
            pai.Create();

             pai.AddVerb(new ProgramVerb("open", executablePath));
        }
Example #26
0
        /// <summary>
        /// Gets array of containing program file names which should be displayed in the Open With List.
        /// </summary>
        /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
        /// <returns>Program file names</returns>
        protected string[] GetOpenWithList(FileAssociationInfo file)
        {
            if (!file.Exists)
            {
                throw new Exception("Extension does not exist");
            }

            RegistryKey root = Registry.ClassesRoot;

            RegistryKey key = root.OpenSubKey(file.extension);

            key = key.OpenSubKey("OpenWithList");

            if (key == null)
            {
                return(new string[0]);
            }

            return(key.GetSubKeyNames());
        }
Example #27
0
        /// <summary>
        /// Associates a single executable with a list of extensions.
        /// </summary>
        /// <param name="progId">Name of program id</param>
        /// <param name="executablePath">Path to executable to start including arguments.</param>
        /// <param name="extensions">String array of extensions to associate with program id.</param>
        /// <example>progId = "MyTextFile"
        /// executablePath = "notepad.exe %1"
        /// extensions = ".txt", ".text"</example>
        public void Associate(string progId, string executablePath, params string[] extensions)
        {
            foreach (string s in extensions)
            {
                FileAssociationInfo fai = new FileAssociationInfo(s);

                if (!fai.Exists)
                {
                    fai.Create(progId);
                }

                fai.ProgID = progId;
            }

            ProgramAssociationInfo pai = new ProgramAssociationInfo(progId);

            if (!pai.Exists)
            {
                pai.Create();
            }

            pai.AddVerb(new ProgramVerb("open", executablePath));
        }
Example #28
0
        /// <summary>
        /// Associates a single executable with a list of extensions.
        /// </summary>
        /// <param name="progId">Name of program id</param>
        /// <param name="executablePath">Path to executable to start including arguments.</param>
        /// <param name="extensions">String array of extensions to associate with program id.</param>
        /// <example>progId = "MyTextFile"
        /// executablePath = "notepad.exe %L"
        /// extensions = ".txt", ".text"</example>
        public void Associate(string progId, string executablePath, string extension, ProgramIcon icon = null)
        {
            FileAssociationInfo fai = new FileAssociationInfo(extension);

            if (!fai.Exists)
            {
                fai.Create(progId);
            }

            fai.ProgID = progId;

            ProgramAssociationInfo pai = new ProgramAssociationInfo(progId);

            if (!pai.Exists)
            {
                pai.Create();
            }

            pai.AddVerb(new ProgramVerb("open", executablePath));
            if (icon != null)
            {
                pai.DefaultIcon = icon;
            }
        }
Example #29
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();
      }
Example #30
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;
      }
Example #31
0
      /// <summary>
      /// Sets array of containing program file names which should be displayed in the Open With List.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <param name="programList">Program file names</param>
      protected void SetOpenWithList(FileAssociationInfo file, string[] programList)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         RegistryKey root = Registry.ClassesRoot;

         RegistryKey key = root.OpenSubKey(file.extension, true);

         RegistryKey tmpkey = key.OpenSubKey("OpenWithList", true);

         if (tmpkey != null)
         {
            key.DeleteSubKeyTree("OpenWithList");
         }

         key = key.CreateSubKey("OpenWithList");

         foreach (string s in programList)
         {
            key.CreateSubKey(s);
         }

         ShellNotification.NotifyOfChange();
      }
Example #32
0
        public static bool IsAssociated(string progId, string extension)
        {
            var fai = new FileAssociationInfo(extension);

            return(fai.Exists && fai.ProgID == progId);
        }
Example #33
0
      /// <summary>
      /// Creates actual file extension entry in registry.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> instance that contains specifics on extension to be created.</param>
      protected void Create(FileAssociationInfo file)
      {
         if (file.Exists)
         {
            file.Delete();
         }

         RegistryKey root = Registry.ClassesRoot;

         root.CreateSubKey(file.extension);
      }
Example #34
0
      /// <summary>
      /// Gets a value that indicates the name of the associated application with the behavior to handle this extension.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <returns>Associated Program ID of handling program.</returns>
      protected string GetProgID(FileAssociationInfo file)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         object val = registryWrapper.Read(file.extension, string.Empty);

         if (val == null)
            return string.Empty;

         return val.ToString();
      }
Example #35
0
      /// <summary>
      /// Gets a value that determines the MIME type of the file.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <returns>MIME content type of extension.</returns>
      protected string GetContentType(FileAssociationInfo file)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         object val = registryWrapper.Read(file.extension, "Content Type");

         if (val == null)
         {
            return string.Empty;
         }
         else
         {
            return val.ToString();
         }
      }
Example #36
0
 private void InitializeRegistryBoundItems()
 {
     if (!UacHelper.IsProcessElevated)
     {
         registryBoundPreferences.IsEnabled = false;
         elevatePermissionsPanel.Visibility = Visibility.Visible;
     }
     try // We know we don't have write access, but we might have read access
     {
         var torrent = new FileAssociationInfo(".torrent");
         if (torrent.Exists)
             torrentAssociationCheckBox.IsChecked = torrent.ProgID == "Patchy";
         else
             torrentAssociationCheckBox.IsChecked = false;
         // Check magnet link association
         var value = Registry.GetValue(@"HKEY_CLASSES_ROOT\\Magnet", null, null);
         if (value == null)
             magnetAssociationCheckBox.IsChecked = false;
         else
         {
             var shell = (string)Registry.GetValue(@"HKEY_CLASSES_ROOT\Magnet\shell\open\command", null, null);
             magnetAssociationCheckBox.IsChecked = shell == string.Format("\"{0}\" \"%1\"", Assembly.GetEntryAssembly().Location);
         }
         var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
         var startup = key.GetValue("Patchy", null) as string;
         startOnWindowsStartupCheckBox.IsChecked = startup != null;
         if (startup == null)
             startMinimizedCheckBox.IsChecked = false;
         else
             startMinimizedCheckBox.IsChecked = startup.EndsWith("--minimized");
     }
     catch { }
 }
      //Prompt for new extension and create it if it does not exist
      private void addExtension_Click(object sender, EventArgs e)
      {
         NewExtensionDialog dialog = new NewExtensionDialog();

         if (dialog.ShowDialog() == DialogResult.OK)
         {
            FileAssociationInfo fai = new FileAssociationInfo(dialog.Extension);

            if (fai.Exists)
            {
               MessageBox.Show("Specified extension already exists and will not be added");
            }
            else
            {
               fai.Create();
            }
            
            refreshExtensionsButton_Click(null, null);
         }

      }
      //Wipes out existing open with list and replaces them with provided list
      private void removeOpenWith_Click(object sender, EventArgs e)
      {
         string extension = (string)extensionsListBox.SelectedItem;

         FileAssociationInfo fa = new FileAssociationInfo(extension);

         if (!fa.Exists)
         {
            return;
         }

         List<string> l = new List<string>();

         l.AddRange(fa.OpenWithList);


         if (l.Contains(openWithListBox.SelectedItem.ToString()))
         {
            l.Remove(openWithListBox.SelectedItem.ToString());
            fa.OpenWithList = l.ToArray();

            refreshExtensionsButton_Click(null, null);
            extensionsListBox.SelectedItem = extension;
         }

      }
      private void extensionsListBox_SelectedIndexChanged(object sender, EventArgs e)
      {
         string extension = (string)extensionsListBox.SelectedItem;

         FileAssociationInfo fa = new FileAssociationInfo(extension);

         contentTypeTextBox.Text = fa.ContentType;
         contentTypeTextBox.Tag = contentTypeTextBox.Text;

         programIdTextBox.Text = fa.ProgID;
         programIdTextBox.Tag = programIdTextBox.Text;

         openWithListBox.DataSource = fa.OpenWithList;

         PerceivedTypeComboBox.DataSource = Enum.GetNames(typeof(PerceivedTypes));
         PerceivedTypeComboBox.SelectedIndex = (int)fa.PerceivedType;
         PerceivedTypeComboBox.Tag = PerceivedTypeComboBox.SelectedIndex;

         extensionLabel.Text = fa.Extension;

         if (fa.PersistentHandler != Guid.Empty)
         {
            persistentHandlerTextBox.Text = fa.PersistentHandler.ToString();
            persistentHandlerTextBox.Tag = fa.PersistentHandler;
         }
         else
         {
            persistentHandlerTextBox.Text = "";
         }

         if (fa.PersistentHandler != Guid.Empty)
         {
            persistentHandlerTextBox.Tag = persistentHandlerTextBox.Text = fa.PersistentHandler.ToString();
         }
         else
         {
            persistentHandlerTextBox.Tag = persistentHandlerTextBox.Text = "";
         }

         ProgramAssociationInfo pa = new ProgramAssociationInfo(fa.ProgID);
         programIdLabel.Text = fa.ProgID;

         if (pa.Exists)
         {
            programIdGroupBox.Enabled = true;

            EditFlags[] editFlags = (EditFlags[])Enum.GetValues(typeof(EditFlags));

            editFlagsListBox.Items.Clear();

            foreach (EditFlags flag in editFlags)
            {
               editFlagsListBox.Items.Add(flag);
            }

            EditFlags[] flags = (EditFlags[])Enum.GetValues(typeof(EditFlags));

            EditFlags setFlags = pa.EditFlags;
            editFlagsListBox.Tag = setFlags;

            for (int x = 1; x < flags.Length; x++)
            {
               EditFlags flag = flags[x];

               if ((setFlags & flag) == flag)
               {
                  editFlagsListBox.SetItemChecked(x, true);
               }
               else
               {
                  editFlagsListBox.SetItemChecked(x, false);
               }
            }

            if (setFlags == EditFlags.None)
            {
               editFlagsListBox.SetItemChecked((int)EditFlags.None, true);
            }
            else
            {
               editFlagsListBox.SetItemChecked((int)EditFlags.None, false);
            }


            editFlagsListBox.Tag = GetIntArray(editFlagsListBox);

            ProgramVerb[] verbs = pa.Verbs;
            verbsTreeView.Nodes.Clear();
            foreach (ProgramVerb verb in verbs)
            {
               TreeNode node = new TreeNode(verb.Name);
               node.Nodes.Add(new TreeNode(verb.Command));
               node.Nodes[0].Tag = "command";
               verbsTreeView.Nodes.Add(node);
            }
            verbsTreeView.ExpandAll();

            descriptionTextBox.Text = pa.Description;
            descriptionTextBox.Tag = descriptionTextBox.Text;


            alwaysShowExtCheckBox.Checked = pa.AlwaysShowExtension;
            alwaysShowExtCheckBox.Tag = alwaysShowExtCheckBox.Checked;

            if (pa.DefaultIcon != ProgramIcon.None)
            {
               iconPathTextBox.Text = pa.DefaultIcon.Path;
               iconIndexTextBox.Text = pa.DefaultIcon.Index.ToString();
            }
            else
            {
               iconPathTextBox.Text = "";
               iconIndexTextBox.Text = "";
            }

         }
         else
         {
            programIdGroupBox.Enabled = false;

            editFlagsListBox.Items.Clear();
            verbsTreeView.Nodes.Clear();

            descriptionTextBox.Text = "";
            descriptionTextBox.Tag = "";
         }

      }
      //Wipes out existing open with list and replaces them with provided list
      private void addOpenWith_Click(object sender, EventArgs e)
      {
         string extension = (string)extensionsListBox.SelectedItem;

         FileAssociationInfo fa = new FileAssociationInfo(extension);

         if (!fa.Exists)
         {
            return;
         }

         AddOpenWithDialog f = new AddOpenWithDialog();
         if (f.ShowDialog() == DialogResult.OK)
         {
            List<string> l = new List<string>();

            l.AddRange(fa.OpenWithList);
            if (!l.Contains(f.ProgramName))
            {
               l.Add(f.ProgramName);
               fa.OpenWithList = l.ToArray();

               refreshExtensionsButton_Click(null, null);
               extensionsListBox.SelectedItem = extension;
            }
         }
      
      }
Example #41
0
      /// <summary>
      /// Gets a value that indicates the filter component that is used to search for text within documents of this type.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <returns>Guid of filter component.</returns>
      protected Guid GetPersistentHandler(FileAssociationInfo file)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         object val = registryWrapper.Read(file.extension + "\\PersistentHandler", string.Empty);

         if (val == null)
            return new Guid();
         else
            return new Guid(val.ToString());
      }
Example #42
0
 private void torrentAssociationCheckBoxChecked(object sender, RoutedEventArgs e)
 {
     var torrent = new FileAssociationInfo(".torrent");
     if (torrentAssociationCheckBox.IsChecked.Value)
     {
         torrent.Create("Patchy");
         torrent.ContentType = "application/x-bittorrent";
         torrent.OpenWithList = new[] { "patchy.exe" };
         var program = new ProgramAssociationInfo(torrent.ProgID);
         if (!program.Exists)
         {
             program.Create("Patchy Torrent File", new ProgramVerb("Open", string.Format(
                 "\"{0}\" \"%1\"", Path.Combine(Assembly.GetEntryAssembly().Location))));
             program.DefaultIcon = new ProgramIcon(Assembly.GetEntryAssembly().Location);
         }
     }
     else
         torrent.Delete();
 }
Example #43
0
      /// <summary>
      /// Sets a value that indicates the filter component that is used to search for text within documents of this type.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <param name="persistentHandler">Guid of filter component.</param>
      protected void SetPersistentHandler(FileAssociationInfo file, Guid persistentHandler)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         if (persistentHandler == Guid.Empty)
            return;

         this.registryWrapper.Write(file.extension + "\\" + PersistentHandler, string.Empty, persistentHandler);

         ShellNotification.NotifyOfChange();
      }
Example #44
0
      /// <summary>
      /// Verifies that given extension exists and is associated with given program id
      /// </summary>
      /// <param name="extension">Extension to be checked for.</param>
      /// <param name="progId">progId to be checked for.</param>
      /// <returns>True if association exists, false if it does not.</returns>
      public bool IsValid(string extension, string progId)
      {
         FileAssociationInfo fai = new FileAssociationInfo(extension);

         if (!fai.Exists)
            return false;

         if (progId != fai.ProgID)
            return false;

         return true;
      }
Example #45
0
      /// <summary>
      /// Sets a value that determines the MIME type of the file.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <param name="type">MIME content type of extension.</param>
      protected void SetContentType(FileAssociationInfo file, string type)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         registryWrapper.Write(file.extension, "Content Type", type);

         ShellNotification.NotifyOfChange();
      }
Example #46
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;
      }
Example #47
0
      /// <summary>
      /// Set a value that indicates the name of the associated application with the behavior to handle this extension.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <param name="progId">Associated Program ID of handling program.</param>
      protected void SetProgID(FileAssociationInfo file, string progId)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         registryWrapper.Write(file.extension, string.Empty, progId);

         ShellNotification.NotifyOfChange();
      }
Example #48
0
      /// <summary>
      /// Gets array of containing program file names which should be displayed in the Open With List.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> that provides specifics of the extension to be changed.</param>
      /// <returns>Program file names</returns>
      protected string[] GetOpenWithList(FileAssociationInfo file)
      {
         if (!file.Exists)
            throw new Exception("Extension does not exist");

         RegistryKey root = Registry.ClassesRoot;

         RegistryKey key = root.OpenSubKey(file.extension);

         key = key.OpenSubKey("OpenWithList");

         if (key == null)
         {
            return new string[0];
         }

         return key.GetSubKeyNames();

      }
Example #49
0
      /// <summary>
      /// Deletes actual file extension entry in registry.
      /// </summary>
      /// <param name="file"><see cref="FileAssociationInfo"/> instance that contains specifics on extension to be deleted.</param>
      protected void Delete(FileAssociationInfo file)
      {
         if (!file.Exists)
         {
            throw new Exception("Key not found.");
         }

         RegistryKey root = Registry.ClassesRoot;

         root.DeleteSubKeyTree(file.extension);
      }
      //Update values related to extension that have changed
      private void extensionUpdateButton_Click(object sender, EventArgs e)
      {
         string extension = (string)extensionsListBox.SelectedItem;

         FileAssociationInfo fa = new FileAssociationInfo(extension);

         if (programIdTextBox.Text != (string)programIdTextBox.Tag)
         {
            fa.ProgID = programIdTextBox.Text;
         }

         if (contentTypeTextBox.Text != (string)contentTypeTextBox.Tag)
         {
            fa.ContentType = contentTypeTextBox.Text;
         }

         if (PerceivedTypeComboBox.SelectedIndex != (int)PerceivedTypeComboBox.Tag)
         {
            fa.PerceivedType = (PerceivedTypes)PerceivedTypeComboBox.SelectedIndex;
         }

         if (persistentHandlerTextBox.Text != (string)persistentHandlerTextBox.Tag)
         {
            fa.PersistentHandler = new Guid(persistentHandlerTextBox.Text);
         }

         refreshExtensionsButton_Click(null, null);
         extensionsListBox.SelectedItem = extension;
      }