Example #1
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 static void Associate(string progId, string executablePath, params string[] extensions)
		{
			Associate(progId, extensions);

			var pai = new ProgramAssociationInfo(progId);

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

			pai.AddVerb(new ProgramVerb("open", executablePath+" \"%1\"")); // Note: the %1 ensures that the opened file will be passed to the program's command line
		}
Example #2
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 static void Associate(string progId, string executablePath, params string[] extensions)
        {
            Associate(progId, extensions);

            var pai = new ProgramAssociationInfo(progId);

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

            pai.AddVerb(new ProgramVerb("open", executablePath + " \"%1\""));           // Note: the %1 ensures that the opened file will be passed to the program's command line
        }
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
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();
 }
        public FileAssociations()
        {
            InitializeComponent();

            this.chkAlwaysCheckFileAssociations.IsChecked = Properties.Settings.Default.AlwaysCheckFileAssociations;

            RegistryHelper.UseCurrentUser = true;

            //Ensure there is Program Association Info for us in the Registry
            ProgramAssociationInfo rdfEditorInfo = new ProgramAssociationInfo(RegistryProgramID);
            if (!rdfEditorInfo.Exists) rdfEditorInfo.Create();
            bool hasOpenVerb = false;
            foreach (ProgramVerb verb in rdfEditorInfo.Verbs)
            {
                if (verb.Name.Equals("open"))
                {
                    if (verb.Command.StartsWith(System.IO.Path.GetFullPath("rdfEditor.exe")))
                    {
                        hasOpenVerb = true;
                    }
                    else
                    {
                        rdfEditorInfo.RemoveVerb("open");
                    }
                }
            }
            if (!hasOpenVerb)
            {
                rdfEditorInfo.AddVerb(new ProgramVerb("open", System.IO.Path.GetFullPath("rdfEditor.exe") + " \"%1\""));
            }

            //See which extensions are currently associated to us
            foreach (FileAssociationInfo info in _associations)
            {
                if (!info.Exists)
                {
                    //If no association exists then we'll aim to create it
                    this.SetAssociationsChecked(info.Extension);
                }
                else
                {
                    //Check if the File Associations Program ID is equal to ours
                    if (info.ProgID.Equals(RegistryProgramID))
                    {
                        //Prog ID is equal to ours to we are associated with this extension
                        this._currentAssociations.Add(info.Extension);
                        this.SetAssociationsChecked(info.Extension);
                    }
                    else if (info.ProgID.Equals(String.Empty))
                    {
                        //No Prog ID specified so we'll aim to create it
                        this.SetAssociationsChecked(info.Extension);
                    }
                    else
                    {
                        ProgramAssociationInfo progInfo = new ProgramAssociationInfo(info.ProgID);
                        if (!progInfo.Exists)
                        {
                            //No program association exists so we'll aim to create it
                            this.SetAssociationsChecked(info.Extension);
                        }
                        else
                        {
                            //Associated with some other program currently
                            bool hasExistingOpen = false;
                            foreach (ProgramVerb verb in progInfo.Verbs)
                            {
                                if (verb.Name.Equals("open"))
                                {
                                    hasExistingOpen = true;
                                }
                            }
                            //No Open Verb so we'll try to associated with ourselves
                            if (!hasExistingOpen) this.SetAssociationsChecked(info.Extension);
                        }
                    }
                }
            }
        }
Example #10
0
 public void associaExt()
 {
     var filename = Assembly.GetEntryAssembly().Location;
     if (!IsAssociated(".zip"))
         Associate(".zip", "SisBackup", "SisBackup", filename, filename);
     associaExt_();
     ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);
     if (!pai.Exists)
     {
         pai.Create("Programa SisBackup", new ProgramVerb("Open", filename + " % 1"));
         pai.DefaultIcon = new ProgramIcon(filename);
     }
 }
Example #11
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);
            }
        }
      //Prompt for new program id and create it if it does not exist.
      private void newProgramAssociationButton_Click(object sender, EventArgs e)
      {
         NewProgramAssociationDialog dialog = new NewProgramAssociationDialog();

         if (dialog.ShowDialog() == DialogResult.OK)
         {
            ProgramAssociationInfo pai = new ProgramAssociationInfo(dialog.ProgramID);

            if (pai.Exists)
            {
               MessageBox.Show("Specified program already exists and will not be added");
            }
            else
            {
               pai.Create();
            }

            refreshExtensionsButton_Click(null, null);
         }

      }
