forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentBuildLogger.cs
More file actions
134 lines (120 loc) · 5.25 KB
/
Copy pathContentBuildLogger.cs
File metadata and controls
134 lines (120 loc) · 5.25 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
// 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.Collections.Generic;
using System.IO;
namespace Microsoft.Xna.Framework.Content.Pipeline
{
/// <summary>
/// Provides methods for reporting informational messages or warnings from content importers and processors.
/// Do not use this class to report errors. Instead, report errors by throwing a PipelineException or InvalidContentException.
/// </summary>
public abstract class ContentBuildLogger
{
Stack<string> filenames = new Stack<string>();
private int indentCount = 0;
/// <summary/>
protected string IndentString { get { return String.Empty.PadLeft(Math.Max(0, indentCount), '\t'); } }
/// <summary>
/// Gets or sets the base reference path used when reporting errors during the content build process.
/// </summary>
public string LoggerRootDirectory { get; set; }
/// <summary>
/// Initializes a new instance of ContentBuildLogger.
/// </summary>
protected ContentBuildLogger ()
{
}
/// <summary>
/// Returns the relative path to the filename from the root directory.
/// </summary>
/// <param name="filename">The target filename.</param>
/// <param name="rootDirectory">The root directory. If not specified, the current directory is used.</param>
/// <returns>The relative path.</returns>
string GetRelativePath(string filename, string rootDirectory)
{
rootDirectory = Path.GetFullPath(string.IsNullOrEmpty(rootDirectory) ? "." : rootDirectory);
filename = Path.GetFullPath(filename);
if (filename.StartsWith(rootDirectory))
return filename.Substring(rootDirectory.Length);
return filename;
}
/// <summary>
/// Gets the filename currently being processed, for use in warning and error messages.
/// </summary>
/// <param name="contentIdentity">Identity of a content item. If specified, GetCurrentFilename uses this value to refine the search. If no value is specified, the current PushFile state is used.</param>
/// <returns>Name of the file being processed.</returns>
protected string GetCurrentFilename(
ContentIdentity contentIdentity
)
{
if ((contentIdentity != null) && !string.IsNullOrEmpty(contentIdentity.SourceFilename))
return GetRelativePath(contentIdentity.SourceFilename, LoggerRootDirectory);
if (filenames.Count > 0)
return GetRelativePath(filenames.Peek(), LoggerRootDirectory);
return null;
}
/// <summary>
/// Outputs a high-priority status message from a content importer or processor.
/// </summary>
/// <param name="message">Message being reported.</param>
/// <param name="messageArgs">Arguments for the reported message.</param>
public abstract void LogImportantMessage(
string message,
params Object[] messageArgs
);
/// <summary>
/// Outputs a low priority status message from a content importer or processor.
/// </summary>
/// <param name="message">Message being reported.</param>
/// <param name="messageArgs">Arguments for the reported message.</param>
public abstract void LogMessage(
string message,
params Object[] messageArgs
);
/// <summary>
/// Outputs a warning message from a content importer or processor.
/// </summary>
/// <param name="helpLink">Link to an existing online help topic containing related information.</param>
/// <param name="contentIdentity">Identity of the content item that generated the message.</param>
/// <param name="message">Message being reported.</param>
/// <param name="messageArgs">Arguments for the reported message.</param>
public abstract void LogWarning(
string helpLink,
ContentIdentity contentIdentity,
string message,
params Object[] messageArgs
);
/// <summary>
/// Outputs a message indicating that a content asset has completed processing.
/// </summary>
public void PopFile()
{
filenames.Pop();
}
/// <summary>
/// Outputs a message indicating that a content asset has begun processing.
/// All logger warnings or error exceptions from this time forward to the next PopFile call refer to this file.
/// </summary>
/// <param name="filename">Name of the file containing future messages.</param>
public void PushFile(string filename)
{
filenames.Push(filename);
}
/// <summary>
/// Increments the indentation level.
/// </summary>
public void Indent()
{
indentCount++;
}
/// <summary>
/// Decrements the indentation level.
/// </summary>
public void Unindent()
{
indentCount--;
}
}
}