clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 using System;
27 using System.Collections.Generic;
28 using System.Collections.Specialized;
29 using System.Xml;
30  
31 using Prebuild.Core.Attributes;
32 using Prebuild.Core.Interfaces;
33 using System.IO;
34  
35 namespace Prebuild.Core.Nodes
36 {
37 /// <summary>
38 ///
39 /// </summary>
40 [DataNode("Files")]
41 public class FilesNode : DataNode
42 {
43 #region Fields
44  
45 private readonly List<string> m_Files = new List<string>();
46 private readonly Dictionary<string,BuildAction> m_BuildActions = new Dictionary<string, BuildAction>();
47 private readonly Dictionary<string, SubType> m_SubTypes = new Dictionary<string, SubType>();
48 private readonly Dictionary<string, string> m_ResourceNames = new Dictionary<string, string>();
49 private readonly Dictionary<string, CopyToOutput> m_CopyToOutputs = new Dictionary<string, CopyToOutput>();
50 private readonly Dictionary<string, bool> m_Links = new Dictionary<string, bool>();
51 private readonly Dictionary<string, string> m_LinkPaths = new Dictionary<string, string>();
52 private readonly Dictionary<string, bool> m_PreservePaths = new Dictionary<string, bool>();
53 private readonly Dictionary<string, string> m_DestinationPath = new Dictionary<string, string>();
54 private readonly NameValueCollection m_CopyFiles = new NameValueCollection();
55  
56 #endregion
57  
58 #region Properties
59  
60 public int Count
61 {
62 get
63 {
64 return m_Files.Count;
65 }
66 }
67  
68 public string[] Destinations
69 {
70 get { return m_CopyFiles.AllKeys; }
71 }
72  
73 public int CopyFiles
74 {
75 get { return m_CopyFiles.Count; }
76 }
77  
78 #endregion
79  
80 #region Public Methods
81  
82 public BuildAction GetBuildAction(string file)
83 {
84 if(!m_BuildActions.ContainsKey(file))
85 {
86 return BuildAction.Compile;
87 }
88  
89 return m_BuildActions[file];
90 }
91  
92 public string GetDestinationPath(string file)
93 {
94 if( !m_DestinationPath.ContainsKey(file))
95 {
96 return null;
97 }
98 return m_DestinationPath[file];
99 }
100  
101 public string[] SourceFiles(string dest)
102 {
103 return m_CopyFiles.GetValues(dest);
104 }
105  
106 public CopyToOutput GetCopyToOutput(string file)
107 {
108 if (!m_CopyToOutputs.ContainsKey(file))
109 {
110 return CopyToOutput.Never;
111 }
112 return m_CopyToOutputs[file];
113 }
114  
115 public bool GetIsLink(string file)
116 {
117 if (!m_Links.ContainsKey(file))
118 {
119 return false;
120 }
121 return m_Links[file];
122 }
123  
124 public bool Contains(string file)
125 {
126 return m_Files.Contains(file);
127 }
128  
129 public string GetLinkPath( string file )
130 {
131 if ( !m_LinkPaths.ContainsKey( file ) )
132 {
133 return string.Empty;
134 }
135 return m_LinkPaths[ file ];
136 }
137  
138 public SubType GetSubType(string file)
139 {
140 if(!m_SubTypes.ContainsKey(file))
141 {
142 return SubType.Code;
143 }
144  
145 return m_SubTypes[file];
146 }
147  
148 public string GetResourceName(string file)
149 {
150 if(!m_ResourceNames.ContainsKey(file))
151 {
152 return string.Empty;
153 }
154  
155 return m_ResourceNames[file];
156 }
157  
158 public bool GetPreservePath( string file )
159 {
160 if ( !m_PreservePaths.ContainsKey( file ) )
161 {
162 return false;
163 }
164  
165 return m_PreservePaths[ file ];
166 }
167  
168 public override void Parse(XmlNode node)
169 {
170 if( node == null )
171 {
172 throw new ArgumentNullException("node");
173 }
174 foreach(XmlNode child in node.ChildNodes)
175 {
176 IDataNode dataNode = Kernel.Instance.ParseNode(child, this);
177 if(dataNode is FileNode)
178 {
179 FileNode fileNode = (FileNode)dataNode;
180 if(fileNode.IsValid)
181 {
182 if (!m_Files.Contains(fileNode.Path))
183 {
184 m_Files.Add(fileNode.Path);
185 m_BuildActions[fileNode.Path] = fileNode.BuildAction;
186 m_SubTypes[fileNode.Path] = fileNode.SubType;
187 m_ResourceNames[fileNode.Path] = fileNode.ResourceName;
188 m_PreservePaths[ fileNode.Path ] = fileNode.PreservePath;
189 m_Links[ fileNode.Path ] = fileNode.IsLink;
190 m_LinkPaths[ fileNode.Path ] = fileNode.LinkPath;
191 m_CopyToOutputs[ fileNode.Path ] = fileNode.CopyToOutput;
192  
193 }
194 }
195 }
196 else if(dataNode is MatchNode)
197 {
198 foreach(string file in ((MatchNode)dataNode).Files)
199 {
200 MatchNode matchNode = (MatchNode)dataNode;
201 if (!m_Files.Contains(file))
202 {
203 m_Files.Add(file);
204 if (matchNode.BuildAction == null)
205 m_BuildActions[file] = GetBuildActionByFileName(file);
206 else
207 m_BuildActions[file] = matchNode.BuildAction.Value;
208  
209 if (matchNode.BuildAction == BuildAction.Copy)
210 {
211 m_CopyFiles.Add(matchNode.DestinationPath, file);
212 m_DestinationPath[file] = matchNode.DestinationPath;
213 }
214  
215 m_SubTypes[file] = matchNode.SubType == null ? GetSubTypeByFileName(file) : matchNode.SubType.Value;
216 m_ResourceNames[ file ] = matchNode.ResourceName;
217 m_PreservePaths[ file ] = matchNode.PreservePath;
218 m_Links[ file ] = matchNode.IsLink;
219 m_LinkPaths[ file ] = matchNode.LinkPath;
220 m_CopyToOutputs[ file ] = matchNode.CopyToOutput;
221  
222 }
223 }
224 }
225 }
226 }
227  
228 // TODO: Check in to why StringCollection's enumerator doesn't implement
229 // IEnumerator?
230 public IEnumerator<string> GetEnumerator()
231 {
232 return m_Files.GetEnumerator();
233 }
234  
235 #endregion
236  
237 }
238 }