Пример #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));
        }
Пример #2
0
        public static void RunAsAdmin()
        {
            if (!IsRunAsAdmin())
            {
                ProcessStartInfo proc = new ProcessStartInfo();
                proc.UseShellExecute  = true;
                proc.WorkingDirectory = Environment.CurrentDirectory;
                proc.FileName         = Assembly.GetEntryAssembly().CodeBase;

                foreach (string arg in Environment.GetCommandLineArgs())
                {
                    proc.Arguments += String.Format("\"{0}\" ", arg);
                }

                proc.Verb = "runas";

                try
                {
                    Process.Start(proc);
                    Environment.Exit(0);
                }
                catch (Exception ex)
                {
                    ChoTrace.WriteLine("This application requires elevated credentials in order to operate correctly! {0}".FormatString(ex.Message));
                }
            }
        }
Пример #3
0
        protected override void OnStart(string[] args)
        {
            _defaultBalloonTipText = "{0} is running...".FormatString(ChoGlobalApplicationSettings.Me.ApplicationName);

            try
            {
                ChoShellExtension.Register();
                ChoTrace.WriteLine("Shell Extensions registered successfully.");
            }
            catch (Exception ex)
            {
                ChoTrace.WriteLine("Failed to register Shell Extensions. {0}".FormatString(ex.Message));
            }
            try
            {
                ChoShellFileAssociation.Register();
                ChoTrace.WriteLine("File Associations registered successfully.");
            }
            catch (Exception ex)
            {
                ChoTrace.WriteLine("Failed to register File Associations. {0}".FormatString(ex.Message));
            }

            if (ChoApplication.ApplicationMode == ChoApplicationMode.Console)
            {
                ChoAppCmdLineArgs cmdLineArgs = new ChoAppCmdLineArgs();
                cmdLineArgs.StartFileCopy();
            }
            base.OnStart(args);
        }
Пример #4
0
        protected override void OnAfterCommandLineArgObjectLoaded(string[] commandLineArgs)
        {
            ChoShellExtensionActionMode?sem = GetShellExtensionActionMode();

            if (DisplayAvailProperties || DisplayAvailTypeParsersNFormatters)
            {
                if (DisplayAvailProperties)
                {
                    ChoApplication.DisplayMsg(ChoPropertyManagerSettings.Me.GetHelpText(), null, ConsoleColor.Yellow);
                }
                if (DisplayAvailTypeParsersNFormatters)
                {
                    ChoApplication.DisplayMsg(ChoTypesManager.GetHelpText(), null, ConsoleColor.Green);
                }
                if (!ConfigObjectTypeName.IsNullOrWhiteSpace())
                {
                    ChoApplication.DisplayMsg(ChoConfigurationManager.GetHelpText(ChoType.GetType(ConfigObjectTypeName)), null, ConsoleColor.Green);
                }
                Environment.Exit(0);
            }
            else if (!ConfigObjectTypeName.IsNullOrWhiteSpace())
            {
                ChoApplication.DisplayMsg(ChoConfigurationManager.GetHelpText(ChoType.GetType(ConfigObjectTypeName)), null, ConsoleColor.Green);
                Environment.Exit(0);
            }
            else if (sem != null)
            {
                if (sem.Value == ChoShellExtensionActionMode.Register)
                {
                    ChoShellExtension.Register();
                    ChoTrace.WriteLine("Shell Extensions registered successfully.");

                    ChoShellFileAssociation.Register();
                    ChoTrace.WriteLine("File Associations registered successfully.");

                    Environment.Exit(0);
                }
                else if (sem.Value == ChoShellExtensionActionMode.Unregister)
                {
                    ChoShellExtension.Unregister();
                    ChoTrace.WriteLine("Shell Extensions unregistered successfully.");

                    ChoShellFileAssociation.Unregister();
                    ChoTrace.WriteLine("File Associations unregistered successfully.");

                    Environment.Exit(0);
                }
            }

            if (ChoShellExtension.ExecuteShellExtensionMethodIfAnySpecified(commandLineArgs))
            {
                ChoTrace.WriteLine("Shell Extension ran successfully.");
                Environment.Exit(0);
            }

            base.OnAfterCommandLineArgObjectLoaded(commandLineArgs);
        }
Пример #5
0
        private void Start()
        {
            if (_minWorkerThreads >= _maxWorkerThreads)
            {
                throw new ChoThreadPoolException("MinWorkerThread should be less than MaxWorkerThreads.");
            }

            //ChoStreamProfile.WriteLine(ChoReservedDirectoryName.Settings, String.Format("{0}_{1}", Name, GetType().Name), ToString(), true);
            ChoTrace.WriteLine(String.Format("Starting `{2}` Threadpool with Min ({0}) - Max ({1}) threads.",
                                             _minWorkerThreads, _maxWorkerThreads, _name));

            StartThreads(_minWorkerThreads);
        }
Пример #6
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.");
            }
        }
Пример #7
0
 public static void UnregisterShellExtensions()
 {
     try
     {
         ChoShellExtension.Unregister();
         ChoTrace.WriteLine("Shell Extensions unregistered successfully.");
     }
     catch (Exception ex)
     {
         ChoTrace.WriteLine("Failed to unregister Shell Extensions. {0}".FormatString(ex.Message));
     }
     try
     {
         ChoShellFileAssociation.Unregister();
         ChoTrace.WriteLine("File Associations unregistered successfully.");
     }
     catch (Exception ex)
     {
         ChoTrace.WriteLine("Failed to unregister File Associations. {0}".FormatString(ex.Message));
     }
 }
Пример #8
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.");
            }
        }