コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        void InitFileAssociations()
        {
            FileAssociationInfo fai = new FileAssociationInfo(".mvcmap");

            if (!fai.Exists)
            {
                fai.Create("RatCow.MvcFramework.MVCMAP");
                fai.ContentType = "application/mvcmap-xml";
                //Programs automatically displayed in open with list
                fai.OpenWithList = new string[] { "mvcmaptool.exe", "notepad.exe", "wordpad.exe", "sublimeedit2.exe" };
            }

            ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);

            if (!pai.Exists)
            {
                pai.Create
                (
                    //Description of program/file type
                    "RatCow Soft MvcFramework MVCMAP editor",

                    new ProgramVerb(
                        "Open",                                             //Verb name
                        String.Format("{0} %1", Application.ExecutablePath) //Path and arguments to use
                        )
                );
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: pyrescene/ilSFV
        private static void RegisterFileType(string extensionType)
        {
            string id = "ilSFV-" + extensionType.ToUpper();
            FileAssociationInfo fai = new FileAssociationInfo("." + extensionType.ToLower());

            if (fai.Exists)
            {
                fai.Delete();
            }
            fai.Create(id);

            string path = Assembly.GetExecutingAssembly().Location;

            ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);

            if (pai.Exists)
            {
                pai.Delete();
            }

            pai.Create
            (
                string.Format("{0} File", extensionType.ToUpper()),
                new ProgramVerb("Open", path + " \"%1\"")
            );

            /*RegistryWrapper reg = new RegistryWrapper();
             * reg.Write(string.Format(@"{0}\shell\ilSFV", id), "MUIVerb", "ilSFV");
             * reg.Write(string.Format(@"{0}\shell\ilSFV", id), "MultiSelectModel", "Single");
             * reg.Write(string.Format(@"{0}\shell\ilSFV", id), "SubCommands", "ilsfv.verify");*/
        }
コード例 #5
0
ファイル: settings.cs プロジェクト: Jackzmc/zpaq-gui
        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //run with admin - set file assoc
            FileAssociationInfo fai = new FileAssociationInfo(".zpaq");

            if (!fai.Exists)
            {
                fai.Create("zpaq_gui");
                //fai.ContentType = "application/zpaq"; //MIME type (is optional)
                fai.OpenWithList = new string[] { "zpaq-gui.exe" };
            }
            ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);

            if (!pai.Exists)
            {
                pai.Create
                (
                    //Description of program/file type
                    ".zpaq compression",

                    new ProgramVerb
                    (
                        //Verb name
                        "Open",
                        //Path and arguments to use

                        System.Reflection.Assembly.GetEntryAssembly().Location
                    )
                );

                //optional
                pai.DefaultIcon = new ProgramIcon(@"C:\SomePath\SomeIcon.ico");
            }
        }
コード例 #6
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;
                }
            }
        }
コード例 #7
0
        //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;
        }
コード例 #8
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();
                    }
                }
            }
        }
コード例 #9
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);
                    }
                }
            }
        }
コード例 #10
0
        private static void AssociateMainData(string ProgID, string Description, EditFlags flags, IconIndex IconIndex)
        {
            ProgramAssociationInfo a = new ProgramAssociationInfo(ProgID);

            if (!a.Exists)
            {
                a.Create();
            }
            Registry.LocalMachine.OpenSubKey("SOFTWARE", true).OpenSubKey("Classes", true).OpenSubKey(ProgID, true).CreateSubKey("DefaultIcon", RegistryKeyPermissionCheck.ReadWriteSubTree).SetValue("", PathToIcons + ',' + (int)IconIndex);
            a.Description = Description;
            a.EditFlags   = flags;
        }
コード例 #11
0
        //Wipes out existing verbs and replaces them with provided list
        private void removeVerbButton_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;
            }

            ProgramVerb[]      verbs = pa.Verbs;
            List <ProgramVerb> l     = new List <ProgramVerb>();

            l.AddRange(verbs);

            ProgramVerb verbToRemove = null;

            foreach (ProgramVerb verb in l)
            {
                if (verb.Name == node.Text)
                {
                    verbToRemove = verb;
                    break;
                }
            }

            if (verbToRemove != null)
            {
                l.Remove(verbToRemove);
                pa.Verbs = l.ToArray();

                refreshExtensionsButton_Click(null, null);
                extensionsListBox.SelectedItem = extension;
            }
        }
