Exemple #1
0
        public void Register()
        {
            if (DefaultIcon.IsNullOrWhiteSpace())
            {
                DefaultIcon = "{0},{1}".FormatString(ChoPath.ToShortFileName(ChoApplication.EntryAssemblyLocation), DefaultIconIndex);
            }

            Registry.ClassesRoot.CreateSubKey(Extension, RegistryKeyPermissionCheck.ReadWriteSubTree).SetValue("", ProgID);

            if (!ProgID.IsNullOrWhiteSpace())
            {
                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(ProgID))
                {
                    if (Description != null)
                    {
                        key.SetValue("", Description);
                    }
                    if (DefaultIcon != null)
                    {
                        key.CreateSubKey("DefaultIcon").SetValue("", DefaultIcon);
                    }
                    if (Application != null)
                    {
                        key.CreateSubKey(@"Shell\Open\Command").SetValue("",
                                                                         "{0} {1}\"%1\" {2}".FormatString(Application, DefaultArgSwitch, AdditionalArguments));
                    }
                }
            }
        }
Exemple #2
0
        public static void Register()
        {
            foreach (MethodInfo methodInfo in GetShellExtensionMethods())
            {
                ChoShellExtensionContextMenuAttribute attr = methodInfo.GetCustomAttribute <ChoShellExtensionContextMenuAttribute>();
                if (attr == null)
                {
                    continue;
                }

                string        methodName            = methodInfo.Name;
                string        fileType              = attr.FileType;
                string        menuText              = attr.MenuText;
                string        shellKeyName          = attr.ShellKeyName;
                string        icon                  = attr.Icon;
                StringBuilder additionalCmdLineArgs = new StringBuilder();

                foreach (string addCmdLineArg in attr.AdditionalCommandLineArgs.NSplit('%', false))
                {
                    if (addCmdLineArg.StartsWith("%") && addCmdLineArg.EndsWith("%") &&
                        !addCmdLineArg.StartsWith("%%") && !addCmdLineArg.EndsWith("%%"))
                    {
                        additionalCmdLineArgs.AppendFormat(@"%{0}%", addCmdLineArg);
                    }
                    else
                    {
                        additionalCmdLineArgs.AppendFormat(@"{0}", addCmdLineArg);
                    }
                }

                string z = additionalCmdLineArgs.ToString();
                additionalCmdLineArgs.Clear();
                foreach (string addCmdLineArg in z.SplitNTrim())
                {
                    //if (addCmdLineArg.StartsWith("%") && addCmdLineArg.EndsWith("%")
                    //    && !addCmdLineArg.StartsWith("%%") && !addCmdLineArg.EndsWith("%%"))
                    //    additionalCmdLineArgs.AppendFormat(@" ""%{0}%""", addCmdLineArg);
                    //else
                    additionalCmdLineArgs.AppendFormat(@" ""{0}""", addCmdLineArg);
                }
                string menuCommand = string.Format("\"{0}\" {3}{1}{3} {2} {4}\"%1\"", ChoPath.ToShortFileName(ChoApplication.EntryAssemblyLocation), methodName, additionalCmdLineArgs, SHELL_EXT_CMD_DELIMITER,
                                                   attr.DefaultArgPrefix);

                menuText     = menuText.IsNullOrWhiteSpace() ? methodName : menuText;
                shellKeyName = shellKeyName.IsNullOrWhiteSpace() ? methodName : shellKeyName;
                if (icon.IsNullOrWhiteSpace())
                {
                    if (attr.IconResourceFilePath.IsNullOrWhiteSpace())
                    {
                        icon = "{0},{1}".FormatString(ChoPath.ToShortName(ChoApplication.EntryAssemblyLocation), attr.IconIndex);
                    }
                    else
                    {
                        icon = "{0},{1}".FormatString(ChoPath.ToShortName(attr.IconResourceFilePath), attr.IconIndex);
                    }
                }

                ChoShellExtension.Register(fileType, shellKeyName, menuText, menuCommand, icon);
                ChoTrace.WriteLine("Shell Extensions registered successfully.");
            }
        }