corrade-vassal – Blame information for rev 1
?pathlinks?
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 | #region CVS Information |
||
27 | /* |
||
28 | * $Source$ |
||
29 | * $Author: jendave $ |
||
30 | * $Date: 2007-01-08 08:55:40 -0800 (Mon, 08 Jan 2007) $ |
||
31 | * $Revision: 197 $ |
||
32 | */ |
||
33 | #endregion |
||
34 | |||
35 | |||
36 | |||
37 | using System; |
||
38 | using System.Collections; |
||
39 | using System.Collections.Specialized; |
||
40 | using System.Reflection; |
||
41 | using System.Xml; |
||
42 | |||
43 | using Prebuild.Core.Attributes; |
||
44 | using Prebuild.Core.Interfaces; |
||
45 | using Prebuild.Core.Utilities; |
||
46 | |||
47 | namespace Prebuild.Core.Nodes |
||
48 | { |
||
49 | /// <summary> |
||
50 | /// |
||
51 | /// </summary> |
||
52 | [DataNode("Options")] |
||
53 | public class OptionsNode : DataNode |
||
54 | { |
||
55 | #region Fields |
||
56 | |||
57 | private static Hashtable m_OptionFields; |
||
58 | |||
59 | [OptionNode("CompilerDefines")] |
||
60 | private string m_CompilerDefines = ""; |
||
61 | |||
62 | /// <summary> |
||
63 | /// |
||
64 | /// </summary> |
||
65 | public string CompilerDefines |
||
66 | { |
||
67 | get |
||
68 | { |
||
69 | return m_CompilerDefines; |
||
70 | } |
||
71 | set |
||
72 | { |
||
73 | m_CompilerDefines = value; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | [OptionNode("OptimizeCode")] |
||
78 | private bool m_OptimizeCode; |
||
79 | |||
80 | /// <summary> |
||
81 | /// |
||
82 | /// </summary> |
||
83 | public bool OptimizeCode |
||
84 | { |
||
85 | get |
||
86 | { |
||
87 | return m_OptimizeCode; |
||
88 | } |
||
89 | set |
||
90 | { |
||
91 | m_OptimizeCode = value; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | [OptionNode("CheckUnderflowOverflow")] |
||
96 | private bool m_CheckUnderflowOverflow; |
||
97 | |||
98 | /// <summary> |
||
99 | /// |
||
100 | /// </summary> |
||
101 | public bool CheckUnderflowOverflow |
||
102 | { |
||
103 | get |
||
104 | { |
||
105 | return m_CheckUnderflowOverflow; |
||
106 | } |
||
107 | set |
||
108 | { |
||
109 | m_CheckUnderflowOverflow = value; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | [OptionNode("AllowUnsafe")] |
||
114 | private bool m_AllowUnsafe; |
||
115 | |||
116 | /// <summary> |
||
117 | /// |
||
118 | /// </summary> |
||
119 | public bool AllowUnsafe |
||
120 | { |
||
121 | get |
||
122 | { |
||
123 | return m_AllowUnsafe; |
||
124 | } |
||
125 | set |
||
126 | { |
||
127 | m_AllowUnsafe = value; |
||
128 | } |
||
129 | } |
||
130 | |||
131 | [OptionNode("PreBuildEvent")] |
||
132 | private string m_PreBuildEvent; |
||
133 | |||
134 | /// <summary> |
||
135 | /// |
||
136 | /// </summary> |
||
137 | public string PreBuildEvent |
||
138 | { |
||
139 | get |
||
140 | { |
||
141 | return m_PreBuildEvent; |
||
142 | } |
||
143 | set |
||
144 | { |
||
145 | m_PreBuildEvent = value; |
||
146 | } |
||
147 | } |
||
148 | |||
149 | [OptionNode("PostBuildEvent")] |
||
150 | private string m_PostBuildEvent; |
||
151 | |||
152 | /// <summary> |
||
153 | /// |
||
154 | /// </summary> |
||
155 | public string PostBuildEvent |
||
156 | { |
||
157 | get |
||
158 | { |
||
159 | return m_PostBuildEvent; |
||
160 | } |
||
161 | set |
||
162 | { |
||
163 | m_PostBuildEvent = value; |
||
164 | } |
||
165 | } |
||
166 | |||
167 | [OptionNode("PreBuildEventArgs")] |
||
168 | private string m_PreBuildEventArgs; |
||
169 | |||
170 | /// <summary> |
||
171 | /// |
||
172 | /// </summary> |
||
173 | public string PreBuildEventArgs |
||
174 | { |
||
175 | get |
||
176 | { |
||
177 | return m_PreBuildEventArgs; |
||
178 | } |
||
179 | set |
||
180 | { |
||
181 | m_PreBuildEventArgs = value; |
||
182 | } |
||
183 | } |
||
184 | |||
185 | [OptionNode("PostBuildEventArgs")] |
||
186 | private string m_PostBuildEventArgs; |
||
187 | |||
188 | /// <summary> |
||
189 | /// |
||
190 | /// </summary> |
||
191 | public string PostBuildEventArgs |
||
192 | { |
||
193 | get |
||
194 | { |
||
195 | return m_PostBuildEventArgs; |
||
196 | } |
||
197 | set |
||
198 | { |
||
199 | m_PostBuildEventArgs = value; |
||
200 | } |
||
201 | } |
||
202 | |||
203 | [OptionNode("RunPostBuildEvent")] |
||
204 | private string m_RunPostBuildEvent; |
||
205 | |||
206 | /// <summary> |
||
207 | /// |
||
208 | /// </summary> |
||
209 | public string RunPostBuildEvent |
||
210 | { |
||
211 | get |
||
212 | { |
||
213 | return m_RunPostBuildEvent; |
||
214 | } |
||
215 | set |
||
216 | { |
||
217 | m_RunPostBuildEvent = value; |
||
218 | } |
||
219 | } |
||
220 | |||
221 | [OptionNode("RunScript")] |
||
222 | private string m_RunScript; |
||
223 | |||
224 | /// <summary> |
||
225 | /// |
||
226 | /// </summary> |
||
227 | public string RunScript |
||
228 | { |
||
229 | get |
||
230 | { |
||
231 | return m_RunScript; |
||
232 | } |
||
233 | set |
||
234 | { |
||
235 | m_RunScript = value; |
||
236 | } |
||
237 | } |
||
238 | |||
239 | [OptionNode("WarningLevel")] |
||
240 | private int m_WarningLevel = 4; |
||
241 | |||
242 | /// <summary> |
||
243 | /// |
||
244 | /// </summary> |
||
245 | public int WarningLevel |
||
246 | { |
||
247 | get |
||
248 | { |
||
249 | return m_WarningLevel; |
||
250 | } |
||
251 | set |
||
252 | { |
||
253 | m_WarningLevel = value; |
||
254 | } |
||
255 | } |
||
256 | |||
257 | [OptionNode("WarningsAsErrors")] |
||
258 | private bool m_WarningsAsErrors; |
||
259 | |||
260 | /// <summary> |
||
261 | /// |
||
262 | /// </summary> |
||
263 | public bool WarningsAsErrors |
||
264 | { |
||
265 | get |
||
266 | { |
||
267 | return m_WarningsAsErrors; |
||
268 | } |
||
269 | set |
||
270 | { |
||
271 | m_WarningsAsErrors = value; |
||
272 | } |
||
273 | } |
||
274 | |||
275 | [OptionNode("SuppressWarnings")] |
||
276 | private string m_SuppressWarnings = ""; |
||
277 | |||
278 | /// <summary> |
||
279 | /// |
||
280 | /// </summary> |
||
281 | public string SuppressWarnings |
||
282 | { |
||
283 | get |
||
284 | { |
||
285 | return m_SuppressWarnings; |
||
286 | } |
||
287 | set |
||
288 | { |
||
289 | m_SuppressWarnings = value; |
||
290 | } |
||
291 | } |
||
292 | |||
293 | [OptionNode("OutputPath")] |
||
294 | private string m_OutputPath = "bin/"; |
||
295 | |||
296 | /// <summary> |
||
297 | /// |
||
298 | /// </summary> |
||
299 | public string OutputPath |
||
300 | { |
||
301 | get |
||
302 | { |
||
303 | return m_OutputPath; |
||
304 | } |
||
305 | set |
||
306 | { |
||
307 | m_OutputPath = value; |
||
308 | } |
||
309 | } |
||
310 | |||
311 | [OptionNode("GenerateDocumentation")] |
||
312 | private bool m_GenerateDocumentation; |
||
313 | |||
314 | /// <summary> |
||
315 | /// |
||
316 | /// </summary> |
||
317 | public bool GenerateDocumentation |
||
318 | { |
||
319 | get |
||
320 | { |
||
321 | return m_GenerateDocumentation; |
||
322 | } |
||
323 | set |
||
324 | { |
||
325 | m_GenerateDocumentation = value; |
||
326 | } |
||
327 | } |
||
328 | |||
329 | [OptionNode("GenerateXmlDocFile")] |
||
330 | private bool m_GenerateXmlDocFile; |
||
331 | |||
332 | /// <summary> |
||
333 | /// |
||
334 | /// </summary> |
||
335 | public bool GenerateXmlDocFile |
||
336 | { |
||
337 | get |
||
338 | { |
||
339 | return m_GenerateXmlDocFile; |
||
340 | } |
||
341 | set |
||
342 | { |
||
343 | m_GenerateXmlDocFile = value; |
||
344 | } |
||
345 | } |
||
346 | |||
347 | [OptionNode("XmlDocFile")] |
||
348 | private string m_XmlDocFile = ""; |
||
349 | |||
350 | /// <summary> |
||
351 | /// |
||
352 | /// </summary> |
||
353 | public string XmlDocFile |
||
354 | { |
||
355 | get |
||
356 | { |
||
357 | return m_XmlDocFile; |
||
358 | } |
||
359 | set |
||
360 | { |
||
361 | m_XmlDocFile = value; |
||
362 | } |
||
363 | } |
||
364 | |||
365 | [OptionNode("KeyFile")] |
||
366 | private string m_KeyFile = ""; |
||
367 | |||
368 | /// <summary> |
||
369 | /// |
||
370 | /// </summary> |
||
371 | public string KeyFile |
||
372 | { |
||
373 | get |
||
374 | { |
||
375 | return m_KeyFile; |
||
376 | } |
||
377 | set |
||
378 | { |
||
379 | m_KeyFile = value; |
||
380 | } |
||
381 | } |
||
382 | |||
383 | [OptionNode("DebugInformation")] |
||
384 | private bool m_DebugInformation; |
||
385 | |||
386 | /// <summary> |
||
387 | /// |
||
388 | /// </summary> |
||
389 | public bool DebugInformation |
||
390 | { |
||
391 | get |
||
392 | { |
||
393 | return m_DebugInformation; |
||
394 | } |
||
395 | set |
||
396 | { |
||
397 | m_DebugInformation = value; |
||
398 | } |
||
399 | } |
||
400 | |||
401 | [OptionNode("RegisterComInterop")] |
||
402 | private bool m_RegisterComInterop; |
||
403 | |||
404 | /// <summary> |
||
405 | /// |
||
406 | /// </summary> |
||
407 | public bool RegisterComInterop |
||
408 | { |
||
409 | get |
||
410 | { |
||
411 | return m_RegisterComInterop; |
||
412 | } |
||
413 | set |
||
414 | { |
||
415 | m_RegisterComInterop = value; |
||
416 | } |
||
417 | } |
||
418 | |||
419 | [OptionNode("RemoveIntegerChecks")] |
||
420 | private bool m_RemoveIntegerChecks; |
||
421 | |||
422 | /// <summary> |
||
423 | /// |
||
424 | /// </summary> |
||
425 | public bool RemoveIntegerChecks |
||
426 | { |
||
427 | get |
||
428 | { |
||
429 | return m_RemoveIntegerChecks; |
||
430 | } |
||
431 | set |
||
432 | { |
||
433 | m_RemoveIntegerChecks = value; |
||
434 | } |
||
435 | } |
||
436 | |||
437 | [OptionNode("IncrementalBuild")] |
||
438 | private bool m_IncrementalBuild; |
||
439 | |||
440 | /// <summary> |
||
441 | /// |
||
442 | /// </summary> |
||
443 | public bool IncrementalBuild |
||
444 | { |
||
445 | get |
||
446 | { |
||
447 | return m_IncrementalBuild; |
||
448 | } |
||
449 | set |
||
450 | { |
||
451 | m_IncrementalBuild = value; |
||
452 | } |
||
453 | } |
||
454 | |||
455 | [OptionNode("BaseAddress")] |
||
456 | private string m_BaseAddress = "285212672"; |
||
457 | |||
458 | /// <summary> |
||
459 | /// |
||
460 | /// </summary> |
||
461 | public string BaseAddress |
||
462 | { |
||
463 | get |
||
464 | { |
||
465 | return m_BaseAddress; |
||
466 | } |
||
467 | set |
||
468 | { |
||
469 | m_BaseAddress = value; |
||
470 | } |
||
471 | } |
||
472 | |||
473 | [OptionNode("FileAlignment")] |
||
474 | private int m_FileAlignment = 4096; |
||
475 | |||
476 | /// <summary> |
||
477 | /// |
||
478 | /// </summary> |
||
479 | public int FileAlignment |
||
480 | { |
||
481 | get |
||
482 | { |
||
483 | return m_FileAlignment; |
||
484 | } |
||
485 | set |
||
486 | { |
||
487 | m_FileAlignment = value; |
||
488 | } |
||
489 | } |
||
490 | |||
491 | [OptionNode("NoStdLib")] |
||
492 | private bool m_NoStdLib; |
||
493 | |||
494 | /// <summary> |
||
495 | /// |
||
496 | /// </summary> |
||
497 | public bool NoStdLib |
||
498 | { |
||
499 | get |
||
500 | { |
||
501 | return m_NoStdLib; |
||
502 | } |
||
503 | set |
||
504 | { |
||
505 | m_NoStdLib = value; |
||
506 | } |
||
507 | } |
||
508 | |||
509 | [OptionNode("PlatformTarget")] |
||
510 | private string m_PlatformTarget = "AnyCPU"; |
||
511 | |||
512 | /// <summary> |
||
513 | /// |
||
514 | /// </summary> |
||
515 | public string PlatformTarget |
||
516 | { |
||
517 | get |
||
518 | { |
||
519 | return m_PlatformTarget; |
||
520 | } |
||
521 | set |
||
522 | { |
||
523 | m_PlatformTarget = value; |
||
524 | } |
||
525 | } |
||
526 | |||
527 | private StringCollection m_FieldsDefined; |
||
528 | |||
529 | #endregion |
||
530 | |||
531 | #region Constructors |
||
532 | |||
533 | /// <summary> |
||
534 | /// Initializes the <see cref="OptionsNode"/> class. |
||
535 | /// </summary> |
||
536 | static OptionsNode() |
||
537 | { |
||
538 | Type t = typeof(OptionsNode); |
||
539 | |||
540 | m_OptionFields = new Hashtable(); |
||
541 | foreach(FieldInfo f in t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) |
||
542 | { |
||
543 | object[] attrs = f.GetCustomAttributes(typeof(OptionNodeAttribute), false); |
||
544 | if(attrs == null || attrs.Length < 1) |
||
545 | { |
||
546 | continue; |
||
547 | } |
||
548 | |||
549 | OptionNodeAttribute ona = (OptionNodeAttribute)attrs[0]; |
||
550 | m_OptionFields[ona.NodeName] = f; |
||
551 | } |
||
552 | } |
||
553 | |||
554 | /// <summary> |
||
555 | /// Initializes a new instance of the <see cref="OptionsNode"/> class. |
||
556 | /// </summary> |
||
557 | public OptionsNode() |
||
558 | { |
||
559 | m_FieldsDefined = new StringCollection(); |
||
560 | } |
||
561 | |||
562 | #endregion |
||
563 | |||
564 | #region Properties |
||
565 | |||
566 | /// <summary> |
||
567 | /// Gets the <see cref="Object"/> at the specified index. |
||
568 | /// </summary> |
||
569 | /// <value></value> |
||
570 | public object this[string index] |
||
571 | { |
||
572 | get |
||
573 | { |
||
574 | if(!m_OptionFields.ContainsKey(index)) |
||
575 | { |
||
576 | return null; |
||
577 | } |
||
578 | |||
579 | FieldInfo f = (FieldInfo)m_OptionFields[index]; |
||
580 | return f.GetValue(this); |
||
581 | } |
||
582 | } |
||
583 | |||
584 | /// <summary> |
||
585 | /// Gets the <see cref="Object"/> at the specified index. |
||
586 | /// </summary> |
||
587 | /// <value></value> |
||
588 | public object this[string index, object defaultValue] |
||
589 | { |
||
590 | get |
||
591 | { |
||
592 | object valueObject = this[index]; |
||
593 | if(valueObject != null && valueObject is string && ((string)valueObject).Length == 0) |
||
594 | { |
||
595 | return defaultValue; |
||
596 | } |
||
597 | return valueObject; |
||
598 | } |
||
599 | } |
||
600 | |||
601 | |||
602 | #endregion |
||
603 | |||
604 | #region Private Methods |
||
605 | |||
606 | private void FlagDefined(string name) |
||
607 | { |
||
608 | if(!m_FieldsDefined.Contains(name)) |
||
609 | { |
||
610 | m_FieldsDefined.Add(name); |
||
611 | } |
||
612 | } |
||
613 | |||
614 | private void SetOption(string nodeName, string val) |
||
615 | { |
||
616 | lock(m_OptionFields) |
||
617 | { |
||
618 | if(!m_OptionFields.ContainsKey(nodeName)) |
||
619 | { |
||
620 | return; |
||
621 | } |
||
622 | |||
623 | FieldInfo f = (FieldInfo)m_OptionFields[nodeName]; |
||
624 | f.SetValue(this, Helper.TranslateValue(f.FieldType, val)); |
||
625 | FlagDefined(f.Name); |
||
626 | } |
||
627 | } |
||
628 | |||
629 | #endregion |
||
630 | |||
631 | #region Public Methods |
||
632 | |||
633 | /// <summary> |
||
634 | /// Parses the specified node. |
||
635 | /// </summary> |
||
636 | /// <param name="node">The node.</param> |
||
637 | public override void Parse(XmlNode node) |
||
638 | { |
||
639 | if( node == null ) |
||
640 | { |
||
641 | throw new ArgumentNullException("node"); |
||
642 | } |
||
643 | |||
644 | foreach(XmlNode child in node.ChildNodes) |
||
645 | { |
||
646 | SetOption(child.Name, Helper.InterpolateForEnvironmentVariables(child.InnerText)); |
||
647 | } |
||
648 | } |
||
649 | |||
650 | /// <summary> |
||
651 | /// Copies to. |
||
652 | /// </summary> |
||
653 | /// <param name="opt">The opt.</param> |
||
654 | public void CopyTo(OptionsNode opt) |
||
655 | { |
||
656 | if(opt == null) |
||
657 | { |
||
658 | return; |
||
659 | } |
||
660 | |||
661 | foreach(FieldInfo f in m_OptionFields.Values) |
||
662 | { |
||
663 | if(m_FieldsDefined.Contains(f.Name)) |
||
664 | { |
||
665 | f.SetValue(opt, f.GetValue(this)); |
||
666 | opt.m_FieldsDefined.Add(f.Name); |
||
667 | } |
||
668 | } |
||
669 | } |
||
670 | |||
671 | #endregion |
||
672 | } |
||
673 | } |