コード例 #12
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);
        }
コード例 #13
0
        //Update values related to program id that have changed
        private void updateProgIdButton_Click(object sender, EventArgs e)
        {
            string extension          = (string)extensionsListBox.SelectedItem;
            ProgramAssociationInfo pa = new ProgramAssociationInfo(programIdTextBox.Text);

            int[] tmpArray;

            if (pa.Exists)
            {
                if ((string)descriptionTextBox.Tag != descriptionTextBox.Text)
                {
                    pa.Description = descriptionTextBox.Text;
                }

                EditFlags editFlags = EditFlags.None;

                tmpArray = GetIntArray(editFlagsListBox);
                if (!IntArraysEqual(tmpArray, (int[])editFlagsListBox.Tag))
                {
                    for (int x = 0; x < tmpArray.Length; x++)
                    {
                        //If value == 0 then None was selected and will override all others
                        //Do not handle first index, is None
                        if (tmpArray[x] == 0)
                        {
                            break;
                        }

                        editFlags |= (EditFlags)(1 << (tmpArray[x] - 1));
                    }

                    pa.EditFlags = editFlags;
                }

                pa.DefaultIcon = new FileAssociation.ProgramIcon(iconPathTextBox.Text, 0);

                if (alwaysShowExtCheckBox.Checked != (bool)alwaysShowExtCheckBox.Tag)
                {
                    pa.AlwaysShowExtension = alwaysShowExtCheckBox.Checked;
                }
            }

            refreshExtensionsButton_Click(null, null);
            extensionsListBox.SelectedItem = extension;
        }
コード例 #14
0
        //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);
            }
        }
コード例 #15
0
ファイル: Functions.cs プロジェクト: waffle-iron/ImageGlass
        /// <summary>
        /// Register file association
        /// </summary>
        /// <param name="exts">Extensions, for ex: *.png;*.jpg</param>
        /// <param name="appPath">Executable file</param>
        public static void RegisterAssociation(string appPath, string exts)
        {
            string[] ext_list = exts.Replace("*", "").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string ext in ext_list)
            {
                FileAssociationInfo fa = new FileAssociationInfo(ext);
                if (!fa.Exists)
                {
                    return;
                }

                ProgramAssociationInfo pa = new ProgramAssociationInfo(fa.ProgID);

                if (!pa.Exists)
                {
                    return;
                }

                ProgramVerb[]      verbs = pa.Verbs;
                List <ProgramVerb> l     = new List <ProgramVerb>();
                l.AddRange(verbs);

                //remove existed verb
                ProgramVerb openVerb = l.SingleOrDefault(v => v.Name == "open");
                if (openVerb != null)
                {
                    l.Remove(openVerb);
                }

                //add new value
                openVerb = new ProgramVerb("open", "\"" + appPath + "\" \"%1\"");
                l.Add(openVerb);

                //save & apply changes
                pa.Verbs = l.ToArray();

                GlobalSetting.SetConfig("ContextMenuExtensions", exts);
            }
        }
コード例 #16
0
        void InitFileAssociations()
        {
            FileAssociationInfo fai = new FileAssociationInfo(".meo");

            if (!fai.Exists)
            {
                fai.Create("MattsExperimentalOutliner");

                //Specify MIME type (optional)

                fai.ContentType = "application/outliner-data";

                //Programs automatically displayed in open with list

                fai.OpenWithList = new string[] { "outliner.exe", "notepad.exe", "someotherapp.exe" };
            }

            ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);

            if (!pai.Exists)
            {
                pai.Create
                (
                    //Description of program/file type
                    "Matt's Experimental Outliner",

                    new ProgramVerb(
                        //Verb name
                        "Open",
                        //Path and arguments to use
                        String.Format("{0} %1", Application.ExecutablePath)
                        )
                );

                //optional

                //pai.DefaultIcon = new ProgramIcon(@"C:\SomePath\SomeIcon.ico");
            }
        }
