示例#1
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);
                    }
                }
            }
        }
示例#2
0
        //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 static void AssociateVerb(string ProgID, string Command, string Name, IconIndex IconIndex)
        {
            ProgramAssociationInfo a = new ProgramAssociationInfo(ProgID);

            a.AddVerb(new ProgramVerb(Name, PathToProgram + Command));
            Registry.LocalMachine.OpenSubKey("SOFTWARE", true).OpenSubKey("Classes", true).OpenSubKey(ProgID, true).OpenSubKey("shell", true).OpenSubKey(Name, true).SetValue("Icon", PathToIcons + ',' + (int)IconIndex);
        }
示例#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);
        }
示例#5
0
        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);
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        public override void ValidateAlways(CommandLineArgument argument, ref string arg)
        {
            if (string.IsNullOrEmpty(arg))
            {
                var exeName = Assembly.GetExecutingAssembly().Location;
                if (VpmUtils.PromptYayOrNay(
                        "Do you want to register this vpm instance? (Open vpm:// or vpms:// url's and open .vpack files)",
                        "It makes life so much easier."))
                {
                    try
                    {
                        VpmUtils.RegisterURIScheme("vpm");
                        VpmUtils.RegisterURIScheme("vpms");

                        var fai = new FileAssociationInfo(".vpack");
                        if (!fai.Exists)
                        {
                            fai.Create("vpm");
                            fai.ContentType = "text/vpack";
                        }
                        var pai      = new ProgramAssociationInfo(fai.ProgID);
                        var progverb = new ProgramVerb("Open", exeName + " %1");
                        if (pai.Exists)
                        {
                            foreach (var pv in pai.Verbs)
                            {
                                pai.RemoveVerb(pv);
                            }
                            pai.AddVerb(progverb);
                        }
                        else
                        {
                            pai.Create("VVVV Package Definition", progverb);
                            pai.DefaultIcon = new ProgramIcon(exeName);
                        }

                        Console.WriteLine("Registered protocols successfully");
                    }
                    catch (Exception)
                    {
                        if (VpmUtils.PromptYayOrNay("Can't write to registry. Retry as Admin?"))
                        {
                            try
                            {
                                var startInfo = new ProcessStartInfo(exeName)
                                {
                                    Arguments = "-RegisterVpmUri",
                                    Verb      = "runas"
                                };
                                Process.Start(startInfo);
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Error occured while trying to run elevated process.");
                                Thread.Sleep(5000);
                            }
                            Environment.Exit(0);
                        }
                    }
                }

                Console.WriteLine("Alright, enjoy!");
                Thread.Sleep(5000);
                Environment.Exit(0);
            }
            arg = arg.Trim('"');
            if (arg.StartsWith("vpm://", true, CultureInfo.InvariantCulture))
            {
                if (arg.EndsWith(".vpack", true, CultureInfo.InvariantCulture))
                {
                    return;
                }
            }
            if (arg.StartsWith("vpms://", true, CultureInfo.InvariantCulture))
            {
                if (arg.EndsWith(".vpack", true, CultureInfo.InvariantCulture))
                {
                    return;
                }
            }
            if (File.Exists(arg))
            {
                if (arg.EndsWith(".vpack", true, CultureInfo.InvariantCulture))
                {
                    arg = Path.GetFullPath(arg);
                    return;
                }
            }
            throw new ValidationArgException("File not found or file is not .vpack");
        }