Example #1
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);
 }
        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);
                        }
                    }
                }
            }
        }
      //Removes single verb from program id without affecting existing verbs
      private void removeSingleVerbButton_Click(object sender, EventArgs e)
      {
         TreeNode node = verbsTreeView.SelectedNode;
         if (node == null)
            return;

         if (node.Tag != null && node.Tag.ToString() == "command")
         {
            node = node.Parent;
         }

         string extension = (string)extensionsListBox.SelectedItem;
         ProgramAssociationInfo pa = new ProgramAssociationInfo(programIdTextBox.Text);

         if (!pa.Exists)
         {
            return;
         }

         pa.RemoveVerb(node.Text);

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

      }
Example #4
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);
              }
            }
              }
        }