예제 #1
0
        public static void Unregister()
        {
            foreach (MethodInfo methodInfo in GetShellExtensionMethods())
            {
                ChoShellExtensionContextMenuAttribute attr = methodInfo.GetCustomAttribute <ChoShellExtensionContextMenuAttribute>();
                if (attr == null)
                {
                    continue;
                }

                string methodName   = methodInfo.Name;
                string fileType     = attr.FileType;
                string shellKeyName = attr.ShellKeyName;

                shellKeyName = shellKeyName.IsNullOrWhiteSpace() ? methodName : shellKeyName;

                ChoShellExtension.Unregister(fileType, shellKeyName);
                ChoTrace.WriteLine("Shell Extensions unregistered successfully.");
            }
        }
예제 #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.");
            }
        }