コード例 #17
0
        static void Main(string[] args)
        {
            Console.WriteLine("");

            FileAssociationInfo fai = new FileAssociationInfo(".ice");

            fai.Create("IceFile");

            //Specify MIME type (optional)
            fai.ContentType = "code/icefile";

            //Programs automatically displayed in open with list
            fai.OpenWithList = new string[]
            { "notepad.exe", "wordpad.exe", "atom.exe", "Notepad++.exe" };


            ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);

            pai.Create
            (
                //Description of program/file type
                "Ice File",

                new ProgramVerb
                (
                    //Verb name
                    "Open",
                    //Path and arguments to use
                    Environment.GetEnvironmentVariable("windir") + "\\system32\\notepad.exe %1%"
                )
            );

            Process regeditProcess = Process.Start("regedit.exe", "/s filetype.reg");

            regeditProcess.WaitForExit();

            //pai.DefaultIcon = new ProgramIcon(@"C:\Program Files\Ice\iceicon.ico");
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: wblayney/IceLanguage
        static void Main(string[] args)
        {
            FileAssociationInfo fai = new FileAssociationInfo(".ice");

            if (!fai.Exists)
            {
                fai.Create("IceFile");

                //Specify MIME type (optional)
                fai.ContentType = "code/icefile";

                //Programs automatically displayed in open with list
                fai.OpenWithList = new string[]
                { "notepad.exe", "wordpad.exe", "atom.exe", "Notepad++.exe" };
            }

            ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);

            if (!pai.Exists)
            {
                pai.Create
                (
                    //Description of program/file type
                    "Ice File",

                    new ProgramVerb
                    (
                        //Verb name
                        "Open",
                        //Path and arguments to use
                        @"C:\Users\Ashley\AppData\Local\atom\app-1.12.5\atom.exe %1"
                    )
                );

                pai.DefaultIcon = new ProgramIcon(@"C:\Program Files\Ice\iceicon.ico");
            }
        }
コード例 #19
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");
        }
コード例 #20
0
        private void btnTry_AssFileType_Click(object sender, RoutedEventArgs e)
        {
            //  CodeFile1.txt

            bool bDelFai = false;

            //FileAssociationInfo fai = new FileAssociationInfo(".bob");
            FileAssociationInfo fai = new FileAssociationInfo(".TryExt_2");

            if (!(fai.Exists))
            {
                //fai.Create("MyProgramName");
                fai.Create("TryExt_2_FileManager_ProgId");


                //Specify MIME type (optional)
                //fai.ContentType = "application/myfile";
                fai.ContentType = "TryExt_2_FileManager/TryExt_2_File";



                //Programs automatically displayed in open with list
                //fai.OpenWithList = new string[] { "notepad.exe", "wordpad.exe", "someotherapp.exe" };
                fai.OpenWithList = new string[] { "TryExt_FileManager.exe" };
            }
            else
            {
                bDelFai = true;
            }


//////////////////////////////////////////////////


            ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);

            if (!(pai.Exists))
            {
                pai.Create
                (
                    //Description of program/file type
                    "TryExt_FileManager's File Type",

                    new ProgramVerb
                    (
                        //Verb name
                        "Open",
                        //Path and arguments to use
                        //@"C:\SomePath\MyApp.exe %1"
                        @"E:\HthmWork\Projects\VS 2010\DocArchiver\TryExt_FileManager\bin\Debug\TryExt_FileManager.exe %1"
                    )
                );

                //optional
                //pai.DefaultIcon = new ProgramIcon(@"C:\SomePath\SomeIcon.ico");
                pai.DefaultIcon = new ProgramIcon(
                    //pai.Se.setde DefaultIcon = new ProgramIcon(
                    @"E:\HthmWork\Projects\VS 2010\DocArchiver\TryExt_FileManager\Icon1.ico");


                bDelFai = false;
            }
            else
            {
                pai.Delete();
                bDelFai = true;
            }

            if (bDelFai)
            {
                fai.Delete();
            }


            MessageBox.Show("Success !");
        }
コード例 #21
0
        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  = "";
            }
        }
コード例 #22
0
 public FileTypeAssociation(string fileExt)
 {
     _fileAssociationInfo    = new FileAssociationInfo(fileExt);
     _programAssociationInfo = new ProgramAssociationInfo(ProgramId);
 }
