aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Nodes/FileNode.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Nodes/FileNode.cs')
-rw-r--r--Prebuild/src/Core/Nodes/FileNode.cs285
1 files changed, 285 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Nodes/FileNode.cs b/Prebuild/src/Core/Nodes/FileNode.cs
new file mode 100644
index 0000000..01cea1e
--- /dev/null
+++ b/Prebuild/src/Core/Nodes/FileNode.cs
@@ -0,0 +1,285 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Xml;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Utilities;
33using Prebuild.Core.Targets;
34
35namespace Prebuild.Core.Nodes
36{
37 /// <summary>
38 ///
39 /// </summary>
40 public enum BuildAction
41 {
42 /// <summary>
43 ///
44 /// </summary>
45 None,
46 /// <summary>
47 ///
48 /// </summary>
49 Compile,
50 /// <summary>
51 ///
52 /// </summary>
53 Content,
54 /// <summary>
55 ///
56 /// </summary>
57 EmbeddedResource,
58 /// <summary>
59 ///
60 /// </summary>
61 ApplicationDefinition,
62 /// <summary>
63 ///
64 /// </summary>
65 Page
66 }
67
68 /// <summary>
69 ///
70 /// </summary>
71 public enum SubType
72 {
73 /// <summary>
74 ///
75 /// </summary>
76 Code,
77 /// <summary>
78 ///
79 /// </summary>
80 Component,
81 /// <summary>
82 ///
83 /// </summary>
84 Designer,
85 /// <summary>
86 ///
87 /// </summary>
88 Form,
89 /// <summary>
90 ///
91 /// </summary>
92 Settings,
93 /// <summary>
94 ///
95 /// </summary>
96 UserControl,
97 /// <summary>
98 ///
99 /// </summary>
100 CodeBehind,
101 }
102
103 public enum CopyToOutput
104 {
105 Never,
106 Always,
107 PreserveNewest
108 }
109
110 /// <summary>
111 ///
112 /// </summary>
113 [DataNode("File")]
114 public class FileNode : DataNode
115 {
116 #region Fields
117
118 private string m_Path;
119 private string m_ResourceName = "";
120 private BuildAction? m_BuildAction;
121 private bool m_Valid;
122 private SubType? m_SubType;
123 private CopyToOutput m_CopyToOutput = CopyToOutput.Never;
124 private bool m_Link = false;
125 private string m_LinkPath = string.Empty;
126 private bool m_PreservePath = false;
127
128
129 #endregion
130
131 #region Properties
132
133 /// <summary>
134 ///
135 /// </summary>
136 public string Path
137 {
138 get
139 {
140 return m_Path;
141 }
142 }
143
144 /// <summary>
145 ///
146 /// </summary>
147 public string ResourceName
148 {
149 get
150 {
151 return m_ResourceName;
152 }
153 }
154
155 /// <summary>
156 ///
157 /// </summary>
158 public BuildAction BuildAction
159 {
160 get
161 {
162 if (m_BuildAction != null)
163 return m_BuildAction.Value;
164 else
165 return GetBuildActionByFileName(this.Path);
166
167 }
168 }
169
170 public CopyToOutput CopyToOutput
171 {
172 get
173 {
174 return this.m_CopyToOutput;
175 }
176 }
177
178 public bool IsLink
179 {
180 get
181 {
182 return this.m_Link;
183 }
184 }
185
186 public string LinkPath
187 {
188 get
189 {
190 return this.m_LinkPath;
191 }
192 }
193 /// <summary>
194 ///
195 /// </summary>
196 public SubType SubType
197 {
198 get
199 {
200 if (m_SubType != null)
201 return m_SubType.Value;
202 else
203 return GetSubTypeByFileName(this.Path);
204 }
205 }
206
207 /// <summary>
208 ///
209 /// </summary>
210 public bool IsValid
211 {
212 get
213 {
214 return m_Valid;
215 }
216 }
217
218 /// <summary>
219 ///
220 /// </summary>
221 /// <param name="file"></param>
222 /// <returns></returns>
223 public bool PreservePath
224 {
225 get
226 {
227 return m_PreservePath;
228 }
229 }
230
231 #endregion
232
233 #region Public Methods
234
235 /// <summary>
236 ///
237 /// </summary>
238 /// <param name="node"></param>
239 public override void Parse(XmlNode node)
240 {
241 string buildAction = Helper.AttributeValue(node, "buildAction", String.Empty);
242 if (buildAction != string.Empty)
243 m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction);
244 string subType = Helper.AttributeValue(node, "subType", string.Empty);
245 if (subType != String.Empty)
246 m_SubType = (SubType)Enum.Parse(typeof(SubType), subType);
247
248 m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString());
249 this.m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
250 if ( this.m_Link == true )
251 {
252 this.m_LinkPath = Helper.AttributeValue( node, "linkPath", string.Empty );
253 }
254 this.m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString()));
255 this.m_PreservePath = bool.Parse( Helper.AttributeValue( node, "preservePath", bool.FalseString ) );
256
257 if( node == null )
258 {
259 throw new ArgumentNullException("node");
260 }
261
262 m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText);
263 if(m_Path == null)
264 {
265 m_Path = "";
266 }
267
268 m_Path = m_Path.Trim();
269 m_Valid = true;
270 if(!File.Exists(m_Path))
271 {
272 m_Valid = false;
273 Kernel.Instance.Log.Write(LogType.Warning, "File does not exist: {0}", m_Path);
274 }
275
276 if (System.IO.Path.GetExtension(m_Path) == ".settings")
277 {
278 m_SubType = SubType.Settings;
279 m_BuildAction = BuildAction.None;
280 }
281 }
282
283 #endregion
284 }
285}