Annotation of /trunk/Prebuild/src/Core/Nodes/FilesNode.cs
Parent Directory
|
Revision Log
Revision 69 - (view) (download)
| 1 : | teravus | 2 | #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 : | teravus | 69 | * $Author: borrillis $ |
| 30 : | * $Date: 2007-05-25 01:03:16 +0900 (Fri, 25 May 2007) $ | ||
| 31 : | * $Revision: 243 $ | ||
| 32 : | teravus | 2 | */ |
| 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 : | teravus | 69 | private Hashtable m_LinkPaths; |
| 60 : | private Hashtable m_PreservePaths; | ||
| 61 : | teravus | 2 | |
| 62 : | #endregion | ||
| 63 : | |||
| 64 : | #region Constructors | ||
| 65 : | |||
| 66 : | /// <summary> | ||
| 67 : | /// | ||
| 68 : | /// </summary> | ||
| 69 : | public FilesNode() | ||
| 70 : | { | ||
| 71 : | m_Files = new StringCollection(); | ||
| 72 : | m_BuildActions = new Hashtable(); | ||
| 73 : | m_SubTypes = new Hashtable(); | ||
| 74 : | m_ResourceNames = new Hashtable(); | ||
| 75 : | m_CopyToOutputs = new Hashtable(); | ||
| 76 : | m_Links = new Hashtable(); | ||
| 77 : | teravus | 69 | m_LinkPaths = new Hashtable(); |
| 78 : | m_PreservePaths = new Hashtable(); | ||
| 79 : | } | ||
| 80 : | teravus | 2 | |
| 81 : | #endregion | ||
| 82 : | |||
| 83 : | #region Properties | ||
| 84 : | |||
| 85 : | /// <summary> | ||
| 86 : | /// | ||
| 87 : | /// </summary> | ||
| 88 : | public int Count | ||
| 89 : | { | ||
| 90 : | get | ||
| 91 : | { | ||
| 92 : | return m_Files.Count; | ||
| 93 : | } | ||
| 94 : | } | ||
| 95 : | |||
| 96 : | #endregion | ||
| 97 : | |||
| 98 : | #region Public Methods | ||
| 99 : | |||
| 100 : | /// <summary> | ||
| 101 : | /// | ||
| 102 : | /// </summary> | ||
| 103 : | /// <param name="file"></param> | ||
| 104 : | /// <returns></returns> | ||
| 105 : | public BuildAction GetBuildAction(string file) | ||
| 106 : | { | ||
| 107 : | if(!m_BuildActions.ContainsKey(file)) | ||
| 108 : | { | ||
| 109 : | return BuildAction.Compile; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | return (BuildAction)m_BuildActions[file]; | ||
| 113 : | } | ||
| 114 : | |||
| 115 : | public CopyToOutput GetCopyToOutput(string file) | ||
| 116 : | { | ||
| 117 : | if (!this.m_CopyToOutputs.ContainsKey(file)) | ||
| 118 : | { | ||
| 119 : | return CopyToOutput.Never; | ||
| 120 : | } | ||
| 121 : | return (CopyToOutput) this.m_CopyToOutputs[file]; | ||
| 122 : | } | ||
| 123 : | |||
| 124 : | public bool GetIsLink(string file) | ||
| 125 : | { | ||
| 126 : | if (!this.m_Links.ContainsKey(file)) | ||
| 127 : | { | ||
| 128 : | return false; | ||
| 129 : | } | ||
| 130 : | return (bool) this.m_Links[file]; | ||
| 131 : | } | ||
| 132 : | |||
| 133 : | teravus | 69 | public string GetLinkPath( string file ) |
| 134 : | { | ||
| 135 : | if ( !this.m_LinkPaths.ContainsKey( file ) ) | ||
| 136 : | { | ||
| 137 : | return string.Empty; | ||
| 138 : | } | ||
| 139 : | return (string)this.m_LinkPaths[ file ]; | ||
| 140 : | } | ||
| 141 : | |||
| 142 : | teravus | 2 | /// <summary> |
| 143 : | /// | ||
| 144 : | /// </summary> | ||
| 145 : | /// <param name="file"></param> | ||
| 146 : | /// <returns></returns> | ||
| 147 : | public SubType GetSubType(string file) | ||
| 148 : | { | ||
| 149 : | if(!m_SubTypes.ContainsKey(file)) | ||
| 150 : | { | ||
| 151 : | return SubType.Code; | ||
| 152 : | } | ||
| 153 : | |||
| 154 : | return (SubType)m_SubTypes[file]; | ||
| 155 : | } | ||
| 156 : | |||
| 157 : | /// <summary> | ||
| 158 : | /// | ||
| 159 : | /// </summary> | ||
| 160 : | /// <param name="file"></param> | ||
| 161 : | /// <returns></returns> | ||
| 162 : | public string GetResourceName(string file) | ||
| 163 : | { | ||
| 164 : | if(!m_ResourceNames.ContainsKey(file)) | ||
| 165 : | { | ||
| 166 : | return ""; | ||
| 167 : | } | ||
| 168 : | |||
| 169 : | return (string)m_ResourceNames[file]; | ||
| 170 : | } | ||
| 171 : | |||
| 172 : | teravus | 69 | /// <summary> |
| 173 : | /// | ||
| 174 : | /// </summary> | ||
| 175 : | /// <param name="file"></param> | ||
| 176 : | /// <returns></returns> | ||
| 177 : | public bool GetPreservePath( string file ) | ||
| 178 : | { | ||
| 179 : | if ( !m_PreservePaths.ContainsKey( file ) ) | ||
| 180 : | { | ||
| 181 : | return false; | ||
| 182 : | } | ||
| 183 : | |||
| 184 : | return (bool)m_PreservePaths[ file ]; | ||
| 185 : | } | ||
| 186 : | |||
| 187 : | teravus | 2 | /// <summary> |
| 188 : | /// | ||
| 189 : | /// </summary> | ||
| 190 : | /// <param name="node"></param> | ||
| 191 : | public override void Parse(XmlNode node) | ||
| 192 : | { | ||
| 193 : | if( node == null ) | ||
| 194 : | { | ||
| 195 : | throw new ArgumentNullException("node"); | ||
| 196 : | } | ||
| 197 : | foreach(XmlNode child in node.ChildNodes) | ||
| 198 : | { | ||
| 199 : | IDataNode dataNode = Kernel.Instance.ParseNode(child, this); | ||
| 200 : | if(dataNode is FileNode) | ||
| 201 : | { | ||
| 202 : | FileNode fileNode = (FileNode)dataNode; | ||
| 203 : | if(fileNode.IsValid) | ||
| 204 : | { | ||
| 205 : | if (!m_Files.Contains(fileNode.Path)) | ||
| 206 : | { | ||
| 207 : | m_Files.Add(fileNode.Path); | ||
| 208 : | m_BuildActions[fileNode.Path] = fileNode.BuildAction; | ||
| 209 : | m_SubTypes[fileNode.Path] = fileNode.SubType; | ||
| 210 : | m_ResourceNames[fileNode.Path] = fileNode.ResourceName; | ||
| 211 : | teravus | 69 | this.m_PreservePaths[ fileNode.Path ] = fileNode.PreservePath; |
| 212 : | this.m_Links[ fileNode.Path ] = fileNode.IsLink; | ||
| 213 : | this.m_LinkPaths[ fileNode.Path ] = fileNode.LinkPath; | ||
| 214 : | this.m_CopyToOutputs[ fileNode.Path ] = fileNode.CopyToOutput; | ||
| 215 : | teravus | 2 | |
| 216 : | } | ||
| 217 : | } | ||
| 218 : | } | ||
| 219 : | else if(dataNode is MatchNode) | ||
| 220 : | { | ||
| 221 : | foreach(string file in ((MatchNode)dataNode).Files) | ||
| 222 : | { | ||
| 223 : | teravus | 69 | MatchNode matchNode = (MatchNode)dataNode; |
| 224 : | teravus | 2 | if (!m_Files.Contains(file)) |
| 225 : | { | ||
| 226 : | m_Files.Add(file); | ||
| 227 : | teravus | 69 | m_BuildActions[ file ] = matchNode.BuildAction; |
| 228 : | m_SubTypes[ file ] = matchNode.SubType; | ||
| 229 : | m_ResourceNames[ file ] = matchNode.ResourceName; | ||
| 230 : | this.m_PreservePaths[ file ] = matchNode.PreservePath; | ||
| 231 : | this.m_Links[ file ] = matchNode.IsLink; | ||
| 232 : | this.m_LinkPaths[ file ] = matchNode.LinkPath; | ||
| 233 : | this.m_CopyToOutputs[ file ] = matchNode.CopyToOutput; | ||
| 234 : | teravus | 2 | |
| 235 : | } | ||
| 236 : | } | ||
| 237 : | } | ||
| 238 : | } | ||
| 239 : | } | ||
| 240 : | |||
| 241 : | // TODO: Check in to why StringCollection's enumerator doesn't implement | ||
| 242 : | // IEnumerator? | ||
| 243 : | /// <summary> | ||
| 244 : | /// | ||
| 245 : | /// </summary> | ||
| 246 : | /// <returns></returns> | ||
| 247 : | public StringEnumerator GetEnumerator() | ||
| 248 : | { | ||
| 249 : | return m_Files.GetEnumerator(); | ||
| 250 : | } | ||
| 251 : | |||
| 252 : | #endregion | ||
| 253 : | |||
| 254 : | } | ||
| 255 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