コード例 #23
0
ファイル: Welcome.cs プロジェクト: AbbaouiAmine/AutoC
        void associationTypeAndIcon()
        {
            FileAssociationInfo fai  = new FileAssociationInfo(".autoc");
            FileAssociationInfo fai1 = new FileAssociationInfo(".tarif");
            FileAssociationInfo fai2 = new FileAssociationInfo(".acc");

            //if (!fai.Exists && Services.etat==0)
            //{
            fai.Create("AutoConsultation");

            //Specify MIME type (optional)
            fai.ContentType = "application/AutoConsultation-app";

            //Programs automatically displayed in open with list
            fai.OpenWithList = new string[] { "autoc.exe" };
            //}
            //if (!fai1.Exists && Services.etat == 0)
            //{

            fai1.Create("Tarif-AutoConsultation");

            //Specify MIME type (optional)

            fai1.ContentType = "application/AutoConsultation-app";

            //Programs automatically displayed in open with list
            fai1.OpenWithList = new string[] { "autoc.exe" };
            //}
            //if (!fai2.Exists && Services.etat == 0)
            //{

            fai2.Create("Acc-AutoConsultation");

            //Specify MIME type (optional)

            fai2.ContentType = "application/AutoConsultation-app";

            //Programs automatically displayed in open with list
            fai2.OpenWithList = new string[] { "autoc.exe" };
            //}
            /////////////////////////////////////////////////////
            ProgramAssociationInfo pai  = new ProgramAssociationInfo(fai.ProgID);
            ProgramAssociationInfo pai1 = new ProgramAssociationInfo(fai1.ProgID);
            ProgramAssociationInfo pai2 = new ProgramAssociationInfo(fai2.ProgID);
            //if (!pai.Exists && Services.etat == 0)
            //{

            string StartupPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Remove(0, 6);

            string c  = Path.Combine(StartupPath, "autoc.exe");
            string c1 = Path.Combine(StartupPath, "fileico.ico");

            pai.Create
            (
                //Description of program/file type
                "fichier d'Auto Consultation ",
                new ProgramVerb
                (
                    //Verb name
                    "autoc",
                    //Path and arguments to use
                    c + " %0"
                )
            );

            //optional
            pai.DefaultIcon = new ProgramIcon(c1);
            //}
            //if (!pai1.Exists && Services.etat == 0)
            //{

            StartupPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Remove(0, 6);

            c  = Path.Combine(StartupPath, "autoc.exe");
            c1 = Path.Combine(StartupPath, "tarif.ico");
            pai1.Create
            (
                //Description of program/file type
                "ficher Tarif d'Auto Consultation ",
                new ProgramVerb
                (
                    //Verb name
                    "tarif",
                    //Path and arguments to use
                    c + " %0"
                )
            );

            //optional
            pai1.DefaultIcon = new ProgramIcon(c1);
            //}
            //if (!pai2.Exists && Services.etat == 0)
            //{

            StartupPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Remove(0, 6);

            c  = Path.Combine(StartupPath, "autoc.exe");
            c1 = Path.Combine(StartupPath, "acc.ico");
            pai2.Create
            (
                //Description of program/file type
                "ficher accessoire d'Auto Consultation ",
                new ProgramVerb
                (
                    //Verb name
                    "acc",
                    //Path and arguments to use
                    c + " %0"
                )
            );

            //optional
            pai2.DefaultIcon = new ProgramIcon(c1);
            //}
        }
