Esempio n. 1
0
        internal static Process GetParentProcess(Process process)
        {
            int     pid              = process.Id;
            Process parentProc       = null;
            IntPtr  handleToSnapshot = IntPtr.Zero;

            try
            {
                NM.ProcessEntry32 procEntry = new NM.ProcessEntry32();
                procEntry.dwSize = (uint)Marshal.SizeOf(typeof(NM.ProcessEntry32));
                handleToSnapshot = NM.CreateToolhelp32Snapshot(NM.ToolHelpCreateSnapshotFlags.Process, 0);
                if (NM.Process32First(handleToSnapshot, ref procEntry))
                {
                    do
                    {
                        if (pid == procEntry.th32ProcessID)
                        {
                            parentProc = Process.GetProcessById((int)procEntry.th32ParentProcessID);
                            break;
                        }
                    }while (NM.Process32Next(handleToSnapshot, ref procEntry));
                }
                else
                {
                    throw GUI.ApeException("Failed with win32 error code " + Marshal.GetLastWin32Error().ToString());
                }
            }
            finally
            {
                NM.CloseHandle(handleToSnapshot);
            }
            return(parentProc);
        }
Esempio n. 2
0
        private void frmViewPort_Shown(Object sender, EventArgs e)
        {
            base.AppbarNew(AppBarEdges.Top);

            if (!NM.RegisterHotKey(this.Handle, 1, 0, NM.VK_PAUSE))
            {
                throw GUI.ApeException("Failed to register hotkey");
            }

            ProcessStartInfo AppStartup = new ProcessStartInfo();

            AppStartup.FileName         = "APE.Watcher.exe";
            AppStartup.Arguments        = Process.GetCurrentProcess().Id.ToString() + " " + ((uint)SystemInformation.DoubleClickTime).ToString();
            AppStartup.WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Process.Start(AppStartup);

            DoubleClickTimer = (uint)SystemInformation.DoubleClickTime;
        }
Esempio n. 3
0
        private void Break()
        {
            // Restore the double click time if need be
            if (SystemInformation.DoubleClickTime == 1)
            {
                NM.SetDoubleClickTime(DoubleClickTimer);
            }

            if (Debugger.IsAttached)
            {
                Process CurrentProcess = Process.GetCurrentProcess();
                Process VisualStudio   = GetParentProcess(CurrentProcess);
                if (VisualStudio.ProcessName.ToLower() == "msvsmon")
                {
                    VisualStudio = GetParentProcess(VisualStudio);
                }

                if (VisualStudio.ProcessName.ToLower() == "devenv" && VisualStudio.MainWindowHandle != IntPtr.Zero)
                {
                    if (!NM.SetForegroundWindow(VisualStudio.MainWindowHandle))
                    {
                        throw GUI.ApeException("SetForegroundWindow VisualStudio failed");
                    }

                    NM.keybd_event(NM.VK_CONTROL, 0x1d, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                    NM.keybd_event(NM.VK_MENU, 0x38, NM.KEYEVENTF_KEYDOWN, UIntPtr.Zero);
                    NM.keybd_event(NM.VK_CANCEL, 0x46, NM.KEYEVENTF_KEYDOWN | NM.KEYEVENTF_EXTENDEDKEY, UIntPtr.Zero);
                    NM.keybd_event(NM.VK_CANCEL, 0x46, NM.KEYEVENTF_KEYUP | NM.KEYEVENTF_EXTENDEDKEY, UIntPtr.Zero);
                    NM.keybd_event(NM.VK_MENU, 0x38, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                    NM.keybd_event(NM.VK_CONTROL, 0x1d, NM.KEYEVENTF_KEYUP, UIntPtr.Zero);
                }
                else
                {
                    Debugger.Launch();
                }
            }
            else
            {
                Debugger.Launch();
            }
        }
Esempio n. 4
0
        internal void AppendToLog(string text, LogItemType type)
        {
            if (InvokeRequired)
            {
                if (AppendToLogDelegater == null)
                {
                    AppendToLogDelegater = new AppendToLogDelegate(AppendToLog);
                }
                Invoke(AppendToLogDelegater, new object[] { text, type });
            }
            else
            {
                Color colText;
                // TODO let the user configure the colours
                switch (type)
                {
                case LogItemType.Action:
                    colText = Color.Black;
                    break;

                case LogItemType.Start:
                    colText = Color.Turquoise;
                    break;

                case LogItemType.Finish:
                    colText = Color.Brown;
                    break;

                case LogItemType.Pass:
                    colText = Color.Green;
                    break;

                case LogItemType.Fail:
                    colText = Color.Red;
                    break;

                case LogItemType.Disabled:
                    colText = Color.LightGray;
                    break;

                case LogItemType.NA:
                    colText = Color.Purple;
                    break;

                case LogItemType.Debug:
                    colText = Color.SlateGray;
                    break;

                case LogItemType.Information:
                    colText = Color.Navy;
                    break;

                case LogItemType.Warning:
                    colText = Color.LightPink;
                    break;

                case LogItemType.Error:
                    colText = Color.DeepPink;
                    break;

                default:
                    throw GUI.ApeException("Implement support for LogItemType." + type.ToString());
                }

                string TextToAdd;

                Lines += 1;

                if (Lines == 1)
                {
                    TextToAdd = text;
                }
                else
                {
                    TextToAdd = "\n" + text;
                }

                // Append the line and set its colour to be correct
                int TextLengthBeforeAppend = rtbLogViewer.TextLength;
                rtbLogViewer.AppendText(TextToAdd);
                rtbLogViewer.SelectionStart  = TextLengthBeforeAppend;
                rtbLogViewer.SelectionLength = TextToAdd.Length;
                rtbLogViewer.SelectionColor  = colText;
                rtbLogViewer.ScrollToCaret();

                // If we have more than 40 lines
                if (Lines > 40)
                {
                    // Remove the first line currently in the rich text box
                    rtbLogViewer.SelectionStart  = 0;
                    rtbLogViewer.SelectionLength = rtbLogViewer.Text.IndexOf('\n') + 1;
                    rtbLogViewer.ReadOnly        = false;
                    rtbLogViewer.SelectedText    = "";
                    rtbLogViewer.ReadOnly        = true;
                    Lines -= 1;
                    rtbLogViewer.SelectionStart = rtbLogViewer.TextLength;
                }
            }
        }