/// <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 }
/// <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 }
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); }
/// <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)); }
/// <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)); }
/// <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; } }
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); } } } } }
//Add single verb without affecting existing verbs private void addSingleVerbButton_Click(object sender, EventArgs e) { string extension = (string)extensionsListBox.SelectedItem; ProgramAssociationInfo pa = new ProgramAssociationInfo(programIdTextBox.Text); if (!pa.Exists) { return; } AddVerbDialog d = new AddVerbDialog(); if (d.ShowDialog() == DialogResult.OK) { ProgramVerb[] verbs = pa.Verbs; ProgramVerb newVerb = new ProgramVerb(d.VerbName, d.VerbCommand); List<ProgramVerb> l = new List<ProgramVerb>(); if (!l.Contains(newVerb)) { pa.AddVerb(newVerb); refreshExtensionsButton_Click(null, null); extensionsListBox.SelectedItem = extension; } } }
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); } } } }
/// <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; }