forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
165 lines (146 loc) · 4.44 KB
/
Program.cs
File metadata and controls
165 lines (146 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Decompiled with JetBrains decompiler
// Type: UnityEditor.Utils.Program
// Assembly: UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 01B28312-B6F5-4E06-90F6-BE297B711E41
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEditor.dll
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace UnityEditor.Utils
{
internal class Program : IDisposable
{
private ProcessOutputStreamReader _stdout;
private ProcessOutputStreamReader _stderr;
private Stream _stdin;
public Process _process;
public bool HasExited
{
get
{
if (this._process == null)
throw new InvalidOperationException("You cannot call HasExited before calling Start");
try
{
return this._process.HasExited;
}
catch (InvalidOperationException ex)
{
return true;
}
}
}
public int ExitCode
{
get
{
return this._process.ExitCode;
}
}
public int Id
{
get
{
return this._process.Id;
}
}
protected Program()
{
this._process = new Process();
}
public Program(ProcessStartInfo si)
: this()
{
this._process.StartInfo = si;
}
public void Start()
{
this._process.StartInfo.RedirectStandardInput = true;
this._process.StartInfo.RedirectStandardError = true;
this._process.StartInfo.RedirectStandardOutput = true;
this._process.StartInfo.UseShellExecute = false;
this._process.Start();
this._stdout = new ProcessOutputStreamReader(this._process, this._process.StandardOutput);
this._stderr = new ProcessOutputStreamReader(this._process, this._process.StandardError);
this._stdin = this._process.StandardInput.BaseStream;
}
public ProcessStartInfo GetProcessStartInfo()
{
return this._process.StartInfo;
}
public void LogProcessStartInfo()
{
if (this._process != null)
Program.LogProcessStartInfo(this._process.StartInfo);
else
Console.WriteLine("Failed to retrieve process startInfo");
}
private static void LogProcessStartInfo(ProcessStartInfo si)
{
Console.WriteLine("Filename: " + si.FileName);
Console.WriteLine("Arguments: " + si.Arguments);
foreach (DictionaryEntry environmentVariable in si.EnvironmentVariables)
{
if (environmentVariable.Key.ToString().StartsWith("MONO"))
Console.WriteLine("{0}: {1}", environmentVariable.Key, environmentVariable.Value);
}
int startIndex = si.Arguments.IndexOf("Temp/UnityTempFile");
Console.WriteLine("index: " + (object) startIndex);
if (startIndex <= 0)
return;
string path = si.Arguments.Substring(startIndex);
Console.WriteLine("Responsefile: " + path + " Contents: ");
Console.WriteLine(File.ReadAllText(path));
}
public string GetAllOutput()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("stdout:");
foreach (string str in this.GetStandardOutput())
stringBuilder.AppendLine(str);
stringBuilder.AppendLine("stderr:");
foreach (string str in this.GetErrorOutput())
stringBuilder.AppendLine(str);
return stringBuilder.ToString();
}
public void Dispose()
{
if (!this.HasExited)
{
this._process.Kill();
this._process.WaitForExit();
}
this._process.Dispose();
}
public Stream GetStandardInput()
{
return this._stdin;
}
public string[] GetStandardOutput()
{
return this._stdout.GetOutput();
}
public string GetStandardOutputAsString()
{
string[] standardOutput = this.GetStandardOutput();
StringBuilder stringBuilder = new StringBuilder(string.Empty);
foreach (string str in standardOutput)
stringBuilder.AppendLine(str);
return stringBuilder.ToString();
}
public string[] GetErrorOutput()
{
return this._stderr.GetOutput();
}
public void WaitForExit()
{
this._process.WaitForExit();
}
public bool WaitForExit(int milliseconds)
{
return this._process.WaitForExit(milliseconds);
}
}
}