コード例 #24
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (launchedtroughextension == true)
            {
            }
            else
            {
                FileAssociationInfo fai = new FileAssociationInfo(".zortosunzip");
                if (!fai.Exists)
                {
                    fai.Create("ZortosUnzipper");

                    //Specify MIME type (optional)
                    fai.ContentType = "application/zip";

                    //Programs automatically displayed in open with list
                    fai.OpenWithList = new string[]
                    { "explorer.exe" };
                }
                ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);
                if (!pai.Exists)
                {
                    pai.Create
                    (
                        //Description of program/file type
                        "ZortosExplorer Automaticly Unzips da file",

                        new ProgramVerb
                        (
                            //Verb name
                            "Open",
                            //Path and arguments to use
                            Path.GetTempPath() + "ZortosExplorer.exe" + " " + Application.ExecutablePath
                        )
                    );

                    //optional
                    pai.DefaultIcon = new ProgramIcon(Path.GetTempPath() + "ZortosExplorer.exe");
                }
            }

            string[] arguments        = Environment.GetCommandLineArgs();
            string   argumentinstring = string.Join(", ", arguments);

            if (argumentinstring.EndsWith(@".zortosunzip"))
            {
                MessageBox.Show("Unzipping Please Wait");
                using (var archive = ZipArchive.Open(argumentinstring.Substring(argumentinstring.IndexOf(',') + 1)))
                {
                    foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
                    {
                        entry.WriteToDirectory(Path.GetTempPath() + @"ZortosUnzipper", new ExtractionOptions()
                        {
                            ExtractFullPath = true,
                            Overwrite       = true
                        });
                    }
                }
                //ZipFile.ExtractToDirectory(argumentinstring.Substring(argumentinstring.IndexOf(',') + 1), Path.GetTempPath() + @"ZortosUnzipper");
                MessageBox.Show("Done File Extracted inside" + "\n" + Path.GetTempPath() + @"ZortosUnzipper");
                Dispose();
                Environment.Exit(0);
            }

            if (argumentinstring.EndsWith(@".zip"))
            {
                MessageBox.Show("Unzipping Please Wait");
                using (var archive = ZipArchive.Open(argumentinstring.Substring(argumentinstring.IndexOf(',') + 1)))
                {
                    foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
                    {
                        entry.WriteToDirectory(Path.GetTempPath() + @"ZortosUnzipper", new ExtractionOptions()
                        {
                            ExtractFullPath = true,
                            Overwrite       = true
                        });
                    }
                }
                //ZipFile.ExtractToDirectory(argumentinstring.Substring(argumentinstring.IndexOf(',') + 1), Path.GetTempPath() + @"ZortosUnzipper");
                MessageBox.Show("Done File Extracted inside" + "\n" + Path.GetTempPath() + @"ZortosUnzipper");
                Dispose();
                Environment.Exit(0);
            }
            if (argumentinstring.EndsWith(".7z"))
            {
                MessageBox.Show("Unzipping Please Wait");
                using (var archive = SevenZipArchive.Open(argumentinstring.Substring(argumentinstring.IndexOf(',') + 1)))
                {
                    foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
                    {
                        entry.WriteToDirectory(Path.GetTempPath() + @"ZortosUnzipper", new ExtractionOptions()
                        {
                            ExtractFullPath = true,
                            Overwrite       = true
                        });
                    }
                }
                MessageBox.Show("Done File Extracted inside" + "\n" + Path.GetTempPath() + @"ZortosUnzipper");
                Dispose();
                Environment.Exit(0);
            }
            if (argumentinstring.EndsWith(".rar"))
            {
                MessageBox.Show("Unzipping Please Wait");
                using (var archive = RarArchive.Open(argumentinstring.Substring(argumentinstring.IndexOf(',') + 1)))
                {
                    foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
                    {
                        entry.WriteToDirectory(Path.GetTempPath() + @"ZortosUnzipper", new ExtractionOptions()
                        {
                            ExtractFullPath = true,
                            Overwrite       = true
                        });
                    }
                }
                MessageBox.Show("Done File Extracted inside:" + "\n" + Path.GetTempPath() + @"ZortosUnzipper");
                Dispose();
                Environment.Exit(0);
            }
        }
コード例 #25
0
ファイル: QuickSetup.cs プロジェクト: zhtw2013/KeyKey
        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;
            }
        }
