Example #1
0
        public int Run(string[] args)
        {
            try
            {
                var settings = new ShowOrStartSettings(args);
                if (settings.HasErrors)
                {
                    _herald.ShowHelp(settings.ErrorMessage);
                    return(EXIT_ERROR);
                }

                if (settings.IsRequestingInfo)
                {
                    ProvideInfo(settings);
                    return(EXIT_OK);
                }

                Process proc   = FindProcess(settings.NameOrTitle);
                IntPtr  handle = (proc != null) ? proc.MainWindowHandle : IntPtr.Zero;

                if (!ShowedOrStarted(handle, settings))
                {
                    _herald.ShowHelp(string.Format("'{0}' was not found and no command was specified", settings.NameOrTitle));
                    return(EXIT_ERROR);
                }
                return(EXIT_OK);
            }
            catch (Exception ex)
            {
                _herald.ShowErrorMessage("UNEXPECTED ERROR: {0}", ex.Message);
                return(EXIT_ERROR);
            }
        }
Example #2
0
        public int Run(string[] args)
        {
            try
            {
                var settings = new ShowOrStartSettings(args);
                if (settings.HasErrors)
                {
                    _herald.ShowHelp(settings.ErrorMessage);
                    return EXIT_ERROR;
                }

                if (settings.IsRequestingInfo)
                {
                    ProvideInfo(settings);
                    return EXIT_OK;
                }

                Process proc = FindProcess(settings.NameOrTitle);
                IntPtr handle = (proc != null) ? proc.MainWindowHandle : IntPtr.Zero;

                if (!ShowedOrStarted(handle, settings))
                {
                    _herald.ShowHelp(string.Format("'{0}' was not found and no command was specified", settings.NameOrTitle));
                    return EXIT_ERROR;
                }
                return EXIT_OK;
            }
            catch (Exception ex)
            {
                _herald.ShowErrorMessage("UNEXPECTED ERROR: {0}", ex.Message);
                return EXIT_ERROR;
            }
        }
Example #3
0
 void ProvideInfo(ShowOrStartSettings settings)
 {
     if (settings.InfoRequestedType == InfoRequestType.Help)
     {
         _herald.ShowHelp();
     }
     else if (settings.InfoRequestedType == InfoRequestType.ProcessList)
     {
         _herald.ShowWindowedProcessList();
     }
     else if (settings.InfoRequestedType == InfoRequestType.Version)
     {
         _herald.ShowBanner();
     }
 }
Example #4
0
        bool ShowedOrStarted(IntPtr handle, ShowOrStartSettings settings)
        {
            if (handle != IntPtr.Zero)
            {
                if (WindowHelper.IsMinimized(handle))
                {
                    WindowHelper.Restore(handle);
                }
            }
            else if (!string.IsNullOrEmpty(settings.Command))
            {
                Process p = Process.Start(settings.Command, settings.CommandArgs);
                handle = p.MainWindowHandle;
            }
            if (handle == IntPtr.Zero)
            {
                return(false);
            }

            WindowHelper.MoveToForeground(handle);
            return(true);
        }
Example #5
0
 void ProvideInfo(ShowOrStartSettings settings)
 {
     if (settings.InfoRequestedType == InfoRequestType.Help)
         _herald.ShowHelp();
     else if (settings.InfoRequestedType == InfoRequestType.ProcessList)
         _herald.ShowWindowedProcessList();
     else if (settings.InfoRequestedType == InfoRequestType.Version)
         _herald.ShowBanner();
 }
Example #6
0
        bool ShowedOrStarted(IntPtr handle, ShowOrStartSettings settings)
        {
            if (handle != IntPtr.Zero)
            {
                if (WindowHelper.IsMinimized(handle))
                    WindowHelper.Restore(handle);
            }
            else if (!string.IsNullOrEmpty(settings.Command))
            {
                Process p = Process.Start(settings.Command, settings.CommandArgs);
                handle = p.MainWindowHandle;
            }
            if (handle == IntPtr.Zero)
                return false;

            WindowHelper.MoveToForeground(handle);
            return true;
        }