diff options
author | BlueWall | 2010-08-31 17:02:36 -0400 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-09-04 02:12:21 +0100 |
commit | 1e44ec84bd90ec9078027d1d9d78e83c7d305f2a (patch) | |
tree | e34db5ced4bc7bf59b98ff9fb72271dda0f25a33 /Prebuild/src/Core/Utilities | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-1e44ec84bd90ec9078027d1d9d78e83c7d305f2a.zip opensim-SC-1e44ec84bd90ec9078027d1d9d78e83c7d305f2a.tar.gz opensim-SC-1e44ec84bd90ec9078027d1d9d78e83c7d305f2a.tar.bz2 opensim-SC-1e44ec84bd90ec9078027d1d9d78e83c7d305f2a.tar.xz |
Build system upgrade:
Upgrading Prebuild.exe to correctly construct build solutions
for crossplatform tools such as xbuild, monodevelop and nant.
NOTE: Module prebuild files will need modification to work,
as the prebuild must correctly define the reference path for
all assemblies shipped in the OpenSimulator ./bin directory.
These include assemblies such as XMLRPC.dll, OpenMetaverse.dll,
Nini.dll, etc. . The entries should follow the form:
<Reference name="Nini" path="../../../bin/"/>
See the distributed prebuild.xml for further examples.
Crossplatform tools: xbuild and monodevelop use the
vs2008 OpenSim.sln and the .csproj files in each namespace.
Changes to the Prebuild.exe are against svn 322 and are included
in a patch attached to the mantis. And the dnpb source are
available@ svn co https://dnpb.svn.sourceforge.net/svnroot/dnpb dnpb
The patches are pending application by the dnpb team. After which,
the un-modified upstream Prebuild.exe will work as expected.
Diffstat (limited to 'Prebuild/src/Core/Utilities')
-rw-r--r-- | Prebuild/src/Core/Utilities/CommandLineCollection.cs | 153 | ||||
-rw-r--r-- | Prebuild/src/Core/Utilities/CurrentDirectory.cs | 80 | ||||
-rw-r--r-- | Prebuild/src/Core/Utilities/Helper.cs | 654 | ||||
-rw-r--r-- | Prebuild/src/Core/Utilities/Log.cs | 270 |
4 files changed, 0 insertions, 1157 deletions
diff --git a/Prebuild/src/Core/Utilities/CommandLineCollection.cs b/Prebuild/src/Core/Utilities/CommandLineCollection.cs deleted file mode 100644 index 22752aa..0000000 --- a/Prebuild/src/Core/Utilities/CommandLineCollection.cs +++ /dev/null | |||
@@ -1,153 +0,0 @@ | |||
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; | ||
28 | using System.Collections.Specialized; | ||
29 | using System.Diagnostics; | ||
30 | |||
31 | namespace Prebuild.Core.Utilities | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// The CommandLine class parses and interprets the command-line arguments passed to | ||
35 | /// prebuild. | ||
36 | /// </summary> | ||
37 | public class CommandLineCollection | ||
38 | { | ||
39 | #region Fields | ||
40 | |||
41 | // The raw OS arguments | ||
42 | private string[] m_RawArgs; | ||
43 | |||
44 | // Command-line argument storage | ||
45 | private Hashtable m_Arguments; | ||
46 | |||
47 | #endregion | ||
48 | |||
49 | #region Constructors | ||
50 | |||
51 | /// <summary> | ||
52 | /// Create a new CommandLine instance and set some internal variables. | ||
53 | /// </summary> | ||
54 | public CommandLineCollection(string[] args) | ||
55 | { | ||
56 | m_RawArgs = args; | ||
57 | m_Arguments = new Hashtable(); | ||
58 | |||
59 | Parse(); | ||
60 | } | ||
61 | |||
62 | #endregion | ||
63 | |||
64 | #region Private Methods | ||
65 | |||
66 | private void Parse() | ||
67 | { | ||
68 | if(m_RawArgs.Length < 1) | ||
69 | return; | ||
70 | |||
71 | int idx = 0; | ||
72 | string arg = null, lastArg = null; | ||
73 | |||
74 | while(idx <m_RawArgs.Length) | ||
75 | { | ||
76 | arg = m_RawArgs[idx]; | ||
77 | |||
78 | if(arg.Length > 2 && arg[0] == '/') | ||
79 | { | ||
80 | arg = arg.Substring(1); | ||
81 | lastArg = arg; | ||
82 | m_Arguments[arg] = ""; | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | if(lastArg != null) | ||
87 | { | ||
88 | m_Arguments[lastArg] = arg; | ||
89 | lastArg = null; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | idx++; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | #endregion | ||
98 | |||
99 | #region Public Methods | ||
100 | |||
101 | /// <summary> | ||
102 | /// Wases the passed. | ||
103 | /// </summary> | ||
104 | /// <param name="arg">The arg.</param> | ||
105 | /// <returns></returns> | ||
106 | public bool WasPassed(string arg) | ||
107 | { | ||
108 | return (m_Arguments.ContainsKey(arg)); | ||
109 | } | ||
110 | |||
111 | #endregion | ||
112 | |||
113 | #region Properties | ||
114 | |||
115 | /// <summary> | ||
116 | /// Gets the parameter associated with the command line option | ||
117 | /// </summary> | ||
118 | /// <remarks>Returns null if option was not specified, | ||
119 | /// null string if no parameter was specified, and the value if a parameter was specified</remarks> | ||
120 | public string this[string index] | ||
121 | { | ||
122 | get | ||
123 | { | ||
124 | if(m_Arguments.ContainsKey(index)) | ||
125 | { | ||
126 | return (string)(m_Arguments[index]); | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | return null; | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
135 | #endregion | ||
136 | |||
137 | #region IEnumerable Members | ||
138 | |||
139 | /// <summary> | ||
140 | /// Returns an enumerator that can iterate through a collection. | ||
141 | /// </summary> | ||
142 | /// <returns> | ||
143 | /// An <see cref="T:System.Collections.IDictionaryEnumerator"/> | ||
144 | /// that can be used to iterate through the collection. | ||
145 | /// </returns> | ||
146 | public IDictionaryEnumerator GetEnumerator() | ||
147 | { | ||
148 | return m_Arguments.GetEnumerator(); | ||
149 | } | ||
150 | |||
151 | #endregion | ||
152 | } | ||
153 | } | ||
diff --git a/Prebuild/src/Core/Utilities/CurrentDirectory.cs b/Prebuild/src/Core/Utilities/CurrentDirectory.cs deleted file mode 100644 index 5fabdf0..0000000 --- a/Prebuild/src/Core/Utilities/CurrentDirectory.cs +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
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; | ||
28 | |||
29 | namespace Prebuild.Core.Utilities | ||
30 | { | ||
31 | /// <summary> | ||
32 | /// | ||
33 | /// </summary> | ||
34 | public class CurrentDirectory | ||
35 | { | ||
36 | #region Fields | ||
37 | |||
38 | private Stack m_Stack; | ||
39 | |||
40 | #endregion | ||
41 | |||
42 | #region Constructors | ||
43 | |||
44 | /// <summary> | ||
45 | /// Initializes a new instance of the <see cref="CurrentDirectory"/> class. | ||
46 | /// </summary> | ||
47 | public CurrentDirectory() | ||
48 | { | ||
49 | m_Stack = new Stack(); | ||
50 | } | ||
51 | |||
52 | #endregion | ||
53 | |||
54 | #region Public Methods | ||
55 | |||
56 | /// <summary> | ||
57 | /// Pushes this instance. | ||
58 | /// </summary> | ||
59 | public void Push() | ||
60 | { | ||
61 | m_Stack.Push(Environment.CurrentDirectory); | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
65 | /// Pops this instance. | ||
66 | /// </summary> | ||
67 | public void Pop() | ||
68 | { | ||
69 | if(m_Stack.Count < 1) | ||
70 | { | ||
71 | return; | ||
72 | } | ||
73 | |||
74 | string cwd = (string)m_Stack.Pop(); | ||
75 | Helper.SetCurrentDir(cwd); | ||
76 | } | ||
77 | |||
78 | #endregion | ||
79 | } | ||
80 | } | ||
diff --git a/Prebuild/src/Core/Utilities/Helper.cs b/Prebuild/src/Core/Utilities/Helper.cs deleted file mode 100644 index 9a0d131..0000000 --- a/Prebuild/src/Core/Utilities/Helper.cs +++ /dev/null | |||
@@ -1,654 +0,0 @@ | |||
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; | ||
28 | using System.Diagnostics; | ||
29 | using System.IO; | ||
30 | using System.Runtime.InteropServices; | ||
31 | using System.Text.RegularExpressions; | ||
32 | using System.Collections.Specialized; | ||
33 | using System.Xml; | ||
34 | using Prebuild.Core.Nodes; | ||
35 | |||
36 | namespace Prebuild.Core.Utilities | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// | ||
40 | /// </summary> | ||
41 | public class Helper | ||
42 | { | ||
43 | #region Fields | ||
44 | |||
45 | private static Stack dirStack; | ||
46 | private static Regex varRegex; | ||
47 | static bool checkForOSVariables; | ||
48 | |||
49 | /// <summary> | ||
50 | /// | ||
51 | /// </summary> | ||
52 | public static bool CheckForOSVariables | ||
53 | { | ||
54 | get | ||
55 | { | ||
56 | return checkForOSVariables; | ||
57 | } | ||
58 | set | ||
59 | { | ||
60 | checkForOSVariables = value; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | #endregion | ||
65 | |||
66 | #region Constructors | ||
67 | |||
68 | /// <summary> | ||
69 | /// Initializes the <see cref="Helper"/> class. | ||
70 | /// </summary> | ||
71 | static Helper() | ||
72 | { | ||
73 | dirStack = new Stack(); | ||
74 | //m_VarRegex = new Regex(@"\${(?<var>[\w|_]+)}"); | ||
75 | } | ||
76 | |||
77 | #endregion | ||
78 | |||
79 | #region Properties | ||
80 | |||
81 | /// <summary> | ||
82 | /// | ||
83 | /// </summary> | ||
84 | public static Stack DirStack | ||
85 | { | ||
86 | get | ||
87 | { | ||
88 | return dirStack; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// | ||
94 | /// </summary> | ||
95 | public static Regex VarRegex | ||
96 | { | ||
97 | get | ||
98 | { | ||
99 | return varRegex; | ||
100 | } | ||
101 | set | ||
102 | { | ||
103 | varRegex = value; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | #endregion | ||
108 | |||
109 | #region Public Methods | ||
110 | |||
111 | #region String Parsing | ||
112 | #region Inner Classes and Delegates | ||
113 | /// <summary> | ||
114 | /// | ||
115 | /// </summary> | ||
116 | public delegate string StringLookup(string key); | ||
117 | |||
118 | #endregion | ||
119 | |||
120 | /// <summary> | ||
121 | /// Gets a collection of StringLocationPair objects that represent the matches | ||
122 | /// </summary> | ||
123 | /// <param name="target">The target.</param> | ||
124 | /// <param name="beforeGroup">The before group.</param> | ||
125 | /// <param name="afterGroup">The after group.</param> | ||
126 | /// <param name="includeDelimitersInSubstrings">if set to <c>true</c> [include delimiters in substrings].</param> | ||
127 | /// <returns></returns> | ||
128 | public static StringCollection FindGroups(string target, string beforeGroup, string afterGroup, bool includeDelimitersInSubstrings) | ||
129 | { | ||
130 | if( beforeGroup == null ) | ||
131 | { | ||
132 | throw new ArgumentNullException("beforeGroup"); | ||
133 | } | ||
134 | if( afterGroup == null ) | ||
135 | { | ||
136 | throw new ArgumentNullException("afterGroup"); | ||
137 | } | ||
138 | StringCollection results = new StringCollection(); | ||
139 | if(target == null || target.Length == 0) | ||
140 | { | ||
141 | return results; | ||
142 | } | ||
143 | |||
144 | int beforeMod = 0; | ||
145 | int afterMod = 0; | ||
146 | if(includeDelimitersInSubstrings) | ||
147 | { | ||
148 | //be sure to not exlude the delims | ||
149 | beforeMod = beforeGroup.Length; | ||
150 | afterMod = afterGroup.Length; | ||
151 | } | ||
152 | int startIndex = 0; | ||
153 | while((startIndex = target.IndexOf(beforeGroup,startIndex)) != -1) { | ||
154 | int endIndex = target.IndexOf(afterGroup,startIndex);//the index of the char after it | ||
155 | if(endIndex == -1) | ||
156 | { | ||
157 | break; | ||
158 | } | ||
159 | int length = endIndex - startIndex - beforeGroup.Length;//move to the first char in the string | ||
160 | string substring = substring = target.Substring(startIndex + beforeGroup.Length - beforeMod, | ||
161 | length - afterMod); | ||
162 | |||
163 | results.Add(substring); | ||
164 | //results.Add(new StringLocationPair(substring,startIndex)); | ||
165 | startIndex = endIndex + 1; | ||
166 | //the Interpolate*() methods will not work if expressions are expandded inside expression due to an optimization | ||
167 | //so start after endIndex | ||
168 | |||
169 | } | ||
170 | return results; | ||
171 | } | ||
172 | |||
173 | /// <summary> | ||
174 | /// Replaces the groups. | ||
175 | /// </summary> | ||
176 | /// <param name="target">The target.</param> | ||
177 | /// <param name="beforeGroup">The before group.</param> | ||
178 | /// <param name="afterGroup">The after group.</param> | ||
179 | /// <param name="lookup">The lookup.</param> | ||
180 | /// <returns></returns> | ||
181 | public static string ReplaceGroups(string target, string beforeGroup, string afterGroup, StringLookup lookup) { | ||
182 | if( target == null ) | ||
183 | { | ||
184 | throw new ArgumentNullException("target"); | ||
185 | } | ||
186 | //int targetLength = target.Length; | ||
187 | StringCollection strings = FindGroups(target,beforeGroup,afterGroup,false); | ||
188 | if( lookup == null ) | ||
189 | { | ||
190 | throw new ArgumentNullException("lookup"); | ||
191 | } | ||
192 | foreach(string substring in strings) | ||
193 | { | ||
194 | target = target.Replace(beforeGroup + substring + afterGroup, lookup(substring) ); | ||
195 | } | ||
196 | return target; | ||
197 | } | ||
198 | |||
199 | /// <summary> | ||
200 | /// Replaces ${var} statements in a string with the corresonding values as detirmined by the lookup delegate | ||
201 | /// </summary> | ||
202 | /// <param name="target">The target.</param> | ||
203 | /// <param name="lookup">The lookup.</param> | ||
204 | /// <returns></returns> | ||
205 | public static string InterpolateForVariables(string target, StringLookup lookup) | ||
206 | { | ||
207 | return ReplaceGroups(target, "${" , "}" , lookup); | ||
208 | } | ||
209 | |||
210 | /// <summary> | ||
211 | /// Replaces ${var} statements in a string with the corresonding environment variable with name var | ||
212 | /// </summary> | ||
213 | /// <param name="target"></param> | ||
214 | /// <returns></returns> | ||
215 | public static string InterpolateForEnvironmentVariables(string target) | ||
216 | { | ||
217 | return InterpolateForVariables(target, new StringLookup(Environment.GetEnvironmentVariable)); | ||
218 | } | ||
219 | |||
220 | #endregion | ||
221 | |||
222 | /// <summary> | ||
223 | /// Translates the value. | ||
224 | /// </summary> | ||
225 | /// <param name="translateType">Type of the translate.</param> | ||
226 | /// <param name="translationItem">The translation item.</param> | ||
227 | /// <returns></returns> | ||
228 | public static object TranslateValue(Type translateType, string translationItem) | ||
229 | { | ||
230 | if(translationItem == null) | ||
231 | { | ||
232 | return null; | ||
233 | } | ||
234 | |||
235 | try | ||
236 | { | ||
237 | string lowerVal = translationItem.ToLower(); | ||
238 | if(translateType == typeof(bool)) | ||
239 | { | ||
240 | return (lowerVal == "true" || lowerVal == "1" || lowerVal == "y" || lowerVal == "yes" || lowerVal == "on"); | ||
241 | } | ||
242 | else if(translateType == typeof(int)) | ||
243 | { | ||
244 | return (Int32.Parse(translationItem)); | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | return translationItem; | ||
249 | } | ||
250 | } | ||
251 | catch(FormatException) | ||
252 | { | ||
253 | return null; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | /// <summary> | ||
258 | /// Deletes if exists. | ||
259 | /// </summary> | ||
260 | /// <param name="file">The file.</param> | ||
261 | /// <returns></returns> | ||
262 | public static bool DeleteIfExists(string file) | ||
263 | { | ||
264 | string resFile = null; | ||
265 | try | ||
266 | { | ||
267 | resFile = ResolvePath(file); | ||
268 | } | ||
269 | catch(ArgumentException) | ||
270 | { | ||
271 | return false; | ||
272 | } | ||
273 | |||
274 | if(!File.Exists(resFile)) | ||
275 | { | ||
276 | return false; | ||
277 | } | ||
278 | |||
279 | File.Delete(resFile); | ||
280 | return true; | ||
281 | } | ||
282 | |||
283 | static readonly char seperator = Path.DirectorySeparatorChar; | ||
284 | |||
285 | // This little gem was taken from the NeL source, thanks guys! | ||
286 | /// <summary> | ||
287 | /// Makes a relative path | ||
288 | /// </summary> | ||
289 | /// <param name="startPath">Path to start from</param> | ||
290 | /// <param name="endPath">Path to end at</param> | ||
291 | /// <returns>Path that will get from startPath to endPath</returns> | ||
292 | public static string MakePathRelativeTo(string startPath, string endPath) | ||
293 | { | ||
294 | string tmp = NormalizePath(startPath, seperator); | ||
295 | string src = NormalizePath(endPath, seperator); | ||
296 | string prefix = ""; | ||
297 | |||
298 | while(true) | ||
299 | { | ||
300 | if((String.Compare(tmp, 0, src, 0, tmp.Length) == 0)) | ||
301 | { | ||
302 | string ret; | ||
303 | int size = tmp.Length; | ||
304 | if(size == src.Length) | ||
305 | { | ||
306 | return "./"; | ||
307 | } | ||
308 | if((src.Length > tmp.Length) && src[tmp.Length - 1] != seperator) | ||
309 | { | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | ret = prefix + endPath.Substring(size, endPath.Length - size); | ||
314 | ret = ret.Trim(); | ||
315 | if(ret[0] == seperator) | ||
316 | { | ||
317 | ret = "." + ret; | ||
318 | } | ||
319 | |||
320 | return NormalizePath(ret); | ||
321 | } | ||
322 | |||
323 | } | ||
324 | |||
325 | if(tmp.Length < 2) | ||
326 | { | ||
327 | break; | ||
328 | } | ||
329 | |||
330 | int lastPos = tmp.LastIndexOf(seperator, tmp.Length - 2); | ||
331 | int prevPos = tmp.IndexOf(seperator); | ||
332 | |||
333 | if((lastPos == prevPos) || (lastPos == -1)) | ||
334 | { | ||
335 | break; | ||
336 | } | ||
337 | |||
338 | tmp = tmp.Substring(0, lastPos + 1); | ||
339 | prefix += ".." + seperator.ToString(); | ||
340 | } | ||
341 | |||
342 | return endPath; | ||
343 | } | ||
344 | |||
345 | /// <summary> | ||
346 | /// Resolves the path. | ||
347 | /// </summary> | ||
348 | /// <param name="path">The path.</param> | ||
349 | /// <returns></returns> | ||
350 | public static string ResolvePath(string path) | ||
351 | { | ||
352 | string tmpPath = NormalizePath(path); | ||
353 | if(tmpPath.Length < 1) | ||
354 | { | ||
355 | tmpPath = "."; | ||
356 | } | ||
357 | |||
358 | tmpPath = Path.GetFullPath(tmpPath); | ||
359 | if(!File.Exists(tmpPath) && !Directory.Exists(tmpPath)) | ||
360 | { | ||
361 | throw new ArgumentException("Path could not be resolved: " + tmpPath); | ||
362 | } | ||
363 | |||
364 | return tmpPath; | ||
365 | } | ||
366 | |||
367 | /// <summary> | ||
368 | /// Normalizes the path. | ||
369 | /// </summary> | ||
370 | /// <param name="path">The path.</param> | ||
371 | /// <param name="separatorCharacter">The separator character.</param> | ||
372 | /// <returns></returns> | ||
373 | public static string NormalizePath(string path, char separatorCharacter) | ||
374 | { | ||
375 | if(path == null || path == "" || path.Length < 1) | ||
376 | { | ||
377 | return ""; | ||
378 | } | ||
379 | |||
380 | string tmpPath = path.Replace('\\', '/'); | ||
381 | tmpPath = tmpPath.Replace('/', separatorCharacter); | ||
382 | return tmpPath; | ||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Normalizes the path. | ||
387 | /// </summary> | ||
388 | /// <param name="path">The path.</param> | ||
389 | /// <returns></returns> | ||
390 | public static string NormalizePath(string path) | ||
391 | { | ||
392 | return NormalizePath(path, Path.DirectorySeparatorChar); | ||
393 | } | ||
394 | |||
395 | /// <summary> | ||
396 | /// Ends the path. | ||
397 | /// </summary> | ||
398 | /// <param name="path">The path.</param> | ||
399 | /// <param name="separatorCharacter">The separator character.</param> | ||
400 | /// <returns></returns> | ||
401 | public static string EndPath(string path, char separatorCharacter) | ||
402 | { | ||
403 | if(path == null || path == "" || path.Length < 1) | ||
404 | { | ||
405 | return ""; | ||
406 | } | ||
407 | |||
408 | if(!path.EndsWith(separatorCharacter.ToString())) | ||
409 | { | ||
410 | return (path + separatorCharacter); | ||
411 | } | ||
412 | |||
413 | return path; | ||
414 | } | ||
415 | |||
416 | /// <summary> | ||
417 | /// Ends the path. | ||
418 | /// </summary> | ||
419 | /// <param name="path">The path.</param> | ||
420 | /// <returns></returns> | ||
421 | public static string EndPath(string path) | ||
422 | { | ||
423 | return EndPath(path, Path.DirectorySeparatorChar); | ||
424 | } | ||
425 | |||
426 | /// <summary> | ||
427 | /// Makes the file path. | ||
428 | /// </summary> | ||
429 | /// <param name="path">The path.</param> | ||
430 | /// <param name="name">The name.</param> | ||
431 | /// <param name="ext">The ext.</param> | ||
432 | /// <returns></returns> | ||
433 | public static string MakeFilePath(string path, string name, string ext) | ||
434 | { | ||
435 | string ret = EndPath(NormalizePath(path)); | ||
436 | |||
437 | if( name == null ) | ||
438 | { | ||
439 | throw new ArgumentNullException("name"); | ||
440 | } | ||
441 | |||
442 | ret += name; | ||
443 | if(!name.EndsWith("." + ext)) | ||
444 | { | ||
445 | ret += "." + ext; | ||
446 | } | ||
447 | |||
448 | //foreach(char c in Path.GetInvalidPathChars()) | ||
449 | //{ | ||
450 | // ret = ret.Replace(c, '_'); | ||
451 | //} | ||
452 | |||
453 | return ret; | ||
454 | } | ||
455 | |||
456 | /// <summary> | ||
457 | /// Makes the file path. | ||
458 | /// </summary> | ||
459 | /// <param name="path">The path.</param> | ||
460 | /// <param name="name">The name.</param> | ||
461 | /// <returns></returns> | ||
462 | public static string MakeFilePath(string path, string name) | ||
463 | { | ||
464 | string ret = EndPath(NormalizePath(path)); | ||
465 | |||
466 | if( name == null ) | ||
467 | { | ||
468 | throw new ArgumentNullException("name"); | ||
469 | } | ||
470 | |||
471 | ret += name; | ||
472 | |||
473 | //foreach (char c in Path.GetInvalidPathChars()) | ||
474 | //{ | ||
475 | // ret = ret.Replace(c, '_'); | ||
476 | //} | ||
477 | |||
478 | return ret; | ||
479 | } | ||
480 | |||
481 | /// <summary> | ||
482 | /// | ||
483 | /// </summary> | ||
484 | /// <param name="path"></param> | ||
485 | /// <returns></returns> | ||
486 | public static string MakeReferencePath(string path) | ||
487 | { | ||
488 | string ret = EndPath(NormalizePath(path)); | ||
489 | |||
490 | //foreach (char c in Path.GetInvalidPathChars()) | ||
491 | //{ | ||
492 | // ret = ret.Replace(c, '_'); | ||
493 | //} | ||
494 | |||
495 | return ret; | ||
496 | } | ||
497 | |||
498 | /// <summary> | ||
499 | /// Sets the current dir. | ||
500 | /// </summary> | ||
501 | /// <param name="path">The path.</param> | ||
502 | public static void SetCurrentDir(string path) | ||
503 | { | ||
504 | if( path == null ) | ||
505 | { | ||
506 | throw new ArgumentNullException("path"); | ||
507 | } | ||
508 | if(path.Length < 1) | ||
509 | { | ||
510 | return; | ||
511 | } | ||
512 | |||
513 | Environment.CurrentDirectory = path; | ||
514 | } | ||
515 | |||
516 | /// <summary> | ||
517 | /// Checks the type. | ||
518 | /// </summary> | ||
519 | /// <param name="typeToCheck">The type to check.</param> | ||
520 | /// <param name="attr">The attr.</param> | ||
521 | /// <param name="inter">The inter.</param> | ||
522 | /// <returns></returns> | ||
523 | public static object CheckType(Type typeToCheck, Type attr, Type inter) | ||
524 | { | ||
525 | if(typeToCheck == null || attr == null) | ||
526 | { | ||
527 | return null; | ||
528 | } | ||
529 | |||
530 | object[] attrs = typeToCheck.GetCustomAttributes(attr, false); | ||
531 | if(attrs == null || attrs.Length < 1) | ||
532 | { | ||
533 | return null; | ||
534 | } | ||
535 | if( inter == null ) | ||
536 | { | ||
537 | throw new ArgumentNullException("inter"); | ||
538 | } | ||
539 | |||
540 | if(typeToCheck.GetInterface(inter.FullName) == null) | ||
541 | { | ||
542 | return null; | ||
543 | } | ||
544 | |||
545 | return attrs[0]; | ||
546 | } | ||
547 | |||
548 | /* A bit of overhead for simple group parsing, there are problems with Regex in Mono | ||
549 | public static string ParseValue(string val) | ||
550 | { | ||
551 | if(val == null || val.Length < 1 || !CheckForOSVariables) | ||
552 | return val; | ||
553 | |||
554 | string tmp = val; | ||
555 | Match m = m_VarRegex.Match(val); | ||
556 | while(m.Success) | ||
557 | { | ||
558 | if(m.Groups["var"] == null) | ||
559 | continue; | ||
560 | |||
561 | Capture c = m.Groups["var"].Captures[0]; | ||
562 | if(c == null) | ||
563 | continue; | ||
564 | |||
565 | string var = c.Value; | ||
566 | string envVal = Environment.GetEnvironmentVariable(var); | ||
567 | if(envVal == null) | ||
568 | envVal = ""; | ||
569 | |||
570 | tmp = tmp.Replace("${" + var + "}", envVal); | ||
571 | m = m.NextMatch(); | ||
572 | } | ||
573 | |||
574 | return tmp; | ||
575 | }*/ | ||
576 | |||
577 | /// <summary> | ||
578 | /// Attributes the value. | ||
579 | /// </summary> | ||
580 | /// <param name="node">The node.</param> | ||
581 | /// <param name="attr">The attr.</param> | ||
582 | /// <param name="def">The def.</param> | ||
583 | /// <returns></returns> | ||
584 | public static string AttributeValue(XmlNode node, string attr, string def) | ||
585 | { | ||
586 | if( node == null ) | ||
587 | { | ||
588 | throw new ArgumentNullException("node"); | ||
589 | } | ||
590 | if(node.Attributes[attr] == null) | ||
591 | { | ||
592 | return def; | ||
593 | } | ||
594 | string val = node.Attributes[attr].Value; | ||
595 | if(!CheckForOSVariables) | ||
596 | { | ||
597 | return val; | ||
598 | } | ||
599 | |||
600 | return InterpolateForEnvironmentVariables(val); | ||
601 | } | ||
602 | |||
603 | /// <summary> | ||
604 | /// Parses the boolean. | ||
605 | /// </summary> | ||
606 | /// <param name="node">The node.</param> | ||
607 | /// <param name="attr">The attr.</param> | ||
608 | /// <param name="defaultValue">if set to <c>true</c> [default value].</param> | ||
609 | /// <returns></returns> | ||
610 | public static bool ParseBoolean(XmlNode node, string attr, bool defaultValue) | ||
611 | { | ||
612 | if( node == null ) | ||
613 | { | ||
614 | throw new ArgumentNullException("node"); | ||
615 | } | ||
616 | if(node.Attributes[attr] == null) | ||
617 | { | ||
618 | return defaultValue; | ||
619 | } | ||
620 | return bool.Parse(node.Attributes[attr].Value); | ||
621 | } | ||
622 | |||
623 | /// <summary> | ||
624 | /// Enums the attribute value. | ||
625 | /// </summary> | ||
626 | /// <param name="node">The node.</param> | ||
627 | /// <param name="attr">The attr.</param> | ||
628 | /// <param name="enumType">Type of the enum.</param> | ||
629 | /// <param name="def">The def.</param> | ||
630 | /// <returns></returns> | ||
631 | public static object EnumAttributeValue(XmlNode node, string attr, Type enumType, object def) | ||
632 | { | ||
633 | if( def == null ) | ||
634 | { | ||
635 | throw new ArgumentNullException("def"); | ||
636 | } | ||
637 | string val = AttributeValue(node, attr, def.ToString()); | ||
638 | return Enum.Parse(enumType, val, true); | ||
639 | } | ||
640 | |||
641 | /// <summary> | ||
642 | /// | ||
643 | /// </summary> | ||
644 | /// <param name="assemblyName"></param> | ||
645 | /// <param name="projectType"></param> | ||
646 | /// <returns></returns> | ||
647 | public static string AssemblyFullName(string assemblyName, ProjectType projectType) | ||
648 | { | ||
649 | return assemblyName + (projectType == ProjectType.Library ? ".dll" : ".exe"); | ||
650 | } | ||
651 | |||
652 | #endregion | ||
653 | } | ||
654 | } | ||
diff --git a/Prebuild/src/Core/Utilities/Log.cs b/Prebuild/src/Core/Utilities/Log.cs deleted file mode 100644 index 548e987..0000000 --- a/Prebuild/src/Core/Utilities/Log.cs +++ /dev/null | |||
@@ -1,270 +0,0 @@ | |||
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.IO; | ||
28 | |||
29 | namespace Prebuild.Core.Utilities | ||
30 | { | ||
31 | /// <summary> | ||
32 | /// | ||
33 | /// </summary> | ||
34 | public enum LogType | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// | ||
38 | /// </summary> | ||
39 | None, | ||
40 | /// <summary> | ||
41 | /// | ||
42 | /// </summary> | ||
43 | Info, | ||
44 | /// <summary> | ||
45 | /// | ||
46 | /// </summary> | ||
47 | Warning, | ||
48 | /// <summary> | ||
49 | /// | ||
50 | /// </summary> | ||
51 | Error | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// | ||
56 | /// </summary> | ||
57 | [Flags] | ||
58 | public enum LogTargets | ||
59 | { | ||
60 | /// <summary> | ||
61 | /// | ||
62 | /// </summary> | ||
63 | None = 0, | ||
64 | /// <summary> | ||
65 | /// | ||
66 | /// </summary> | ||
67 | Null = 1, | ||
68 | /// <summary> | ||
69 | /// | ||
70 | /// </summary> | ||
71 | File = 2, | ||
72 | /// <summary> | ||
73 | /// | ||
74 | /// </summary> | ||
75 | Console = 4 | ||
76 | } | ||
77 | |||
78 | /// <summary> | ||
79 | /// Summary description for Log. | ||
80 | /// </summary> | ||
81 | public class Log : IDisposable | ||
82 | { | ||
83 | #region Fields | ||
84 | |||
85 | private StreamWriter m_Writer; | ||
86 | private LogTargets m_Target = LogTargets.Null; | ||
87 | bool disposed; | ||
88 | |||
89 | #endregion | ||
90 | |||
91 | #region Constructors | ||
92 | |||
93 | /// <summary> | ||
94 | /// Initializes a new instance of the <see cref="Log"/> class. | ||
95 | /// </summary> | ||
96 | /// <param name="target">The target.</param> | ||
97 | /// <param name="fileName">Name of the file.</param> | ||
98 | public Log(LogTargets target, string fileName) | ||
99 | { | ||
100 | m_Target = target; | ||
101 | |||
102 | if((m_Target & LogTargets.File) != 0) | ||
103 | { | ||
104 | m_Writer = new StreamWriter(fileName, false); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | #endregion | ||
109 | |||
110 | #region Public Methods | ||
111 | |||
112 | /// <summary> | ||
113 | /// Writes this instance. | ||
114 | /// </summary> | ||
115 | public void Write() | ||
116 | { | ||
117 | Write(string.Empty); | ||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// Writes the specified MSG. | ||
122 | /// </summary> | ||
123 | /// <param name="msg">The MSG.</param> | ||
124 | public void Write(string msg) | ||
125 | { | ||
126 | if((m_Target & LogTargets.Null) != 0) | ||
127 | { | ||
128 | return; | ||
129 | } | ||
130 | |||
131 | if((m_Target & LogTargets.Console) != 0) | ||
132 | { | ||
133 | Console.WriteLine(msg); | ||
134 | } | ||
135 | if((m_Target & LogTargets.File) != 0 && m_Writer != null) | ||
136 | { | ||
137 | m_Writer.WriteLine(msg); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | /// <summary> | ||
142 | /// Writes the specified format. | ||
143 | /// </summary> | ||
144 | /// <param name="format">The format.</param> | ||
145 | /// <param name="args">The args.</param> | ||
146 | public void Write(string format, params object[] args) | ||
147 | { | ||
148 | Write(string.Format(format,args)); | ||
149 | } | ||
150 | |||
151 | /// <summary> | ||
152 | /// Writes the specified type. | ||
153 | /// </summary> | ||
154 | /// <param name="type">The type.</param> | ||
155 | /// <param name="format">The format.</param> | ||
156 | /// <param name="args">The args.</param> | ||
157 | public void Write(LogType type, string format, params object[] args) | ||
158 | { | ||
159 | if((m_Target & LogTargets.Null) != 0) | ||
160 | { | ||
161 | return; | ||
162 | } | ||
163 | |||
164 | string str = ""; | ||
165 | switch(type) | ||
166 | { | ||
167 | case LogType.Info: | ||
168 | str = "[I] "; | ||
169 | break; | ||
170 | case LogType.Warning: | ||
171 | str = "[!] "; | ||
172 | break; | ||
173 | case LogType.Error: | ||
174 | str = "[X] "; | ||
175 | break; | ||
176 | } | ||
177 | |||
178 | Write(str + format,args); | ||
179 | } | ||
180 | |||
181 | /// <summary> | ||
182 | /// Writes the exception. | ||
183 | /// </summary> | ||
184 | /// <param name="type">The type.</param> | ||
185 | /// <param name="ex">The ex.</param> | ||
186 | public void WriteException(LogType type, Exception ex) | ||
187 | { | ||
188 | if(ex != null) | ||
189 | { | ||
190 | Write(type, ex.Message); | ||
191 | //#if DEBUG | ||
192 | m_Writer.WriteLine("Exception @{0} stack trace [[", ex.TargetSite.Name); | ||
193 | m_Writer.WriteLine(ex.StackTrace); | ||
194 | m_Writer.WriteLine("]]"); | ||
195 | //#endif | ||
196 | } | ||
197 | } | ||
198 | |||
199 | /// <summary> | ||
200 | /// Flushes this instance. | ||
201 | /// </summary> | ||
202 | public void Flush() | ||
203 | { | ||
204 | if(m_Writer != null) | ||
205 | { | ||
206 | m_Writer.Flush(); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | #endregion | ||
211 | |||
212 | #region IDisposable Members | ||
213 | |||
214 | /// <summary> | ||
215 | /// Performs application-defined tasks associated with freeing, releasing, or | ||
216 | /// resetting unmanaged resources. | ||
217 | /// </summary> | ||
218 | public void Dispose() | ||
219 | { | ||
220 | Dispose(true); | ||
221 | GC.SuppressFinalize(this); | ||
222 | } | ||
223 | |||
224 | /// <summary> | ||
225 | /// Dispose objects | ||
226 | /// </summary> | ||
227 | /// <param name="disposing"> | ||
228 | /// If true, it will dispose close the handle | ||
229 | /// </param> | ||
230 | /// <remarks> | ||
231 | /// Will dispose managed and unmanaged resources. | ||
232 | /// </remarks> | ||
233 | protected virtual void Dispose(bool disposing) | ||
234 | { | ||
235 | if (!this.disposed) | ||
236 | { | ||
237 | if (disposing) | ||
238 | { | ||
239 | if (m_Writer != null) | ||
240 | { | ||
241 | m_Writer.Close(); | ||
242 | m_Writer = null; | ||
243 | } | ||
244 | } | ||
245 | } | ||
246 | this.disposed = true; | ||
247 | } | ||
248 | |||
249 | /// <summary> | ||
250 | /// | ||
251 | /// </summary> | ||
252 | ~Log() | ||
253 | { | ||
254 | this.Dispose(false); | ||
255 | } | ||
256 | |||
257 | /// <summary> | ||
258 | /// Closes and destroys this object | ||
259 | /// </summary> | ||
260 | /// <remarks> | ||
261 | /// Same as Dispose(true) | ||
262 | /// </remarks> | ||
263 | public void Close() | ||
264 | { | ||
265 | Dispose(); | ||
266 | } | ||
267 | |||
268 | #endregion | ||
269 | } | ||
270 | } | ||