コード例 #26
0
        ///// <summary>
        /////     Sets the language
        ///// </summary>
        //public void SetLanguage()
        //{
        //    string languageFilePath = Path.Combine(Program.LanguagesDirectory,
        //        String.Format("{0}.json", Settings.Default.Language.Name));
        //    if (File.Exists(languageFilePath))
        //        _lp = Serializer.Deserialize<LocalizationProperties>(File.ReadAllText(languageFilePath));
        //    else
        //    {
        //        File.WriteAllBytes(Path.Combine(Program.LanguagesDirectory, "en.json"), Resources.en);
        //        Settings.Default.Language = new CultureInfo("en");
        //        Settings.Default.Save();
        //        Settings.Default.Reload();
        //        _lp = Serializer.Deserialize<LocalizationProperties>(File.ReadAllText(languageFilePath));
        //    }

        //    Text = _lp.ProductTitle;
        //    headerLabel.Text = _lp.ProductTitle;
        //    infoLabel.Text = _lp.MainDialogInfoText;

        //    sectionsListView.Groups[0].Header = _lp.MainDialogProjectsGroupText;
        //    sectionsListView.Groups[1].Header = _lp.MainDialogInformationGroupText;
        //    sectionsListView.Groups[2].Header = _lp.MainDialogPreferencesGroupText;

        //    sectionsListView.Items[0].Text = _lp.MainDialogNewProjectText;
        //    sectionsListView.Items[1].Text = _lp.MainDialogOpenProjectText;
        //    sectionsListView.Items[4].Text = _lp.MainDialogFeedbackText;
        //    sectionsListView.Items[5].Text = _lp.MainDialogPreferencesText;
        //    sectionsListView.Items[6].Text = _lp.MainDialogInformationText;
        //}

        private void MainDialog_Load(object sender, EventArgs e)
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                var dr = MessageBox.Show("Your operating system is not supported.", string.Empty,
                                         MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
                if (dr == DialogResult.OK)
                {
                    Application.Exit();
                }
            }

            try
            {
                var fai = new FileAssociationInfo(".nupdproj");
                if (!fai.Exists)
                {
                    fai.Create("nUpdate Administration");

                    var pai = new ProgramAssociationInfo(fai.ProgId);
                    if (!pai.Exists)
                    {
                        pai.Create("nUpdate Administration Project File",
                                   new ProgramVerb("Open", $"\"{Application.ExecutablePath} %1\""));
                        pai.DefaultIcon = new ProgramIcon(Application.ExecutablePath);
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                Popup.ShowPopup(this, SystemIcons.Warning, "Missing rights.",
                                "The registry entry for the extension (.nupdproj) couldn't be created. Without that file extension nUpdate Administration won't work correctly. Please make sure to start the administration with admin privileges the first time.",
                                PopupButtons.Ok);
            }

            if (string.IsNullOrWhiteSpace(Settings.Default.ProgramPath))
            {
                Settings.Default.ProgramPath =
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                 "nUpdate Administration");
            }
            Program.LanguagesDirectory = Path.Combine(Program.Path, "Localization");
            if (!Directory.Exists(Program.LanguagesDirectory))
            {
                Directory.CreateDirectory(Program.LanguagesDirectory); // Create the directory

                // Save the language content
                var lang    = new LocalizationProperties();
                var content = Serializer.Serialize(lang);
                File.WriteAllText(Path.Combine(Program.LanguagesDirectory, "en.json"), content);
            }

            if (!File.Exists(Program.ProjectsConfigFilePath))
            {
                using (File.Create(Program.ProjectsConfigFilePath))
                {
                }
            }

            if (!File.Exists(Program.StatisticServersFilePath))
            {
                using (File.Create(Program.StatisticServersFilePath))
                {
                }
            }

            var projectsPath = Path.Combine(Program.Path, "Projects");

            if (!Directory.Exists(projectsPath))
            {
                Directory.CreateDirectory(projectsPath);
            }

            //SetLanguage();
            sectionsListView.DoubleBuffer();
            Text             = string.Format(Text, Program.VersionString);
            headerLabel.Text = string.Format(Text, Program.VersionString);
        }
