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