aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Nodes/FilesNode.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Nodes/FilesNode.cs')
-rw-r--r--Prebuild/src/Core/Nodes/FilesNode.cs204
1 files changed, 204 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..23a716c
--- /dev/null
+++ b/Prebuild/src/Core/Nodes/FilesNode.cs
@@ -0,0 +1,204 @@
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.Collections.Generic;
28using System.Xml;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using System.IO;
33
34namespace Prebuild.Core.Nodes
35{
36 /// <summary>
37 ///
38 /// </summary>
39 [DataNode("Files")]
40 public class FilesNode : DataNode
41 {
42 #region Fields
43
44 private readonly List<string> m_Files = new List<string>();
45 private readonly Dictionary<string,BuildAction> m_BuildActions = new Dictionary<string, BuildAction>();
46 private readonly Dictionary<string, SubType> m_SubTypes = new Dictionary<string, SubType>();
47 private readonly Dictionary<string, string> m_ResourceNames = new Dictionary<string, string>();
48 private readonly Dictionary<string, CopyToOutput> m_CopyToOutputs = new Dictionary<string, CopyToOutput>();
49 private readonly Dictionary<string, bool> m_Links = new Dictionary<string, bool>();
50 private readonly Dictionary<string, string> m_LinkPaths = new Dictionary<string, string>();
51 private readonly Dictionary<string, bool> m_PreservePaths = new Dictionary<string, bool>();
52
53 #endregion
54
55 #region Properties
56
57 public int Count
58 {
59 get
60 {
61 return m_Files.Count;
62 }
63 }
64
65 #endregion
66
67 #region Public Methods
68
69 public BuildAction GetBuildAction(string file)
70 {
71 if(!m_BuildActions.ContainsKey(file))
72 {
73 return BuildAction.Compile;
74 }
75
76 return m_BuildActions[file];
77 }
78
79 public CopyToOutput GetCopyToOutput(string file)
80 {
81 if (!m_CopyToOutputs.ContainsKey(file))
82 {
83 return CopyToOutput.Never;
84 }
85 return m_CopyToOutputs[file];
86 }
87
88 public bool GetIsLink(string file)
89 {
90 if (!m_Links.ContainsKey(file))
91 {
92 return false;
93 }
94 return m_Links[file];
95 }
96
97 public bool Contains(string file)
98 {
99 return m_Files.Contains(file);
100 }
101
102 public string GetLinkPath( string file )
103 {
104 if ( !m_LinkPaths.ContainsKey( file ) )
105 {
106 return string.Empty;
107 }
108 return m_LinkPaths[ file ];
109 }
110
111 public SubType GetSubType(string file)
112 {
113 if(!m_SubTypes.ContainsKey(file))
114 {
115 return SubType.Code;
116 }
117
118 return m_SubTypes[file];
119 }
120
121 public string GetResourceName(string file)
122 {
123 if(!m_ResourceNames.ContainsKey(file))
124 {
125 return string.Empty;
126 }
127
128 return m_ResourceNames[file];
129 }
130
131 public bool GetPreservePath( string file )
132 {
133 if ( !m_PreservePaths.ContainsKey( file ) )
134 {
135 return false;
136 }
137
138 return m_PreservePaths[ file ];
139 }
140
141 public override void Parse(XmlNode node)
142 {
143 if( node == null )
144 {
145 throw new ArgumentNullException("node");
146 }
147 foreach(XmlNode child in node.ChildNodes)
148 {
149 IDataNode dataNode = Kernel.Instance.ParseNode(child, this);
150 if(dataNode is FileNode)
151 {
152 FileNode fileNode = (FileNode)dataNode;
153 if(fileNode.IsValid)
154 {
155 if (!m_Files.Contains(fileNode.Path))
156 {
157 m_Files.Add(fileNode.Path);
158 m_BuildActions[fileNode.Path] = fileNode.BuildAction;
159 m_SubTypes[fileNode.Path] = fileNode.SubType;
160 m_ResourceNames[fileNode.Path] = fileNode.ResourceName;
161 m_PreservePaths[ fileNode.Path ] = fileNode.PreservePath;
162 m_Links[ fileNode.Path ] = fileNode.IsLink;
163 m_LinkPaths[ fileNode.Path ] = fileNode.LinkPath;
164 m_CopyToOutputs[ fileNode.Path ] = fileNode.CopyToOutput;
165
166 }
167 }
168 }
169 else if(dataNode is MatchNode)
170 {
171 foreach(string file in ((MatchNode)dataNode).Files)
172 {
173 MatchNode matchNode = (MatchNode)dataNode;
174 if (!m_Files.Contains(file))
175 {
176 m_Files.Add(file);
177 if (matchNode.BuildAction == null)
178 m_BuildActions[file] = GetBuildActionByFileName(file);
179 else
180 m_BuildActions[file] = matchNode.BuildAction.Value;
181 m_SubTypes[file] = matchNode.SubType == null ? GetSubTypeByFileName(file) : matchNode.SubType.Value;
182 m_ResourceNames[ file ] = matchNode.ResourceName;
183 m_PreservePaths[ file ] = matchNode.PreservePath;
184 m_Links[ file ] = matchNode.IsLink;
185 m_LinkPaths[ file ] = matchNode.LinkPath;
186 m_CopyToOutputs[ file ] = matchNode.CopyToOutput;
187
188 }
189 }
190 }
191 }
192 }
193
194 // TODO: Check in to why StringCollection's enumerator doesn't implement
195 // IEnumerator?
196 public IEnumerator<string> GetEnumerator()
197 {
198 return m_Files.GetEnumerator();
199 }
200
201 #endregion
202
203 }
204}