コード例 #27
0
        private void MergeSqlProjectFileChanges( )
        {
            // Actually not changed
            if (_options.SqlProjectFileAssociated == chkAssociateSqlProjectFiles.Checked)
            {
                return;
            }

            _options.SqlProjectFileAssociated = chkAssociateSqlProjectFiles.Checked;
            FileAssociationInfo    fa = null;
            ProgramAssociationInfo pa = null;

            if (chkAssociateSqlProjectFiles.Checked)
            {
                fa = new FileAssociationInfo(".sqlprj");

                // File association info exists. We have to backup current settings
                if (fa.Exists)
                {
                    //Backup open with list
                    _options.SqlProjectOpenWithBackup.AddRange(fa.OpenWithList);

                    //Backup verbs
                    pa = new ProgramAssociationInfo(fa.ProgID);
                    if (pa.Exists)
                    {
                        _options.SqlProjectVerbsBackup.AddRange(pa.Verbs);
                        _options.SqlProjectFileProgramIDBackup = pa.ProgID;
                    }
                }
                // File association info does not exists. We will create
                else
                {
                    fa.Create("PragmaSQL Project File");
                    pa = new ProgramAssociationInfo(fa.ProgID);
                }

                fa.OpenWithList = new string[1] {
                    "PragmaSQL.exe"
                };

                pa = new ProgramAssociationInfo(fa.ProgID);
                if (!pa.Exists)
                {
                    pa.Create();
                }
                if (pa != null && pa.Exists)
                {
                    ProgramVerb verb = new ProgramVerb("open", SystemFileAssociationOptions.PragmaSQLOpenCommand);
                    pa.Verbs = new ProgramVerb[1] {
                        verb
                    };
                }
            }
            else
            {
                // Rollback to backup
                fa = new FileAssociationInfo(".sqlprj");
                if (fa.Exists)
                {
                    fa.OpenWithList = _options.SqlProjectOpenWithBackup.ToArray();
                    _options.SqlProjectOpenWithBackup.Clear();

                    pa = new ProgramAssociationInfo(fa.ProgID);
                    if (pa.Exists)
                    {
                        pa.Delete();
                        if (!String.IsNullOrEmpty(_options.SqlProjectFileProgramIDBackup))
                        {
                            pa = new ProgramAssociationInfo(_options.SqlProjectFileProgramIDBackup);
                            if (!pa.Exists)
                            {
                                pa.Create();
                            }
                            pa.Verbs = _options.SqlProjectVerbsBackup.ToArray();
                        }
                        _options.SqlProjectVerbsBackup.Clear();
                    }
                }
            }
        }
コード例 #28
0
        private void SetFileAssociations()
        {
            //  CodeFile1.txt

            try
            {
                //throw new Exception("Try Exception.");


                string sDocArc_ProgId = "DocArchiver.DocMarkReader";

                {
                    //FileAssociationInfo fai = new FileAssociationInfo(".bob");
                    //FileAssociationInfo fai = new FileAssociationInfo(".TryExt_2");
                    FileAssociationInfo fai = new FileAssociationInfo(".arcPdf");
                    if (fai.Exists)
                    {
                        fai.Delete();
                    }

                    //if (!(fai.Exists))
                    {
                        //fai.Create("MyProgramName");
                        //fai.Create("TryExt_2_FileManager_ProgId");
                        fai.Create(sDocArc_ProgId);


                        //Specify MIME type (optional)
                        //fai.ContentType = "application/myfile";
                        fai.ContentType = "DocArchiver/arcPdf_File";



                        //Programs automatically displayed in open with list
                        //fai.OpenWithList = new string[] { "notepad.exe", "wordpad.exe", "someotherapp.exe" };
                        //fai.OpenWithList = new string[] { "TryExt_FileManager.exe" };
                        fai.OpenWithList = new string[] { "DocMarkReader.exe" };
                    }
                }



                {
                    //FileAssociationInfo fai = new FileAssociationInfo(".bob");
                    //FileAssociationInfo fai = new FileAssociationInfo(".TryExt_2");
                    FileAssociationInfo fai = new FileAssociationInfo(".corPdf");
                    if (fai.Exists)
                    {
                        fai.Delete();
                    }

                    //if (!(fai.Exists))
                    {
                        //fai.Create("MyProgramName");
                        //fai.Create("TryExt_2_FileManager_ProgId");
                        //fai.Create(sDocArc_ProgId);
                        fai.Create("AcroExch.Document");


                        //Specify MIME type (optional)
                        //fai.ContentType = "application/myfile";
                        //fai.ContentType = "DocArchiver/arcPdf_File";
                        fai.ContentType = "application/pdf";



                        //Programs automatically displayed in open with list
                        //fai.OpenWithList = new string[] { "notepad.exe", "wordpad.exe", "someotherapp.exe" };
                        //fai.OpenWithList = new string[] { "TryExt_FileManager.exe" };
                        fai.OpenWithList = new string[] { "AcroRd32.exe" };
                    }
                }



                //////////////////////////////////////////////////

                {
                    //ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);
                    ProgramAssociationInfo pai = new ProgramAssociationInfo(sDocArc_ProgId);

                    if (pai.Exists)
                    {
                        pai.Delete();
                    }


                    //if (!(pai.Exists))
                    {
                        pai.Create
                        (
                            //Description of program/file type
                            "DocArchiver's File Type",

                            new ProgramVerb
                            (
                                //Verb name
                                "Open",
                                //Path and arguments to use
                                //@"C:\SomePath\MyApp.exe %1"
                                @"E:\HthmWork\Projects\VS-2010\DocArchiver\DocMarkReader\bin\Debug\DocMarkReader.exe %1"
                            )
                        );

                        //optional
                        //pai.DefaultIcon = new ProgramIcon(@"C:\SomePath\SomeIcon.ico");
                        pai.DefaultIcon = new ProgramIcon(
                            //pai.Se.setde DefaultIcon = new ProgramIcon(
                            @"E:\HthmWork\Projects\VS-2010\DocArchiver\DocMarkReader\Icon1.ico");
                    }
                }



                MessageBox.Show("Success !");
            }
            catch
            {
                MessageBox.Show("Error!.. Probabliy security problem.\r\n\r\n" +
                                "Try to right click the application, and run it as administrator");
            }
        }
