Example #1
0
        private static void ExecuteShellExtensionMethod(string command, string[] args)
        {
            ChoEnvironment.CommandLineArgs = args;
            foreach (MethodInfo methodInfo in GetShellExtensionMethods())
            {
                ChoShellExtensionContextMenuAttribute attr = methodInfo.GetCustomAttribute <ChoShellExtensionContextMenuAttribute>();
                if (attr == null)
                {
                    continue;
                }
                if (methodInfo.Name == command)
                {
                    try
                    {
                        methodInfo.Invoke(null, new object[] { args });
                    }
                    catch (Exception ex)
                    {
                        ChoTrace.WriteLine("Error while executing '{0}' shell extension command. \n {1}".FormatString(command, ChoApplicationException.ToString(ex)));
                        ChoApplication.WriteToEventLog("Error while executing '{0}' shell extension command. \n {1}".FormatString(command, ChoApplicationException.ToString(ex)));
                    }

                    return;
                }
            }

            ChoApplication.WriteToEventLog("'{0}' shell extension command not found.".FormatString(command));
        }
Example #2
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.");
            }
        }
Example #3
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.");
            }
        }