コード例 #1
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");*/
        }
コード例 #2
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();
                    }
                }
            }
        }
コード例 #3
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;
            }
        }
コード例 #4
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 !");
        }
コード例 #5
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");
            }
        }