Example #13
0
        public static void RegisterFileAssociation()
        {
            FileAssociationInfo fileInfo = new FileAssociationInfo(".cin");

            if (fileInfo.Exists)
                fileInfo.Delete();

            if (!fileInfo.Exists)
            {
                fileInfo.Create("YahooKeyKeyCin");
                fileInfo.ContentType = "text/plain";
                fileInfo.OpenWithList = new string[] {
                    "CinInstaller.exe", "notepad.exe", "winword.exe"
                };
            }

            string currentLocale = CultureInfo.CurrentUICulture.Name;

            ProgramAssociationInfo programInfo = new ProgramAssociationInfo(fileInfo.ProgID);

            if (programInfo.Exists)
                programInfo.Delete();

            if (!programInfo.Exists)
            {
                string cinInstallerFilename = Application.StartupPath +
                    Path.DirectorySeparatorChar + "CinInstaller.exe";

                string command = cinInstallerFilename + " %1";
                string description = "Yahoo! KeyKey Input Method Table";

                if (currentLocale.Equals("zh-TW"))
                    description = "Yahoo! \u5947\u6469\u8f38\u5165\u6cd5\u8868\u683c";
                else if (currentLocale.Equals("zh-CN"))
                    description = "Yahoo! \u5947\u6469\u8f93\u5165\u6cd5\u8868\u683c";

                programInfo.Create(description, new ProgramVerb("Open", @command));
                programInfo.DefaultIcon = new ProgramIcon(cinInstallerFilename, 1);
                programInfo.AlwaysShowExtension = true;
            }

            ProgramAssociationInfo uriInfo = new ProgramAssociationInfo("ykeykey");

            if (uriInfo.Exists)
                uriInfo.Delete();

            if (!uriInfo.Exists)
            {
                string urlHandlerFilename = Application.StartupPath +
                    Path.DirectorySeparatorChar + "PhraseEditor.exe";

                string command = urlHandlerFilename + " %1";
                string description = "URL:Yahoo! KeyKey User Phrase Protocol";

                if (currentLocale.Equals("zh-TW"))
                    description = "URL:Yahoo! \u5947\u6469\u8f38\u5165\u6cd5\u52a0\u5b57\u52a0\u8a5e\u5354\u5b9a";
                else if (currentLocale.Equals("zh-CN"))
                    description = "URL:Yahoo! \u5947\u6469\u8f93\u5165\u6cd5\u52a0\u5b57\u52a0\u8bcd\u534f\u5b9a";

                uriInfo.Create(description, new ProgramVerb("Open", @command));
                // uriInfo.DefaultIcon = new ProgramIcon(urlHandlerFilename, 1);
                uriInfo.IsURLProtocol = true;
            }
        }
Example #14
0
        private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.tabControl.SelectedTab == this.tabPageAssociations) {
            ProgramAssociationInfo programAssociationInfo = new ProgramAssociationInfo("TRE Explorer");
            if (!programAssociationInfo.Exists) {
              programAssociationInfo.Create(new ProgramVerb("Open", "\"" + Application.ExecutablePath + "\" \"%1\""));
              programAssociationInfo.DefaultIcon = new ProgramIcon(Application.ExecutablePath, 0);
            } else {
              if (programAssociationInfo.Verbs.Length > 0) {
            for (Int32 counter = 0; counter < programAssociationInfo.Verbs.Length; counter++) {
              if ((programAssociationInfo.Verbs[counter].Name == "Open") && (programAssociationInfo.Verbs[counter].Command != "\"" + Application.ExecutablePath + "\" \"%1\"")) {
                programAssociationInfo.RemoveVerb(programAssociationInfo.Verbs[counter]);
                programAssociationInfo.AddVerb(new ProgramVerb("Open", "\"" + Application.ExecutablePath + "\" \"%1\""));
                break;
              }
            }
              } else {
            programAssociationInfo.AddVerb(new ProgramVerb("Open", "\"" + Application.ExecutablePath + "\" \"%1\""));
              }
              if (programAssociationInfo.DefaultIcon.Path != Application.ExecutablePath) {
            programAssociationInfo.DefaultIcon = new ProgramIcon(Application.ExecutablePath, 0);
              }
            }

            for (Int32 counter = 0; counter < this.checkedListBoxFileTypes.Items.Count; counter++) {
              FileAssociationInfo fileAssociationInfo = new FileAssociationInfo("." + this.checkedListBoxFileTypes.Items[counter].ToString().ToLower());
              if (fileAssociationInfo.Exists) {
            if (fileAssociationInfo.ProgID == "TRE Explorer") {
              this.checkedListBoxFileTypes.SetItemChecked(counter, true);
            } else {
              this.checkedListBoxFileTypes.SetItemChecked(counter, false);
            }
              } else {
            this.checkedListBoxFileTypes.SetItemChecked(counter, false);
              }
            }
              }
        }
Example #15
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 #16
0
        private void associateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!UAC.IsAdmin())
            {
                if (!UAC.RestartElevated("assoc"))
                {
                    MessageBox.Show("Can't associate extension without admin rights!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
            else
            {

                DialogResult dRes = MessageBox.Show("Associate *.wad and *.spr files with this program?", "File(s) association",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dRes == System.Windows.Forms.DialogResult.Yes)
                {
                    FileAssociationInfo faiWad = new FileAssociationInfo(".wad");
                    FileAssociationInfo faiSpr = new FileAssociationInfo(".spr");
                    faiWad.Create(Application.ProductName);
                    faiSpr.Create(Application.ProductName);
                    faiWad.OpenWithList = new string[] { Application.ExecutablePath };
                    faiSpr.OpenWithList = new string[] { Application.ExecutablePath };

                    ProgramAssociationInfo paiWad = new ProgramAssociationInfo(faiWad.ProgID);
                    ProgramAssociationInfo paiSpr = new ProgramAssociationInfo(faiSpr.ProgID);
                    paiWad.Create(new ProgramVerb("Open", Application.ExecutablePath + " \"%1\""));
                    paiSpr.Create(new ProgramVerb("Open", Application.ExecutablePath + " \"%1\""));
                }
            }
        }