Beispiel #1
0
 private static void OnWindowOpened(object sender, AutomationEventArgs automationEventArgs)
 {
     try
     {
         var element = sender as AutomationElement;
         if (element != null)
         {
             if (element.Current.Name.Trim() == "Editor for A Hat in Time (64-bit, DX9, Cooked Editor, PMT)")
             {
                 if (Benchmark != null)
                 {
                     Benchmark.Stop();
                 }
                 Meme.StopElevatorMusic();
             }
             else if (element.Current.Name.Trim() == "Editor for A Hat in Time (64-bit, DX9)")
             {
                 Meme.PlayElevatorMusic();
             }
         }
     }
     catch (ElementNotAvailableException)
     {
     }
 }
Beispiel #2
0
 private void mButton3_Click(object sender, System.EventArgs e)
 {
     Runner.KillAllWorkers();
     Utils.KillEditor();
     Meme.StopElevatorMusic();
     if (!Program.Uploader.IsUploaderRunning)
     {
         ToggleConsole(false);
     }
 }
        private bool RunApp(string exe, string[] args, string cwd = ".", string taskName = "", Action o = null, bool cleanConsole = true)
        {
            this.Invoke(new MethodInvoker(() =>
            {
                if (cleanConsole)
                {
                    textBox1.Clear();
                }
                Log(taskName, LogLevel.Verbose);
            }));

            NamedPipe mLogPipe;
            Thread    mOutputThread = null;

            AppRun?.Invoke();

            SetText(taskName);

            Process process = new Process();

            process.StartInfo.FileName               = exe;
            process.StartInfo.Arguments              = string.Join(" ", args);
            process.StartInfo.WorkingDirectory       = cwd;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.CreateNoWindow         = true;
            process.StartInfo.RedirectStandardError  = false;
            process.StartInfo.RedirectStandardOutput = false;
            process.StartInfo.RedirectStandardInput  = true;
            process.EnableRaisingEvents              = true;

            process.Start();
            runningProcesses.Add(process);
            SetText(taskName);


            mLogPipe = new NamedPipe();
            if (mLogPipe.Connect(process))
            {
                if (mOutputThread != null && mOutputThread.IsAlive)
                {
                    mOutputThread.Abort();
                }
                mOutputThread = new Thread(() => {
                    Debug.WriteLine("Pipe open");
                    try
                    {
                        var level = LogLevel.Info;
                        while (process != null && !process.HasExited)
                        {
                            string text = mLogPipe.Read();
                            //Debug.WriteLine(text);

                            if (text.StartsWith("`~[~`")) // control code
                            {
                                var raw  = text.Split('`');
                                var code = raw[raw.Length - 1].Trim();

                                switch (code)
                                {
                                case "Reset":
                                    level = LogLevel.Info;
                                    break;

                                case "1111":
                                    level = LogLevel.Info;
                                    break;

                                case "1101":
                                    level = LogLevel.Warn;
                                    break;

                                case "1001":
                                    level = LogLevel.Error;
                                    break;

                                case "0101":
                                    level = LogLevel.Success;
                                    break;

                                default:
                                    Debug.WriteLine("Code not implemented: " + code);
                                    break;
                                }
                            }
                            else if (text.Length > 0)
                            {
                                Log(text.Replace("\r\n", ""), level);
                            }
                        }
                    }
                    catch (ThreadAbortException)
                    {
                    }
                    catch (Exception)
                    {
                    }
                    Debug.WriteLine("Pipe close");
                    Log("Process exited with exit code: " + process.ExitCode, process.ExitCode != 0 ? LogLevel.Warn : LogLevel.Verbose);
                });
                mOutputThread.Start();
            }

            while (!process.HasExited && !isCancelling)
            {
                Thread.Sleep(300);
            }

            Meme.StopElevatorMusic();

            if (runningProcesses.Contains(process))
            {
                runningProcesses.Remove(process);
            }

            this.Invoke(new MethodInvoker(() =>
            {
                if (runningProcesses.Count == 0)
                {
                    mButton3.Visible = false;
                }
            }));

            AppClose?.Invoke(process.ExitCode);

            if (runningProcesses.Count == 0)
            {
                SetText(null);
            }

            this.Invoke(new MethodInvoker(() =>
            {
                MainWindow.Instance.ToggleConsole(false);
            }));

            return(process.ExitCode == 0);
        }