aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Utilities')
-rw-r--r--Prebuild/src/Core/Utilities/CommandLineCollection.cs254
-rw-r--r--Prebuild/src/Core/Utilities/CurrentDirectory.cs80
-rw-r--r--Prebuild/src/Core/Utilities/Helper.cs1036
-rw-r--r--Prebuild/src/Core/Utilities/Log.cs434
4 files changed, 902 insertions, 902 deletions
diff --git a/Prebuild/src/Core/Utilities/CommandLineCollection.cs b/Prebuild/src/Core/Utilities/CommandLineCollection.cs
index 786fa1e..5e6face 100644
--- a/Prebuild/src/Core/Utilities/CommandLineCollection.cs
+++ b/Prebuild/src/Core/Utilities/CommandLineCollection.cs
@@ -5,16 +5,16 @@ Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehea
5Redistribution and use in source and binary forms, with or without modification, are permitted 5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met: 6provided that the following conditions are met:
7 7
8* Redistributions of source code must retain the above copyright notice, this list of conditions 8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer. 9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions 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 11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution. 12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software 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. 14 without specific prior written permission.
15 15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 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 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, 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 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 20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
@@ -27,126 +27,126 @@ using System.Collections;
27using System.Collections.Generic; 27using System.Collections.Generic;
28 28
29namespace Prebuild.Core.Utilities 29namespace Prebuild.Core.Utilities
30{ 30{
31 /// <summary> 31 /// <summary>
32 /// The CommandLine class parses and interprets the command-line arguments passed to 32 /// The CommandLine class parses and interprets the command-line arguments passed to
33 /// prebuild. 33 /// prebuild.
34 /// </summary> 34 /// </summary>
35 public class CommandLineCollection : IEnumerable<KeyValuePair<string, string>> 35 public class CommandLineCollection : IEnumerable<KeyValuePair<string, string>>
36 { 36 {
37 #region Fields 37 #region Fields
38 38
39 // The raw OS arguments 39 // The raw OS arguments
40 private readonly string[] m_RawArgs; 40 private readonly string[] m_RawArgs;
41 41
42 // Command-line argument storage 42 // Command-line argument storage
43 private readonly Dictionary<string, string> m_Arguments = new Dictionary<string, string>(); 43 private readonly Dictionary<string, string> m_Arguments = new Dictionary<string, string>();
44 44
45 #endregion 45 #endregion
46 46
47 #region Constructors 47 #region Constructors
48 48
49 /// <summary> 49 /// <summary>
50 /// Create a new CommandLine instance and set some internal variables. 50 /// Create a new CommandLine instance and set some internal variables.
51 /// </summary> 51 /// </summary>
52 public CommandLineCollection(string[] args) 52 public CommandLineCollection(string[] args)
53 { 53 {
54 m_RawArgs = args; 54 m_RawArgs = args;
55 55
56 Parse(); 56 Parse();
57 } 57 }
58 58
59 #endregion 59 #endregion
60 60
61 #region Private Methods 61 #region Private Methods
62 62
63 private void Parse() 63 private void Parse()
64 { 64 {
65 if(m_RawArgs.Length < 1) 65 if(m_RawArgs.Length < 1)
66 return; 66 return;
67 67
68 int idx = 0; 68 int idx = 0;
69 string lastArg = null; 69 string lastArg = null;
70 70
71 while(idx <m_RawArgs.Length) 71 while(idx <m_RawArgs.Length)
72 { 72 {
73 string arg = m_RawArgs[idx]; 73 string arg = m_RawArgs[idx];
74 74
75 if(arg.Length > 2 && arg[0] == '/') 75 if(arg.Length > 2 && arg[0] == '/')
76 { 76 {
77 arg = arg.Substring(1); 77 arg = arg.Substring(1);
78 lastArg = arg; 78 lastArg = arg;
79 m_Arguments[arg] = ""; 79 m_Arguments[arg] = "";
80 } 80 }
81 else 81 else
82 { 82 {
83 if(lastArg != null) 83 if(lastArg != null)
84 { 84 {
85 m_Arguments[lastArg] = arg; 85 m_Arguments[lastArg] = arg;
86 lastArg = null; 86 lastArg = null;
87 } 87 }
88 } 88 }
89 89
90 idx++; 90 idx++;
91 } 91 }
92 } 92 }
93 93
94 #endregion 94 #endregion
95 95
96 #region Public Methods 96 #region Public Methods
97 97
98 /// <summary> 98 /// <summary>
99 /// Wases the passed. 99 /// Wases the passed.
100 /// </summary> 100 /// </summary>
101 /// <param name="arg">The arg.</param> 101 /// <param name="arg">The arg.</param>
102 /// <returns></returns> 102 /// <returns></returns>
103 public bool WasPassed(string arg) 103 public bool WasPassed(string arg)
104 { 104 {
105 return (m_Arguments.ContainsKey(arg)); 105 return (m_Arguments.ContainsKey(arg));
106 } 106 }
107 107
108 #endregion 108 #endregion
109 109
110 #region Properties 110 #region Properties
111 111
112 /// <summary> 112 /// <summary>
113 /// Gets the parameter associated with the command line option 113 /// Gets the parameter associated with the command line option
114 /// </summary> 114 /// </summary>
115 /// <remarks>Returns null if option was not specified, 115 /// <remarks>Returns null if option was not specified,
116 /// null string if no parameter was specified, and the value if a parameter was specified</remarks> 116 /// null string if no parameter was specified, and the value if a parameter was specified</remarks>
117 public string this[string index] 117 public string this[string index]
118 { 118 {
119 get 119 get
120 { 120 {
121 if(m_Arguments.ContainsKey(index)) 121 if(m_Arguments.ContainsKey(index))
122 { 122 {
123 return (m_Arguments[index]); 123 return (m_Arguments[index]);
124 } 124 }
125 return null; 125 return null;
126 } 126 }
127 } 127 }
128 128
129 #endregion 129 #endregion
130 130
131 #region IEnumerable Members 131 #region IEnumerable Members
132 132
133 /// <summary> 133 /// <summary>
134 /// Returns an enumerator that can iterate through a collection. 134 /// Returns an enumerator that can iterate through a collection.
135 /// </summary> 135 /// </summary>
136 /// <returns> 136 /// <returns>
137 /// An <see cref="T:System.Collections.IDictionaryEnumerator"/> 137 /// An <see cref="T:System.Collections.IDictionaryEnumerator"/>
138 /// that can be used to iterate through the collection. 138 /// that can be used to iterate through the collection.
139 /// </returns> 139 /// </returns>
140 public IEnumerator<KeyValuePair<string, string>> GetEnumerator() 140 public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
141 { 141 {
142 return m_Arguments.GetEnumerator(); 142 return m_Arguments.GetEnumerator();
143 } 143 }
144 144
145 IEnumerator IEnumerable.GetEnumerator() 145 IEnumerator IEnumerable.GetEnumerator()
146 { 146 {
147 return GetEnumerator(); 147 return GetEnumerator();
148 } 148 }
149 149
150 #endregion 150 #endregion
151 } 151 }
152} 152}
diff --git a/Prebuild/src/Core/Utilities/CurrentDirectory.cs b/Prebuild/src/Core/Utilities/CurrentDirectory.cs
index 9624c35..d743d83 100644
--- a/Prebuild/src/Core/Utilities/CurrentDirectory.cs
+++ b/Prebuild/src/Core/Utilities/CurrentDirectory.cs
@@ -5,16 +5,16 @@ Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehea
5Redistribution and use in source and binary forms, with or without modification, are permitted 5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met: 6provided that the following conditions are met:
7 7
8* Redistributions of source code must retain the above copyright notice, this list of conditions 8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer. 9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions 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 11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution. 12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software 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. 14 without specific prior written permission.
15 15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 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 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, 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 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 20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
@@ -28,41 +28,41 @@ using System.Collections.Generic;
28 28
29namespace Prebuild.Core.Utilities 29namespace Prebuild.Core.Utilities
30{ 30{
31 /// <summary> 31 /// <summary>
32 /// 32 ///
33 /// </summary> 33 /// </summary>
34 public class CurrentDirectory 34 public class CurrentDirectory
35 { 35 {
36 #region Fields 36 #region Fields
37 37
38 private readonly Stack<string> m_Stack = new Stack<string>(); 38 private readonly Stack<string> m_Stack = new Stack<string>();
39 39
40 #endregion 40 #endregion
41 41
42 #region Public Methods 42 #region Public Methods
43 43
44 /// <summary> 44 /// <summary>
45 /// Pushes this instance. 45 /// Pushes this instance.
46 /// </summary> 46 /// </summary>
47 public void Push() 47 public void Push()
48 { 48 {
49 m_Stack.Push(Environment.CurrentDirectory); 49 m_Stack.Push(Environment.CurrentDirectory);
50 } 50 }
51 51
52 /// <summary> 52 /// <summary>
53 /// Pops this instance. 53 /// Pops this instance.
54 /// </summary> 54 /// </summary>
55 public void Pop() 55 public void Pop()
56 { 56 {
57 if(m_Stack.Count < 1) 57 if(m_Stack.Count < 1)
58 { 58 {
59 return; 59 return;
60 } 60 }
61
62 string cwd = m_Stack.Pop();
63 Helper.SetCurrentDir(cwd);
64 }
65 61
66 #endregion 62 string cwd = m_Stack.Pop();
67 } 63 Helper.SetCurrentDir(cwd);
64 }
65
66 #endregion
67 }
68} 68}
diff --git a/Prebuild/src/Core/Utilities/Helper.cs b/Prebuild/src/Core/Utilities/Helper.cs
index 8c3e968..a440e58 100644
--- a/Prebuild/src/Core/Utilities/Helper.cs
+++ b/Prebuild/src/Core/Utilities/Helper.cs
@@ -5,16 +5,16 @@ Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehea
5Redistribution and use in source and binary forms, with or without modification, are permitted 5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met: 6provided that the following conditions are met:
7 7
8* Redistributions of source code must retain the above copyright notice, this list of conditions 8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer. 9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions 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 11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution. 12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software 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. 14 without specific prior written permission.
15 15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 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 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, 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 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 20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
@@ -35,541 +35,541 @@ using Prebuild.Core.Nodes;
35 35
36namespace Prebuild.Core.Utilities 36namespace Prebuild.Core.Utilities
37{ 37{
38 /// <summary> 38 /// <summary>
39 /// 39 ///
40 /// </summary> 40 /// </summary>
41 public class Helper 41 public class Helper
42 { 42 {
43 #region Fields 43 #region Fields
44 44
45 static bool checkForOSVariables; 45 static bool checkForOSVariables;
46 46
47 /// <summary> 47 /// <summary>
48 /// 48 ///
49 /// </summary> 49 /// </summary>
50 public static bool CheckForOSVariables 50 public static bool CheckForOSVariables
51 { 51 {
52 get 52 get
53 { 53 {
54 return checkForOSVariables; 54 return checkForOSVariables;
55 } 55 }
56 set 56 set
57 { 57 {
58 checkForOSVariables = value; 58 checkForOSVariables = value;
59 } 59 }
60 } 60 }
61 61
62 #endregion 62 #endregion
63 63
64 #region Public Methods 64 #region Public Methods
65 65
66 #region String Parsing 66 #region String Parsing
67 67
68 public delegate string StringLookup(string key); 68 public delegate string StringLookup(string key);
69 69
70 /// <summary> 70 /// <summary>
71 /// Gets a collection of StringLocationPair objects that represent the matches 71 /// Gets a collection of StringLocationPair objects that represent the matches
72 /// </summary> 72 /// </summary>
73 /// <param name="target">The target.</param> 73 /// <param name="target">The target.</param>
74 /// <param name="beforeGroup">The before group.</param> 74 /// <param name="beforeGroup">The before group.</param>
75 /// <param name="afterGroup">The after group.</param> 75 /// <param name="afterGroup">The after group.</param>
76 /// <param name="includeDelimitersInSubstrings">if set to <c>true</c> [include delimiters in substrings].</param> 76 /// <param name="includeDelimitersInSubstrings">if set to <c>true</c> [include delimiters in substrings].</param>
77 /// <returns></returns> 77 /// <returns></returns>
78 public static StringCollection FindGroups(string target, string beforeGroup, string afterGroup, bool includeDelimitersInSubstrings) 78 public static StringCollection FindGroups(string target, string beforeGroup, string afterGroup, bool includeDelimitersInSubstrings)
79 { 79 {
80 if( beforeGroup == null ) 80 if( beforeGroup == null )
81 { 81 {
82 throw new ArgumentNullException("beforeGroup"); 82 throw new ArgumentNullException("beforeGroup");
83 } 83 }
84 if( afterGroup == null ) 84 if( afterGroup == null )
85 { 85 {
86 throw new ArgumentNullException("afterGroup"); 86 throw new ArgumentNullException("afterGroup");
87 } 87 }
88 StringCollection results = new StringCollection(); 88 StringCollection results = new StringCollection();
89 if(target == null || target.Length == 0) 89 if(target == null || target.Length == 0)
90 { 90 {
91 return results; 91 return results;
92 } 92 }
93 93
94 int beforeMod = 0; 94 int beforeMod = 0;
95 int afterMod = 0; 95 int afterMod = 0;
96 if(includeDelimitersInSubstrings) 96 if(includeDelimitersInSubstrings)
97 { 97 {
98 //be sure to not exlude the delims 98 //be sure to not exlude the delims
99 beforeMod = beforeGroup.Length; 99 beforeMod = beforeGroup.Length;
100 afterMod = afterGroup.Length; 100 afterMod = afterGroup.Length;
101 } 101 }
102 int startIndex = 0; 102 int startIndex = 0;
103 while((startIndex = target.IndexOf(beforeGroup,startIndex)) != -1) { 103 while((startIndex = target.IndexOf(beforeGroup,startIndex)) != -1) {
104 int endIndex = target.IndexOf(afterGroup,startIndex);//the index of the char after it 104 int endIndex = target.IndexOf(afterGroup,startIndex);//the index of the char after it
105 if(endIndex == -1) 105 if(endIndex == -1)
106 { 106 {
107 break; 107 break;
108 } 108 }
109 int length = endIndex - startIndex - beforeGroup.Length;//move to the first char in the string 109 int length = endIndex - startIndex - beforeGroup.Length;//move to the first char in the string
110 string substring = substring = target.Substring(startIndex + beforeGroup.Length - beforeMod, 110 string substring = substring = target.Substring(startIndex + beforeGroup.Length - beforeMod,
111 length - afterMod); 111 length - afterMod);
112 112
113 results.Add(substring); 113 results.Add(substring);
114 //results.Add(new StringLocationPair(substring,startIndex)); 114 //results.Add(new StringLocationPair(substring,startIndex));
115 startIndex = endIndex + 1; 115 startIndex = endIndex + 1;
116 //the Interpolate*() methods will not work if expressions are expandded inside expression due to an optimization 116 //the Interpolate*() methods will not work if expressions are expandded inside expression due to an optimization
117 //so start after endIndex 117 //so start after endIndex
118 118
119 } 119 }
120 return results; 120 return results;
121 } 121 }
122 122
123 /// <summary> 123 /// <summary>
124 /// Replaces the groups. 124 /// Replaces the groups.
125 /// </summary> 125 /// </summary>
126 /// <param name="target">The target.</param> 126 /// <param name="target">The target.</param>
127 /// <param name="beforeGroup">The before group.</param> 127 /// <param name="beforeGroup">The before group.</param>
128 /// <param name="afterGroup">The after group.</param> 128 /// <param name="afterGroup">The after group.</param>
129 /// <param name="lookup">The lookup.</param> 129 /// <param name="lookup">The lookup.</param>
130 /// <returns></returns> 130 /// <returns></returns>
131 public static string ReplaceGroups(string target, string beforeGroup, string afterGroup, StringLookup lookup) { 131 public static string ReplaceGroups(string target, string beforeGroup, string afterGroup, StringLookup lookup) {
132 if( target == null ) 132 if( target == null )
133 { 133 {
134 throw new ArgumentNullException("target"); 134 throw new ArgumentNullException("target");
135 } 135 }
136 //int targetLength = target.Length; 136 //int targetLength = target.Length;
137 StringCollection strings = FindGroups(target,beforeGroup,afterGroup,false); 137 StringCollection strings = FindGroups(target,beforeGroup,afterGroup,false);
138 if( lookup == null ) 138 if( lookup == null )
139 { 139 {
140 throw new ArgumentNullException("lookup"); 140 throw new ArgumentNullException("lookup");
141 } 141 }
142 foreach(string substring in strings) 142 foreach(string substring in strings)
143 { 143 {
144 target = target.Replace(beforeGroup + substring + afterGroup, lookup(substring) ); 144 target = target.Replace(beforeGroup + substring + afterGroup, lookup(substring) );
145 } 145 }
146 return target; 146 return target;
147 } 147 }
148 148
149 /// <summary> 149 /// <summary>
150 /// Replaces ${var} statements in a string with the corresonding values as detirmined by the lookup delegate 150 /// Replaces ${var} statements in a string with the corresonding values as detirmined by the lookup delegate
151 /// </summary> 151 /// </summary>
152 /// <param name="target">The target.</param> 152 /// <param name="target">The target.</param>
153 /// <param name="lookup">The lookup.</param> 153 /// <param name="lookup">The lookup.</param>
154 /// <returns></returns> 154 /// <returns></returns>
155 public static string InterpolateForVariables(string target, StringLookup lookup) 155 public static string InterpolateForVariables(string target, StringLookup lookup)
156 { 156 {
157 return ReplaceGroups(target, "${" , "}" , lookup); 157 return ReplaceGroups(target, "${" , "}" , lookup);
158 } 158 }
159 159
160 /// <summary> 160 /// <summary>
161 /// Replaces ${var} statements in a string with the corresonding environment variable with name var 161 /// Replaces ${var} statements in a string with the corresonding environment variable with name var
162 /// </summary> 162 /// </summary>
163 /// <param name="target"></param> 163 /// <param name="target"></param>
164 /// <returns></returns> 164 /// <returns></returns>
165 public static string InterpolateForEnvironmentVariables(string target) 165 public static string InterpolateForEnvironmentVariables(string target)
166 { 166 {
167 return InterpolateForVariables(target, new StringLookup(Environment.GetEnvironmentVariable)); 167 return InterpolateForVariables(target, new StringLookup(Environment.GetEnvironmentVariable));
168 } 168 }
169 169
170 #endregion 170 #endregion
171 171
172 /// <summary> 172 /// <summary>
173 /// Translates the value. 173 /// Translates the value.
174 /// </summary> 174 /// </summary>
175 /// <param name="translateType">Type of the translate.</param> 175 /// <param name="translateType">Type of the translate.</param>
176 /// <param name="translationItem">The translation item.</param> 176 /// <param name="translationItem">The translation item.</param>
177 /// <returns></returns> 177 /// <returns></returns>
178 public static object TranslateValue(Type translateType, string translationItem) 178 public static object TranslateValue(Type translateType, string translationItem)
179 { 179 {
180 if(translationItem == null) 180 if(translationItem == null)
181 { 181 {
182 return null; 182 return null;
183 } 183 }
184 184
185 try 185 try
186 { 186 {
187 string lowerVal = translationItem.ToLower(); 187 string lowerVal = translationItem.ToLower();
188 if(translateType == typeof(bool)) 188 if(translateType == typeof(bool))
189 { 189 {
190 return (lowerVal == "true" || lowerVal == "1" || lowerVal == "y" || lowerVal == "yes" || lowerVal == "on"); 190 return (lowerVal == "true" || lowerVal == "1" || lowerVal == "y" || lowerVal == "yes" || lowerVal == "on");
191 } 191 }
192 else if(translateType == typeof(int)) 192 else if(translateType == typeof(int))
193 { 193 {
194 return (Int32.Parse(translationItem)); 194 return (Int32.Parse(translationItem));
195 } 195 }
196 else 196 else
197 { 197 {
198 return translationItem; 198 return translationItem;
199 } 199 }
200 } 200 }
201 catch(FormatException) 201 catch(FormatException)
202 { 202 {
203 return null; 203 return null;
204 } 204 }
205 } 205 }
206 206
207 /// <summary> 207 /// <summary>
208 /// Deletes if exists. 208 /// Deletes if exists.
209 /// </summary> 209 /// </summary>
210 /// <param name="file">The file.</param> 210 /// <param name="file">The file.</param>
211 /// <returns></returns> 211 /// <returns></returns>
212 public static bool DeleteIfExists(string file) 212 public static bool DeleteIfExists(string file)
213 { 213 {
214 string resFile = null; 214 string resFile = null;
215 try 215 try
216 { 216 {
217 resFile = ResolvePath(file); 217 resFile = ResolvePath(file);
218 } 218 }
219 catch(ArgumentException) 219 catch(ArgumentException)
220 { 220 {
221 return false; 221 return false;
222 } 222 }
223 223
224 if(!File.Exists(resFile)) 224 if(!File.Exists(resFile))
225 { 225 {
226 return false; 226 return false;
227 } 227 }
228 228
229 File.Delete(resFile); 229 File.Delete(resFile);
230 return true; 230 return true;
231 } 231 }
232 232
233 static readonly char seperator = Path.DirectorySeparatorChar; 233 static readonly char seperator = Path.DirectorySeparatorChar;
234 234
235 // This little gem was taken from the NeL source, thanks guys! 235 // This little gem was taken from the NeL source, thanks guys!
236 /// <summary> 236 /// <summary>
237 /// Makes a relative path 237 /// Makes a relative path
238 /// </summary> 238 /// </summary>
239 /// <param name="startPath">Path to start from</param> 239 /// <param name="startPath">Path to start from</param>
240 /// <param name="endPath">Path to end at</param> 240 /// <param name="endPath">Path to end at</param>
241 /// <returns>Path that will get from startPath to endPath</returns> 241 /// <returns>Path that will get from startPath to endPath</returns>
242 public static string MakePathRelativeTo(string startPath, string endPath) 242 public static string MakePathRelativeTo(string startPath, string endPath)
243 { 243 {
244 string tmp = NormalizePath(startPath, seperator); 244 string tmp = NormalizePath(startPath, seperator);
245 string src = NormalizePath(endPath, seperator); 245 string src = NormalizePath(endPath, seperator);
246 string prefix = ""; 246 string prefix = "";
247 247
248 while(true) 248 while(true)
249 { 249 {
250 if((String.Compare(tmp, 0, src, 0, tmp.Length) == 0)) 250 if((String.Compare(tmp, 0, src, 0, tmp.Length) == 0))
251 { 251 {
252 string ret; 252 string ret;
253 int size = tmp.Length; 253 int size = tmp.Length;
254 if(size == src.Length) 254 if(size == src.Length)
255 { 255 {
256 return "./"; 256 return "./";
257 } 257 }
258 if((src.Length > tmp.Length) && src[tmp.Length - 1] != seperator) 258 if((src.Length > tmp.Length) && src[tmp.Length - 1] != seperator)
259 { 259 {
260 } 260 }
261 else 261 else
262 { 262 {
263 ret = prefix + endPath.Substring(size, endPath.Length - size); 263 ret = prefix + endPath.Substring(size, endPath.Length - size);
264 ret = ret.Trim(); 264 ret = ret.Trim();
265 if(ret[0] == seperator) 265 if(ret[0] == seperator)
266 { 266 {
267 ret = "." + ret; 267 ret = "." + ret;
268 } 268 }
269 269
270 return NormalizePath(ret); 270 return NormalizePath(ret);
271 } 271 }
272
273 }
274 272
275 if(tmp.Length < 2) 273 }
276 { 274
277 break; 275 if(tmp.Length < 2)
278 } 276 {
277 break;
278 }
279 279
280 int lastPos = tmp.LastIndexOf(seperator, tmp.Length - 2); 280 int lastPos = tmp.LastIndexOf(seperator, tmp.Length - 2);
281 int prevPos = tmp.IndexOf(seperator); 281 int prevPos = tmp.IndexOf(seperator);
282 282
283 if((lastPos == prevPos) || (lastPos == -1)) 283 if((lastPos == prevPos) || (lastPos == -1))
284 { 284 {
285 break; 285 break;
286 } 286 }
287 287
288 tmp = tmp.Substring(0, lastPos + 1); 288 tmp = tmp.Substring(0, lastPos + 1);
289 prefix += ".." + seperator.ToString(); 289 prefix += ".." + seperator.ToString();
290 } 290 }
291 291
292 return endPath; 292 return endPath;
293 } 293 }
294 294
295 /// <summary> 295 /// <summary>
296 /// Resolves the path. 296 /// Resolves the path.
297 /// </summary> 297 /// </summary>
298 /// <param name="path">The path.</param> 298 /// <param name="path">The path.</param>
299 /// <returns></returns> 299 /// <returns></returns>
300 public static string ResolvePath(string path) 300 public static string ResolvePath(string path)
301 { 301 {
302 string tmpPath = NormalizePath(path); 302 string tmpPath = NormalizePath(path);
303 if(tmpPath.Length < 1) 303 if(tmpPath.Length < 1)
304 { 304 {
305 tmpPath = "."; 305 tmpPath = ".";
306 } 306 }
307 307
308 tmpPath = Path.GetFullPath(tmpPath); 308 tmpPath = Path.GetFullPath(tmpPath);
309 if(!File.Exists(tmpPath) && !Directory.Exists(tmpPath)) 309 if(!File.Exists(tmpPath) && !Directory.Exists(tmpPath))
310 { 310 {
311 throw new ArgumentException("Path could not be resolved: " + tmpPath); 311 throw new ArgumentException("Path could not be resolved: " + tmpPath);
312 } 312 }
313 313
314 return tmpPath; 314 return tmpPath;
315 } 315 }
316 316
317 /// <summary> 317 /// <summary>
318 /// Normalizes the path. 318 /// Normalizes the path.
319 /// </summary> 319 /// </summary>
320 /// <param name="path">The path.</param> 320 /// <param name="path">The path.</param>
321 /// <param name="separatorCharacter">The separator character.</param> 321 /// <param name="separatorCharacter">The separator character.</param>
322 /// <returns></returns> 322 /// <returns></returns>
323 public static string NormalizePath(string path, char separatorCharacter) 323 public static string NormalizePath(string path, char separatorCharacter)
324 { 324 {
325 if(path == null || path == "" || path.Length < 1) 325 if(path == null || path == "" || path.Length < 1)
326 { 326 {
327 return ""; 327 return "";
328 } 328 }
329 329
330 string tmpPath = path.Replace('\\', '/'); 330 string tmpPath = path.Replace('\\', '/');
331 tmpPath = tmpPath.Replace('/', separatorCharacter); 331 tmpPath = tmpPath.Replace('/', separatorCharacter);
332 return tmpPath; 332 return tmpPath;
333 } 333 }
334 334
335 /// <summary> 335 /// <summary>
336 /// Normalizes the path. 336 /// Normalizes the path.
337 /// </summary> 337 /// </summary>
338 /// <param name="path">The path.</param> 338 /// <param name="path">The path.</param>
339 /// <returns></returns> 339 /// <returns></returns>
340 public static string NormalizePath(string path) 340 public static string NormalizePath(string path)
341 { 341 {
342 return NormalizePath(path, Path.DirectorySeparatorChar); 342 return NormalizePath(path, Path.DirectorySeparatorChar);
343 } 343 }
344 344
345 /// <summary> 345 /// <summary>
346 /// Ends the path. 346 /// Ends the path.
347 /// </summary> 347 /// </summary>
348 /// <param name="path">The path.</param> 348 /// <param name="path">The path.</param>
349 /// <param name="separatorCharacter">The separator character.</param> 349 /// <param name="separatorCharacter">The separator character.</param>
350 /// <returns></returns> 350 /// <returns></returns>
351 public static string EndPath(string path, char separatorCharacter) 351 public static string EndPath(string path, char separatorCharacter)
352 { 352 {
353 if(path == null || path == "" || path.Length < 1) 353 if(path == null || path == "" || path.Length < 1)
354 { 354 {
355 return ""; 355 return "";
356 } 356 }
357 357
358 if(!path.EndsWith(separatorCharacter.ToString())) 358 if(!path.EndsWith(separatorCharacter.ToString()))
359 { 359 {
360 return (path + separatorCharacter); 360 return (path + separatorCharacter);
361 } 361 }
362 362
363 return path; 363 return path;
364 } 364 }
365 365
366 /// <summary> 366 /// <summary>
367 /// Ends the path. 367 /// Ends the path.
368 /// </summary> 368 /// </summary>
369 /// <param name="path">The path.</param> 369 /// <param name="path">The path.</param>
370 /// <returns></returns> 370 /// <returns></returns>
371 public static string EndPath(string path) 371 public static string EndPath(string path)
372 { 372 {
373 return EndPath(path, Path.DirectorySeparatorChar); 373 return EndPath(path, Path.DirectorySeparatorChar);
374 } 374 }
375 375
376 /// <summary> 376 /// <summary>
377 /// Makes the file path. 377 /// Makes the file path.
378 /// </summary> 378 /// </summary>
379 /// <param name="path">The path.</param> 379 /// <param name="path">The path.</param>
380 /// <param name="name">The name.</param> 380 /// <param name="name">The name.</param>
381 /// <param name="ext">The ext.</param> 381 /// <param name="ext">The ext.</param>
382 /// <returns></returns> 382 /// <returns></returns>
383 public static string MakeFilePath(string path, string name, string ext) 383 public static string MakeFilePath(string path, string name, string ext)
384 { 384 {
385 string ret = EndPath(NormalizePath(path)); 385 string ret = EndPath(NormalizePath(path));
386 386
387 if( name == null ) 387 if( name == null )
388 { 388 {
389 throw new ArgumentNullException("name"); 389 throw new ArgumentNullException("name");
390 } 390 }
391 391
392 ret += name; 392 ret += name;
393 if(!name.EndsWith("." + ext)) 393 if(!name.EndsWith("." + ext))
394 { 394 {
395 ret += "." + ext; 395 ret += "." + ext;
396 } 396 }
397 397
398 //foreach(char c in Path.GetInvalidPathChars()) 398 //foreach(char c in Path.GetInvalidPathChars())
399 //{ 399 //{
400 // ret = ret.Replace(c, '_'); 400 // ret = ret.Replace(c, '_');
401 //} 401 //}
402 402
403 return ret; 403 return ret;
404 } 404 }
405 405
406 /// <summary> 406 /// <summary>
407 /// Makes the file path. 407 /// Makes the file path.
408 /// </summary> 408 /// </summary>
409 /// <param name="path">The path.</param> 409 /// <param name="path">The path.</param>
410 /// <param name="name">The name.</param> 410 /// <param name="name">The name.</param>
411 /// <returns></returns> 411 /// <returns></returns>
412 public static string MakeFilePath(string path, string name) 412 public static string MakeFilePath(string path, string name)
413 { 413 {
414 string ret = EndPath(NormalizePath(path)); 414 string ret = EndPath(NormalizePath(path));
415 415
416 if( name == null ) 416 if( name == null )
417 { 417 {
418 throw new ArgumentNullException("name"); 418 throw new ArgumentNullException("name");
419 } 419 }
420 420
421 ret += name; 421 ret += name;
422 422
423 //foreach (char c in Path.GetInvalidPathChars()) 423 //foreach (char c in Path.GetInvalidPathChars())
424 //{ 424 //{
425 // ret = ret.Replace(c, '_'); 425 // ret = ret.Replace(c, '_');
426 //} 426 //}
427 427
428 return ret; 428 return ret;
429 } 429 }
430 430
431 /// <summary> 431 /// <summary>
432 /// 432 ///
433 /// </summary> 433 /// </summary>
434 /// <param name="path"></param> 434 /// <param name="path"></param>
435 /// <returns></returns> 435 /// <returns></returns>
436 public static string MakeReferencePath(string path) 436 public static string MakeReferencePath(string path)
437 { 437 {
438 string ret = EndPath(NormalizePath(path)); 438 string ret = EndPath(NormalizePath(path));
439 439
440 //foreach (char c in Path.GetInvalidPathChars()) 440 //foreach (char c in Path.GetInvalidPathChars())
441 //{ 441 //{
442 // ret = ret.Replace(c, '_'); 442 // ret = ret.Replace(c, '_');
443 //} 443 //}
444 444
445 return ret; 445 return ret;
446 } 446 }
447 447
448 /// <summary> 448 /// <summary>
449 /// Sets the current dir. 449 /// Sets the current dir.
450 /// </summary> 450 /// </summary>
451 /// <param name="path">The path.</param> 451 /// <param name="path">The path.</param>
452 public static void SetCurrentDir(string path) 452 public static void SetCurrentDir(string path)
453 { 453 {
454 if( path == null ) 454 if( path == null )
455 { 455 {
456 throw new ArgumentNullException("path"); 456 throw new ArgumentNullException("path");
457 } 457 }
458 if(path.Length < 1) 458 if(path.Length < 1)
459 { 459 {
460 return; 460 return;
461 } 461 }
462 462
463 Environment.CurrentDirectory = path; 463 Environment.CurrentDirectory = path;
464 } 464 }
465 465
466 /// <summary> 466 /// <summary>
467 /// Checks the type. 467 /// Checks the type.
468 /// </summary> 468 /// </summary>
469 /// <param name="typeToCheck">The type to check.</param> 469 /// <param name="typeToCheck">The type to check.</param>
470 /// <param name="attr">The attr.</param> 470 /// <param name="attr">The attr.</param>
471 /// <param name="inter">The inter.</param> 471 /// <param name="inter">The inter.</param>
472 /// <returns></returns> 472 /// <returns></returns>
473 public static object CheckType(Type typeToCheck, Type attr, Type inter) 473 public static object CheckType(Type typeToCheck, Type attr, Type inter)
474 { 474 {
475 if(typeToCheck == null || attr == null) 475 if(typeToCheck == null || attr == null)
476 { 476 {
477 return null; 477 return null;
478 } 478 }
479 479
480 object[] attrs = typeToCheck.GetCustomAttributes(attr, false); 480 object[] attrs = typeToCheck.GetCustomAttributes(attr, false);
481 if(attrs == null || attrs.Length < 1) 481 if(attrs == null || attrs.Length < 1)
482 { 482 {
483 return null; 483 return null;
484 } 484 }
485 if( inter == null ) 485 if( inter == null )
486 { 486 {
487 throw new ArgumentNullException("inter"); 487 throw new ArgumentNullException("inter");
488 } 488 }
489 489
490 if(typeToCheck.GetInterface(inter.FullName) == null) 490 if(typeToCheck.GetInterface(inter.FullName) == null)
491 { 491 {
492 return null; 492 return null;
493 } 493 }
494 494
495 return attrs[0]; 495 return attrs[0];
496 } 496 }
497 497
498 /// <summary> 498 /// <summary>
499 /// Attributes the value. 499 /// Attributes the value.
500 /// </summary> 500 /// </summary>
501 /// <param name="node">The node.</param> 501 /// <param name="node">The node.</param>
502 /// <param name="attr">The attr.</param> 502 /// <param name="attr">The attr.</param>
503 /// <param name="def">The def.</param> 503 /// <param name="def">The def.</param>
504 /// <returns></returns> 504 /// <returns></returns>
505 public static string AttributeValue(XmlNode node, string attr, string def) 505 public static string AttributeValue(XmlNode node, string attr, string def)
506 { 506 {
507 if( node == null ) 507 if( node == null )
508 { 508 {
509 throw new ArgumentNullException("node"); 509 throw new ArgumentNullException("node");
510 } 510 }
511 if(node.Attributes[attr] == null) 511 if(node.Attributes[attr] == null)
512 { 512 {
513 return def; 513 return def;
514 } 514 }
515 string val = node.Attributes[attr].Value; 515 string val = node.Attributes[attr].Value;
516 if(!CheckForOSVariables) 516 if(!CheckForOSVariables)
517 { 517 {
518 return val; 518 return val;
519 } 519 }
520 520
521 return InterpolateForEnvironmentVariables(val); 521 return InterpolateForEnvironmentVariables(val);
522 } 522 }
523 523
524 /// <summary> 524 /// <summary>
525 /// Parses the boolean. 525 /// Parses the boolean.
526 /// </summary> 526 /// </summary>
527 /// <param name="node">The node.</param> 527 /// <param name="node">The node.</param>
528 /// <param name="attr">The attr.</param> 528 /// <param name="attr">The attr.</param>
529 /// <param name="defaultValue">if set to <c>true</c> [default value].</param> 529 /// <param name="defaultValue">if set to <c>true</c> [default value].</param>
530 /// <returns></returns> 530 /// <returns></returns>
531 public static bool ParseBoolean(XmlNode node, string attr, bool defaultValue) 531 public static bool ParseBoolean(XmlNode node, string attr, bool defaultValue)
532 { 532 {
533 if( node == null ) 533 if( node == null )
534 { 534 {
535 throw new ArgumentNullException("node"); 535 throw new ArgumentNullException("node");
536 } 536 }
537 if(node.Attributes[attr] == null) 537 if(node.Attributes[attr] == null)
538 { 538 {
539 return defaultValue; 539 return defaultValue;
540 } 540 }
541 return bool.Parse(node.Attributes[attr].Value); 541 return bool.Parse(node.Attributes[attr].Value);
542 } 542 }
543 543
544 /// <summary> 544 /// <summary>
545 /// Enums the attribute value. 545 /// Enums the attribute value.
546 /// </summary> 546 /// </summary>
547 /// <param name="node">The node.</param> 547 /// <param name="node">The node.</param>
548 /// <param name="attr">The attr.</param> 548 /// <param name="attr">The attr.</param>
549 /// <param name="enumType">Type of the enum.</param> 549 /// <param name="enumType">Type of the enum.</param>
550 /// <param name="def">The def.</param> 550 /// <param name="def">The def.</param>
551 /// <returns></returns> 551 /// <returns></returns>
552 public static object EnumAttributeValue(XmlNode node, string attr, Type enumType, object def) 552 public static object EnumAttributeValue(XmlNode node, string attr, Type enumType, object def)
553 { 553 {
554 if( def == null ) 554 if( def == null )
555 { 555 {
556 throw new ArgumentNullException("def"); 556 throw new ArgumentNullException("def");
557 } 557 }
558 string val = AttributeValue(node, attr, def.ToString()); 558 string val = AttributeValue(node, attr, def.ToString());
559 return Enum.Parse(enumType, val, true); 559 return Enum.Parse(enumType, val, true);
560 } 560 }
561 561
562 /// <summary> 562 /// <summary>
563 /// 563 ///
564 /// </summary> 564 /// </summary>
565 /// <param name="assemblyName"></param> 565 /// <param name="assemblyName"></param>
566 /// <param name="projectType"></param> 566 /// <param name="projectType"></param>
567 /// <returns></returns> 567 /// <returns></returns>
568 public static string AssemblyFullName(string assemblyName, ProjectType projectType) 568 public static string AssemblyFullName(string assemblyName, ProjectType projectType)
569 { 569 {
570 return assemblyName + (projectType == ProjectType.Library ? ".dll" : ".exe"); 570 return assemblyName + (projectType == ProjectType.Library ? ".dll" : ".exe");
571 } 571 }
572 572
573 #endregion 573 #endregion
574 } 574 }
575} 575}
diff --git a/Prebuild/src/Core/Utilities/Log.cs b/Prebuild/src/Core/Utilities/Log.cs
index 4df3def..cd95633 100644
--- a/Prebuild/src/Core/Utilities/Log.cs
+++ b/Prebuild/src/Core/Utilities/Log.cs
@@ -5,16 +5,16 @@ Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehea
5Redistribution and use in source and binary forms, with or without modification, are permitted 5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met: 6provided that the following conditions are met:
7 7
8* Redistributions of source code must retain the above copyright notice, this list of conditions 8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer. 9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions 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 11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution. 12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software 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. 14 without specific prior written permission.
15 15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 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 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, 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 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 20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
@@ -28,74 +28,74 @@ using System.IO;
28 28
29namespace Prebuild.Core.Utilities 29namespace Prebuild.Core.Utilities
30{ 30{
31 /// <summary> 31 /// <summary>
32 /// 32 ///
33 /// </summary> 33 /// </summary>
34 public enum LogType 34 public enum LogType
35 { 35 {
36 /// <summary> 36 /// <summary>
37 /// 37 ///
38 /// </summary> 38 /// </summary>
39 None, 39 None,
40 /// <summary> 40 /// <summary>
41 /// 41 ///
42 /// </summary> 42 /// </summary>
43 Info, 43 Info,
44 /// <summary> 44 /// <summary>
45 /// 45 ///
46 /// </summary> 46 /// </summary>
47 Warning, 47 Warning,
48 /// <summary> 48 /// <summary>
49 /// 49 ///
50 /// </summary> 50 /// </summary>
51 Error 51 Error
52 } 52 }
53 53
54 /// <summary> 54 /// <summary>
55 /// 55 ///
56 /// </summary> 56 /// </summary>
57 [Flags] 57 [Flags]
58 public enum LogTargets 58 public enum LogTargets
59 { 59 {
60 /// <summary> 60 /// <summary>
61 /// 61 ///
62 /// </summary> 62 /// </summary>
63 None = 0, 63 None = 0,
64 /// <summary> 64 /// <summary>
65 /// 65 ///
66 /// </summary> 66 /// </summary>
67 Null = 1, 67 Null = 1,
68 /// <summary> 68 /// <summary>
69 /// 69 ///
70 /// </summary> 70 /// </summary>
71 File = 2, 71 File = 2,
72 /// <summary> 72 /// <summary>
73 /// 73 ///
74 /// </summary> 74 /// </summary>
75 Console = 4 75 Console = 4
76 } 76 }
77 77
78 /// <summary> 78 /// <summary>
79 /// Summary description for Log. 79 /// Summary description for Log.
80 /// </summary> 80 /// </summary>
81 public class Log : IDisposable 81 public class Log : IDisposable
82 { 82 {
83 #region Fields 83 #region Fields
84 84
85 private TextWriter m_Writer; 85 private TextWriter m_Writer;
86 private LogTargets m_Target = LogTargets.Null; 86 private LogTargets m_Target = LogTargets.Null;
87 bool disposed; 87 bool disposed;
88 88
89 #endregion 89 #endregion
90 90
91 #region Constructors 91 #region Constructors
92 92
93 /// <summary> 93 /// <summary>
94 /// Initializes a new instance of the <see cref="Log"/> class. 94 /// Initializes a new instance of the <see cref="Log"/> class.
95 /// </summary> 95 /// </summary>
96 /// <param name="target">The target.</param> 96 /// <param name="target">The target.</param>
97 /// <param name="fileName">Name of the file.</param> 97 /// <param name="fileName">Name of the file.</param>
98 public Log(LogTargets target, string fileName) 98 public Log(LogTargets target, string fileName)
99 { 99 {
100 m_Target = target; 100 m_Target = target;
101 101
@@ -111,166 +111,166 @@ namespace Prebuild.Core.Utilities
111 } 111 }
112 } 112 }
113 113
114 #endregion 114 #endregion
115 115
116 #region Public Methods 116 #region Public Methods
117 117
118 /// <summary> 118 /// <summary>
119 /// Writes this instance. 119 /// Writes this instance.
120 /// </summary> 120 /// </summary>
121 public void Write() 121 public void Write()
122 { 122 {
123 Write(string.Empty); 123 Write(string.Empty);
124 } 124 }
125 125
126 /// <summary> 126 /// <summary>
127 /// Writes the specified MSG. 127 /// Writes the specified MSG.
128 /// </summary> 128 /// </summary>
129 /// <param name="msg">The MSG.</param> 129 /// <param name="msg">The MSG.</param>
130 public void Write(string msg) 130 public void Write(string msg)
131 { 131 {
132 if((m_Target & LogTargets.Null) != 0) 132 if((m_Target & LogTargets.Null) != 0)
133 { 133 {
134 return; 134 return;
135 } 135 }
136 136
137 if((m_Target & LogTargets.Console) != 0) 137 if((m_Target & LogTargets.Console) != 0)
138 { 138 {
139 Console.WriteLine(msg); 139 Console.WriteLine(msg);
140 } 140 }
141 if((m_Target & LogTargets.File) != 0 && m_Writer != null) 141 if((m_Target & LogTargets.File) != 0 && m_Writer != null)
142 { 142 {
143 m_Writer.WriteLine(msg); 143 m_Writer.WriteLine(msg);
144 } 144 }
145 } 145 }
146 146
147 /// <summary> 147 /// <summary>
148 /// Writes the specified format. 148 /// Writes the specified format.
149 /// </summary> 149 /// </summary>
150 /// <param name="format">The format.</param> 150 /// <param name="format">The format.</param>
151 /// <param name="args">The args.</param> 151 /// <param name="args">The args.</param>
152 public void Write(string format, params object[] args) 152 public void Write(string format, params object[] args)
153 { 153 {
154 Write(string.Format(format,args)); 154 Write(string.Format(format,args));
155 } 155 }
156 156
157 /// <summary> 157 /// <summary>
158 /// Writes the specified type. 158 /// Writes the specified type.
159 /// </summary> 159 /// </summary>
160 /// <param name="type">The type.</param> 160 /// <param name="type">The type.</param>
161 /// <param name="format">The format.</param> 161 /// <param name="format">The format.</param>
162 /// <param name="args">The args.</param> 162 /// <param name="args">The args.</param>
163 public void Write(LogType type, string format, params object[] args) 163 public void Write(LogType type, string format, params object[] args)
164 { 164 {
165 if((m_Target & LogTargets.Null) != 0) 165 if((m_Target & LogTargets.Null) != 0)
166 { 166 {
167 return; 167 return;
168 } 168 }
169 169
170 string str = ""; 170 string str = "";
171 switch(type) 171 switch(type)
172 { 172 {
173 case LogType.Info: 173 case LogType.Info:
174 str = "[I] "; 174 str = "[I] ";
175 break; 175 break;
176 case LogType.Warning: 176 case LogType.Warning:
177 str = "[!] "; 177 str = "[!] ";
178 break; 178 break;
179 case LogType.Error: 179 case LogType.Error:
180 str = "[X] "; 180 str = "[X] ";
181 break; 181 break;
182 } 182 }
183 183
184 Write(str + format,args); 184 Write(str + format,args);
185 } 185 }
186 186
187 /// <summary> 187 /// <summary>
188 /// Writes the exception. 188 /// Writes the exception.
189 /// </summary> 189 /// </summary>
190 /// <param name="type">The type.</param> 190 /// <param name="type">The type.</param>
191 /// <param name="ex">The ex.</param> 191 /// <param name="ex">The ex.</param>
192 public void WriteException(LogType type, Exception ex) 192 public void WriteException(LogType type, Exception ex)
193 { 193 {
194 if(ex != null) 194 if(ex != null)
195 { 195 {
196 Write(type, ex.Message); 196 Write(type, ex.Message);
197 //#if DEBUG 197 //#if DEBUG
198 m_Writer.WriteLine("Exception @{0} stack trace [[", ex.TargetSite.Name); 198 m_Writer.WriteLine("Exception @{0} stack trace [[", ex.TargetSite.Name);
199 m_Writer.WriteLine(ex.StackTrace); 199 m_Writer.WriteLine(ex.StackTrace);
200 m_Writer.WriteLine("]]"); 200 m_Writer.WriteLine("]]");
201 //#endif 201 //#endif
202 } 202 }
203 } 203 }
204 204
205 /// <summary> 205 /// <summary>
206 /// Flushes this instance. 206 /// Flushes this instance.
207 /// </summary> 207 /// </summary>
208 public void Flush() 208 public void Flush()
209 { 209 {
210 if(m_Writer != null) 210 if(m_Writer != null)
211 { 211 {
212 m_Writer.Flush(); 212 m_Writer.Flush();
213 } 213 }
214 } 214 }
215 215
216 #endregion 216 #endregion
217 217
218 #region IDisposable Members 218 #region IDisposable Members
219
220 /// <summary>
221 /// Performs application-defined tasks associated with freeing, releasing, or
222 /// resetting unmanaged resources.
223 /// </summary>
224 public void Dispose()
225 {
226 Dispose(true);
227 GC.SuppressFinalize(this);
228 }
219 229
220 /// <summary> 230 /// <summary>
221 /// Performs application-defined tasks associated with freeing, releasing, or 231 /// Dispose objects
222 /// resetting unmanaged resources. 232 /// </summary>
223 /// </summary> 233 /// <param name="disposing">
224 public void Dispose() 234 /// If true, it will dispose close the handle
225 { 235 /// </param>
226 Dispose(true); 236 /// <remarks>
227 GC.SuppressFinalize(this); 237 /// Will dispose managed and unmanaged resources.
228 } 238 /// </remarks>
239 protected virtual void Dispose(bool disposing)
240 {
241 if (!this.disposed)
242 {
243 if (disposing)
244 {
245 if (m_Writer != null)
246 {
247 m_Writer.Close();
248 m_Writer = null;
249 }
250 }
251 }
252 this.disposed = true;
253 }
229 254
230 /// <summary> 255 /// <summary>
231 /// Dispose objects 256 ///
232 /// </summary> 257 /// </summary>
233 /// <param name="disposing"> 258 ~Log()
234 /// If true, it will dispose close the handle 259 {
235 /// </param> 260 this.Dispose(false);
236 /// <remarks> 261 }
237 /// Will dispose managed and unmanaged resources.
238 /// </remarks>
239 protected virtual void Dispose(bool disposing)
240 {
241 if (!this.disposed)
242 {
243 if (disposing)
244 {
245 if (m_Writer != null)
246 {
247 m_Writer.Close();
248 m_Writer = null;
249 }
250 }
251 }
252 this.disposed = true;
253 }
254 262
255 /// <summary> 263 /// <summary>
256 /// 264 /// Closes and destroys this object
257 /// </summary> 265 /// </summary>
258 ~Log() 266 /// <remarks>
259 { 267 /// Same as Dispose(true)
260 this.Dispose(false); 268 /// </remarks>
261 } 269 public void Close()
262 270 {
263 /// <summary> 271 Dispose();
264 /// Closes and destroys this object 272 }
265 /// </summary>
266 /// <remarks>
267 /// Same as Dispose(true)
268 /// </remarks>
269 public void Close()
270 {
271 Dispose();
272 }
273 273
274 #endregion 274 #endregion
275 } 275 }
276} 276}