forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Program.cs
111 lines (95 loc) · 3.74 KB
/
Program.cs
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
// MonoGame - Copyright (C) MonoGame Foundation, Inc
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace MonoGame.Content.Builder
{
class Program
{
class AssertListener : TraceListener
{
public override void Write(string message)
{
Console.Write(message);
}
public override void WriteLine(string message)
{
Console.WriteLine(message);
}
public override void Fail(string message, string detailMessage)
{
Console.WriteLine(message);
if (!string.IsNullOrEmpty(detailMessage))
Console.WriteLine(detailMessage);
}
}
static int Main(string[] args)
{
// We force all stderr to redirect to stdout
// to avoid any out of order console output.
Console.SetError(Console.Out);
// Hook in our own trace listener so that errors
// from asserts appear in the output logging instead
// of having silent failures.
Trace.Listeners.Clear();
Trace.Listeners.Add(new AssertListener());
if (!Environment.Is64BitProcess && Environment.OSVersion.Platform != PlatformID.Unix)
{
Console.Error.WriteLine("The MonoGame content tools only work on a 64bit OS.");
return -1;
}
var content = new BuildContent();
// Parse the command line.
var parser = new MGBuildParser(content)
{
Title = "MonoGame Content Builder\n" +
"Builds optimized game content for MonoGame projects."
};
if (!parser.Parse(args))
return -1;
// Launch debugger if requested.
if (content.LaunchDebugger)
{
try {
System.Diagnostics.Debugger.Launch();
} catch (NotImplementedException) {
// not implemented under Mono
Console.Error.WriteLine("The debugger is not implemented under Mono and thus is not supported on your platform.");
}
}
if (content.WaitForDebuggerToAttach)
{
var currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Waiting for debugger to attach ({currentProcess.MainModule.FileName} PID {currentProcess.Id}). Press any key to continue without debugger.");
while (!Debugger.IsAttached)
{
if (Console.KeyAvailable)
{
break;
}
Thread.Sleep(100);
}
}
// Print a startup message.
var buildStarted = DateTime.Now;
if (!content.Quiet)
Console.WriteLine("Build started {0}\n", buildStarted);
// Let the content build.
int successCount, errorCount;
content.Build(out successCount, out errorCount);
// Print the finishing info.
if (!content.Quiet)
{
Console.WriteLine("\nBuild {0} succeeded, {1} failed.\n", successCount, errorCount);
Console.WriteLine("Time elapsed {0:hh\\:mm\\:ss\\.ff}.", DateTime.Now - buildStarted);
}
// Return the error count.
return errorCount;
}
}
}