diff options
Diffstat (limited to 'Prebuild/src/Core/Nodes/FilesNode.cs')
-rw-r--r-- | Prebuild/src/Core/Nodes/FilesNode.cs | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Nodes/FilesNode.cs b/Prebuild/src/Core/Nodes/FilesNode.cs new file mode 100644 index 0000000..442a45f --- /dev/null +++ b/Prebuild/src/Core/Nodes/FilesNode.cs | |||
@@ -0,0 +1,222 @@ | |||
1 | #region BSD License | ||
2 | /* | ||
3 | Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com) | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without modification, are permitted | ||
6 | provided 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 | |||
16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | ||
17 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
20 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
21 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | #endregion | ||
25 | |||
26 | #region CVS Information | ||
27 | /* | ||
28 | * $Source$ | ||
29 | * $Author: jendave $ | ||
30 | * $Date: 2006-09-20 09:42:51 +0200 (on, 20 sep 2006) $ | ||
31 | * $Revision: 164 $ | ||
32 | */ | ||
33 | #endregion | ||
34 | |||
35 | using System; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Specialized; | ||
38 | using System.Xml; | ||
39 | |||
40 | using Prebuild.Core.Attributes; | ||
41 | using Prebuild.Core.Interfaces; | ||
42 | |||
43 | namespace Prebuild.Core.Nodes | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// | ||
47 | /// </summary> | ||
48 | [DataNode("Files")] | ||
49 | public class FilesNode : DataNode | ||
50 | { | ||
51 | #region Fields | ||
52 | |||
53 | private StringCollection m_Files; | ||
54 | private Hashtable m_BuildActions; | ||
55 | private Hashtable m_SubTypes; | ||
56 | private Hashtable m_ResourceNames; | ||
57 | private Hashtable m_CopyToOutputs; | ||
58 | private Hashtable m_Links; | ||
59 | |||
60 | |||
61 | #endregion | ||
62 | |||
63 | #region Constructors | ||
64 | |||
65 | /// <summary> | ||
66 | /// | ||
67 | /// </summary> | ||
68 | public FilesNode() | ||
69 | { | ||
70 | m_Files = new StringCollection(); | ||
71 | m_BuildActions = new Hashtable(); | ||
72 | m_SubTypes = new Hashtable(); | ||
73 | m_ResourceNames = new Hashtable(); | ||
74 | m_CopyToOutputs = new Hashtable(); | ||
75 | m_Links = new Hashtable(); | ||
76 | } | ||
77 | |||
78 | #endregion | ||
79 | |||
80 | #region Properties | ||
81 | |||
82 | /// <summary> | ||
83 | /// | ||
84 | /// </summary> | ||
85 | public int Count | ||
86 | { | ||
87 | get | ||
88 | { | ||
89 | return m_Files.Count; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | #endregion | ||
94 | |||
95 | #region Public Methods | ||
96 | |||
97 | /// <summary> | ||
98 | /// | ||
99 | /// </summary> | ||
100 | /// <param name="file"></param> | ||
101 | /// <returns></returns> | ||
102 | public BuildAction GetBuildAction(string file) | ||
103 | { | ||
104 | if(!m_BuildActions.ContainsKey(file)) | ||
105 | { | ||
106 | return BuildAction.Compile; | ||
107 | } | ||
108 | |||
109 | return (BuildAction)m_BuildActions[file]; | ||
110 | } | ||
111 | |||
112 | public CopyToOutput GetCopyToOutput(string file) | ||
113 | { | ||
114 | if (!this.m_CopyToOutputs.ContainsKey(file)) | ||
115 | { | ||
116 | return CopyToOutput.Never; | ||
117 | } | ||
118 | return (CopyToOutput) this.m_CopyToOutputs[file]; | ||
119 | } | ||
120 | |||
121 | public bool GetIsLink(string file) | ||
122 | { | ||
123 | if (!this.m_Links.ContainsKey(file)) | ||
124 | { | ||
125 | return false; | ||
126 | } | ||
127 | return (bool) this.m_Links[file]; | ||
128 | } | ||
129 | |||
130 | /// <summary> | ||
131 | /// | ||
132 | /// </summary> | ||
133 | /// <param name="file"></param> | ||
134 | /// <returns></returns> | ||
135 | public SubType GetSubType(string file) | ||
136 | { | ||
137 | if(!m_SubTypes.ContainsKey(file)) | ||
138 | { | ||
139 | return SubType.Code; | ||
140 | } | ||
141 | |||
142 | return (SubType)m_SubTypes[file]; | ||
143 | } | ||
144 | |||
145 | /// <summary> | ||
146 | /// | ||
147 | /// </summary> | ||
148 | /// <param name="file"></param> | ||
149 | /// <returns></returns> | ||
150 | public string GetResourceName(string file) | ||
151 | { | ||
152 | if(!m_ResourceNames.ContainsKey(file)) | ||
153 | { | ||
154 | return ""; | ||
155 | } | ||
156 | |||
157 | return (string)m_ResourceNames[file]; | ||
158 | } | ||
159 | |||
160 | /// <summary> | ||
161 | /// | ||
162 | /// </summary> | ||
163 | /// <param name="node"></param> | ||
164 | public override void Parse(XmlNode node) | ||
165 | { | ||
166 | if( node == null ) | ||
167 | { | ||
168 | throw new ArgumentNullException("node"); | ||
169 | } | ||
170 | foreach(XmlNode child in node.ChildNodes) | ||
171 | { | ||
172 | IDataNode dataNode = Kernel.Instance.ParseNode(child, this); | ||
173 | if(dataNode is FileNode) | ||
174 | { | ||
175 | FileNode fileNode = (FileNode)dataNode; | ||
176 | if(fileNode.IsValid) | ||
177 | { | ||
178 | if (!m_Files.Contains(fileNode.Path)) | ||
179 | { | ||
180 | m_Files.Add(fileNode.Path); | ||
181 | m_BuildActions[fileNode.Path] = fileNode.BuildAction; | ||
182 | m_SubTypes[fileNode.Path] = fileNode.SubType; | ||
183 | m_ResourceNames[fileNode.Path] = fileNode.ResourceName; | ||
184 | this.m_Links[fileNode.Path] = fileNode.IsLink; | ||
185 | this.m_CopyToOutputs[fileNode.Path] = fileNode.CopyToOutput; | ||
186 | |||
187 | } | ||
188 | } | ||
189 | } | ||
190 | else if(dataNode is MatchNode) | ||
191 | { | ||
192 | foreach(string file in ((MatchNode)dataNode).Files) | ||
193 | { | ||
194 | if (!m_Files.Contains(file)) | ||
195 | { | ||
196 | m_Files.Add(file); | ||
197 | m_BuildActions[file] = ((MatchNode)dataNode).BuildAction; | ||
198 | m_SubTypes[file] = ((MatchNode)dataNode).SubType; | ||
199 | m_ResourceNames[file] = ((MatchNode)dataNode).ResourceName; | ||
200 | this.m_Links[file] = ((MatchNode) dataNode).IsLink; | ||
201 | this.m_CopyToOutputs[file] = ((MatchNode) dataNode).CopyToOutput; | ||
202 | |||
203 | } | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | |||
209 | // TODO: Check in to why StringCollection's enumerator doesn't implement | ||
210 | // IEnumerator? | ||
211 | /// <summary> | ||
212 | /// | ||
213 | /// </summary> | ||
214 | /// <returns></returns> | ||
215 | public StringEnumerator GetEnumerator() | ||
216 | { | ||
217 | return m_Files.GetEnumerator(); | ||
218 | } | ||
219 | |||
220 | #endregion | ||
221 | } | ||
222 | } | ||