forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
222 lines (197 loc) · 4.65 KB
/
Program.cs
File metadata and controls
222 lines (197 loc) · 4.65 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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");
}
bool result;
try
{
result = this._process.HasExited;
}
catch (InvalidOperationException)
{
result = true;
}
return result;
}
}
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.Start(null);
}
public void Start(EventHandler exitCallback)
{
if (exitCallback != null)
{
this._process.EnableRaisingEvents = true;
this._process.Exited += exitCallback;
}
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);
IEnumerator enumerator = si.EnvironmentVariables.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator.Current;
if (dictionaryEntry.Key.ToString().StartsWith("MONO"))
{
Console.WriteLine("{0}: {1}", dictionaryEntry.Key, dictionaryEntry.Value);
}
}
}
finally
{
IDisposable disposable;
if ((disposable = (enumerator as IDisposable)) != null)
{
disposable.Dispose();
}
}
int num = si.Arguments.IndexOf("Temp/UnityTempFile");
Console.WriteLine("index: " + num);
if (num > 0)
{
string text = si.Arguments.Substring(num);
Console.WriteLine("Responsefile: " + text + " Contents: ");
Console.WriteLine(File.ReadAllText(text));
}
}
public string GetAllOutput()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("stdout:");
string[] standardOutput = this.GetStandardOutput();
for (int i = 0; i < standardOutput.Length; i++)
{
string value = standardOutput[i];
stringBuilder.AppendLine(value);
}
stringBuilder.AppendLine("stderr:");
string[] errorOutput = this.GetErrorOutput();
for (int j = 0; j < errorOutput.Length; j++)
{
string value2 = errorOutput[j];
stringBuilder.AppendLine(value2);
}
return stringBuilder.ToString();
}
public void Dispose()
{
this.Kill();
this._process.Dispose();
}
public void Kill()
{
if (!this.HasExited)
{
this._process.Kill();
this._process.WaitForExit();
}
}
public Stream GetStandardInput()
{
return this._stdin;
}
public string[] GetStandardOutput()
{
return this._stdout.GetOutput();
}
public string GetStandardOutputAsString()
{
string[] standardOutput = this.GetStandardOutput();
return Program.GetOutputAsString(standardOutput);
}
public string[] GetErrorOutput()
{
return this._stderr.GetOutput();
}
public string GetErrorOutputAsString()
{
string[] errorOutput = this.GetErrorOutput();
return Program.GetOutputAsString(errorOutput);
}
private static string GetOutputAsString(string[] output)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < output.Length; i++)
{
string value = output[i];
stringBuilder.AppendLine(value);
}
return stringBuilder.ToString();
}
public void WaitForExit()
{
this._process.WaitForExit();
}
public bool WaitForExit(int milliseconds)
{
return this._process.WaitForExit(milliseconds);
}
}
}