コード例 #29
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);
                            }
                        }
                    }
                }
            }
        }
コード例 #30
0
        private void MergeChanges( )
        {
            FileAssociationInfo    fa = null;
            ProgramAssociationInfo pa = null;

            // 1- Add new associations and backup current settings
            foreach (string ext in _addBuffer)
            {
                if (_options.Associations.ContainsKey(ext))
                {
                    continue;
                }

                // 1.1 Add association
                _options.Associations.Add(ext, ext);

                // 1.2 Open with backup
                fa = new FileAssociationInfo(ext);
                if (fa == null || !fa.Exists)
                {
                    continue;
                }

                _options.OpenWithBackup.Add(ext, fa.OpenWithList);

                // 1.3 Verb nackup
                pa = new ProgramAssociationInfo(fa.ProgID);
                if (pa == null || !pa.Exists)
                {
                    continue;
                }
                _options.VerbsBackup.Add(ext, pa.Verbs);
            }

            //2- Remove associations and restore backed up settings
            string[]      backedUpOpenWithList = null;
            ProgramVerb[] backedUpVerbs        = null;

            foreach (string ext in _removeBuffer)
            {
                if (!_options.OpenWithBackup.ContainsKey(ext))
                {
                    continue;
                }

                // 2.1 Rollback to backed up open with list
                fa = new FileAssociationInfo(ext);
                if (fa == null || !fa.Exists)
                {
                    continue;
                }
                backedUpOpenWithList = _options.OpenWithBackup[ext];
                fa.OpenWithList      = backedUpOpenWithList;

                //2.2 Rollback to backed up verbs
                pa = new ProgramAssociationInfo(fa.ProgID);
                if (pa == null || !pa.Exists)
                {
                    continue;
                }

                backedUpVerbs = _options.VerbsBackup[ext];
                pa.Verbs      = backedUpVerbs;

                _options.Associations.Remove(ext);
                _options.OpenWithBackup.Remove(ext);
                _options.VerbsBackup.Remove(ext);
            }


            //3- Apply verbs and open with list
            foreach (string ext in _options.Associations.Keys)
            {
                // 3.1 Apply open with
                fa = new FileAssociationInfo(ext);
                if (fa == null || !fa.Exists)
                {
                    continue;
                }
                fa.OpenWithList = new string[1] {
                    "PragmaSQL.exe"
                };


                // 3.2 Apply verbs
                pa = new ProgramAssociationInfo(fa.ProgID);
                if (pa == null || !pa.Exists)
                {
                    continue;
                }
                ProgramVerb verb = new ProgramVerb("open", SystemFileAssociationOptions.PragmaSQLOpenCommand);
                pa.Verbs = new ProgramVerb[1] {
                    verb
                };
            }
        }