diff options
author | lbsa71 | 2007-10-30 09:05:31 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-30 09:05:31 +0000 |
commit | 67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch) | |
tree | 20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Framework/General/Util.cs | |
parent | * Deleted .user file (diff) | |
download | opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2 opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz |
* Optimized usings
* Shortened type references
* Removed redundant 'this' qualifier
Diffstat (limited to 'OpenSim/Framework/General/Util.cs')
-rw-r--r-- | OpenSim/Framework/General/Util.cs | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/OpenSim/Framework/General/Util.cs b/OpenSim/Framework/General/Util.cs index e3b156d..c731561 100644 --- a/OpenSim/Framework/General/Util.cs +++ b/OpenSim/Framework/General/Util.cs | |||
@@ -25,14 +25,16 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | |||
28 | using System; | 29 | using System; |
29 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Data; | ||
30 | using System.IO; | 32 | using System.IO; |
31 | using System.Security.Cryptography; | ||
32 | using System.Net; | 33 | using System.Net; |
34 | using System.Net.Sockets; | ||
35 | using System.Security.Cryptography; | ||
33 | using System.Text; | 36 | using System.Text; |
34 | using libsecondlife; | 37 | using libsecondlife; |
35 | |||
36 | using Nini.Config; | 38 | using Nini.Config; |
37 | 39 | ||
38 | namespace OpenSim.Framework | 40 | namespace OpenSim.Framework |
@@ -52,16 +54,13 @@ namespace OpenSim.Framework | |||
52 | 54 | ||
53 | public static Random RandomClass | 55 | public static Random RandomClass |
54 | { | 56 | { |
55 | get | 57 | get { return randomClass; } |
56 | { | ||
57 | return randomClass; | ||
58 | } | ||
59 | } | 58 | } |
60 | 59 | ||
61 | public static uint GetNextXferID() | 60 | public static uint GetNextXferID() |
62 | { | 61 | { |
63 | uint id = 0; | 62 | uint id = 0; |
64 | lock(XferLock) | 63 | lock (XferLock) |
65 | { | 64 | { |
66 | id = nextXferID; | 65 | id = nextXferID; |
67 | nextXferID++; | 66 | nextXferID++; |
@@ -71,25 +70,24 @@ namespace OpenSim.Framework | |||
71 | 70 | ||
72 | public Util() | 71 | public Util() |
73 | { | 72 | { |
74 | |||
75 | } | 73 | } |
76 | 74 | ||
77 | public static string GetFileName(string file) | 75 | public static string GetFileName(string file) |
78 | { | 76 | { |
79 | // Return just the filename on UNIX platforms | 77 | // Return just the filename on UNIX platforms |
80 | // TODO: this should be customisable with a prefix, but that's something to do later. | 78 | // TODO: this should be customisable with a prefix, but that's something to do later. |
81 | if (System.Environment.OSVersion.Platform == PlatformID.Unix) | 79 | if (Environment.OSVersion.Platform == PlatformID.Unix) |
82 | { | 80 | { |
83 | return file; | 81 | return file; |
84 | } | 82 | } |
85 | 83 | ||
86 | // Return %APPDATA%/OpenSim/file for 2K/XP/NT/2K3/VISTA | 84 | // Return %APPDATA%/OpenSim/file for 2K/XP/NT/2K3/VISTA |
87 | // TODO: Switch this to System.Enviroment.SpecialFolders.ApplicationData | 85 | // TODO: Switch this to System.Enviroment.SpecialFolders.ApplicationData |
88 | if (System.Environment.OSVersion.Platform == PlatformID.Win32NT) | 86 | if (Environment.OSVersion.Platform == PlatformID.Win32NT) |
89 | { | 87 | { |
90 | if (!System.IO.Directory.Exists("%APPDATA%\\OpenSim\\")) | 88 | if (!Directory.Exists("%APPDATA%\\OpenSim\\")) |
91 | { | 89 | { |
92 | System.IO.Directory.CreateDirectory("%APPDATA%\\OpenSim"); | 90 | Directory.CreateDirectory("%APPDATA%\\OpenSim"); |
93 | } | 91 | } |
94 | 92 | ||
95 | return "%APPDATA%\\OpenSim\\" + file; | 93 | return "%APPDATA%\\OpenSim\\" + file; |
@@ -103,23 +101,23 @@ namespace OpenSim.Framework | |||
103 | public static bool IsEnvironmentSupported(ref string reason) | 101 | public static bool IsEnvironmentSupported(ref string reason) |
104 | { | 102 | { |
105 | // Must have .NET 2.0 (Generics / libsl) | 103 | // Must have .NET 2.0 (Generics / libsl) |
106 | if (System.Environment.Version.Major < 2) | 104 | if (Environment.Version.Major < 2) |
107 | { | 105 | { |
108 | reason = ".NET 1.0/1.1 lacks components that is used by OpenSim"; | 106 | reason = ".NET 1.0/1.1 lacks components that is used by OpenSim"; |
109 | return false; | 107 | return false; |
110 | } | 108 | } |
111 | 109 | ||
112 | // Windows 95/98/ME are unsupported | 110 | // Windows 95/98/ME are unsupported |
113 | if (System.Environment.OSVersion.Platform == PlatformID.Win32Windows && | 111 | if (Environment.OSVersion.Platform == PlatformID.Win32Windows && |
114 | System.Environment.OSVersion.Platform != PlatformID.Win32NT) | 112 | Environment.OSVersion.Platform != PlatformID.Win32NT) |
115 | { | 113 | { |
116 | reason = "Windows 95/98/ME will not run OpenSim"; | 114 | reason = "Windows 95/98/ME will not run OpenSim"; |
117 | return false; | 115 | return false; |
118 | } | 116 | } |
119 | 117 | ||
120 | // Windows 2000 / Pre-SP2 XP | 118 | // Windows 2000 / Pre-SP2 XP |
121 | if (System.Environment.OSVersion.Version.Major == 5 && ( | 119 | if (Environment.OSVersion.Version.Major == 5 && ( |
122 | System.Environment.OSVersion.Version.Minor == 0)) | 120 | Environment.OSVersion.Version.Minor == 0)) |
123 | { | 121 | { |
124 | reason = "Please update to Windows XP Service Pack 2 or Server2003"; | 122 | reason = "Please update to Windows XP Service Pack 2 or Server2003"; |
125 | return false; | 123 | return false; |
@@ -131,7 +129,7 @@ namespace OpenSim.Framework | |||
131 | public static int UnixTimeSinceEpoch() | 129 | public static int UnixTimeSinceEpoch() |
132 | { | 130 | { |
133 | TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); | 131 | TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); |
134 | int timestamp = (int)t.TotalSeconds; | 132 | int timestamp = (int) t.TotalSeconds; |
135 | return timestamp; | 133 | return timestamp; |
136 | } | 134 | } |
137 | 135 | ||
@@ -155,10 +153,10 @@ namespace OpenSim.Framework | |||
155 | 153 | ||
156 | public static int fast_distance2d(int x, int y) | 154 | public static int fast_distance2d(int x, int y) |
157 | { | 155 | { |
158 | x = System.Math.Abs(x); | 156 | x = Math.Abs(x); |
159 | y = System.Math.Abs(y); | 157 | y = Math.Abs(y); |
160 | 158 | ||
161 | int min = System.Math.Min(x, y); | 159 | int min = Math.Min(x, y); |
162 | 160 | ||
163 | return (x + y - (min >> 1) - (min >> 2) + (min >> 4)); | 161 | return (x + y - (min >> 1) - (min >> 2) + (min >> 4)); |
164 | } | 162 | } |
@@ -233,7 +231,7 @@ namespace OpenSim.Framework | |||
233 | for (int j = 0; j < 16 && (i + j) < bytes.Length; j++) | 231 | for (int j = 0; j < 16 && (i + j) < bytes.Length; j++) |
234 | { | 232 | { |
235 | if (bytes[i + j] >= 0x20 && bytes[i + j] < 0x7E) | 233 | if (bytes[i + j] >= 0x20 && bytes[i + j] < 0x7E) |
236 | output.Append((char)bytes[i + j]); | 234 | output.Append((char) bytes[i + j]); |
237 | else | 235 | else |
238 | output.Append("."); | 236 | output.Append("."); |
239 | } | 237 | } |
@@ -250,7 +248,6 @@ namespace OpenSim.Framework | |||
250 | /// <returns>An IP address, or null</returns> | 248 | /// <returns>An IP address, or null</returns> |
251 | public static IPAddress GetHostFromDNS(string dnsAddress) | 249 | public static IPAddress GetHostFromDNS(string dnsAddress) |
252 | { | 250 | { |
253 | |||
254 | // Is it already a valid IP? No need to look it up. | 251 | // Is it already a valid IP? No need to look it up. |
255 | IPAddress ipa; | 252 | IPAddress ipa; |
256 | if (IPAddress.TryParse(dnsAddress, out ipa)) | 253 | if (IPAddress.TryParse(dnsAddress, out ipa)) |
@@ -261,7 +258,7 @@ namespace OpenSim.Framework | |||
261 | 258 | ||
262 | foreach (IPAddress host in hosts) | 259 | foreach (IPAddress host in hosts) |
263 | { | 260 | { |
264 | if (host.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) | 261 | if (host.AddressFamily == AddressFamily.InterNetwork) |
265 | { | 262 | { |
266 | return host; | 263 | return host; |
267 | } | 264 | } |
@@ -281,7 +278,7 @@ namespace OpenSim.Framework | |||
281 | 278 | ||
282 | foreach (IPAddress host in hosts) | 279 | foreach (IPAddress host in hosts) |
283 | { | 280 | { |
284 | if (!IPAddress.IsLoopback(host) && host.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) | 281 | if (!IPAddress.IsLoopback(host) && host.AddressFamily == AddressFamily.InterNetwork) |
285 | { | 282 | { |
286 | return host; | 283 | return host; |
287 | } | 284 | } |
@@ -302,7 +299,7 @@ namespace OpenSim.Framework | |||
302 | string temp; | 299 | string temp; |
303 | // string personal=(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); | 300 | // string personal=(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); |
304 | // temp = Path.Combine(personal,".OpenSim"); | 301 | // temp = Path.Combine(personal,".OpenSim"); |
305 | temp="."; | 302 | temp = "."; |
306 | return temp; | 303 | return temp; |
307 | } | 304 | } |
308 | 305 | ||
@@ -349,9 +346,9 @@ namespace OpenSim.Framework | |||
349 | } | 346 | } |
350 | 347 | ||
351 | // Nini (config) related Methods | 348 | // Nini (config) related Methods |
352 | public static IConfigSource ConvertDataRowToXMLConfig(System.Data.DataRow row, string fileName) | 349 | public static IConfigSource ConvertDataRowToXMLConfig(DataRow row, string fileName) |
353 | { | 350 | { |
354 | if(!File.Exists(fileName)) | 351 | if (!File.Exists(fileName)) |
355 | { | 352 | { |
356 | //create new file | 353 | //create new file |
357 | } | 354 | } |
@@ -362,13 +359,13 @@ namespace OpenSim.Framework | |||
362 | return config; | 359 | return config; |
363 | } | 360 | } |
364 | 361 | ||
365 | public static void AddDataRowToConfig(IConfigSource config, System.Data.DataRow row) | 362 | public static void AddDataRowToConfig(IConfigSource config, DataRow row) |
366 | { | 363 | { |
367 | config.Configs.Add((string)row[0]); | 364 | config.Configs.Add((string) row[0]); |
368 | for (int i = 0; i < row.Table.Columns.Count; i++) | 365 | for (int i = 0; i < row.Table.Columns.Count; i++) |
369 | { | 366 | { |
370 | config.Configs[(string)row[0]].Set(row.Table.Columns[i].ColumnName, row[i]); | 367 | config.Configs[(string) row[0]].Set(row.Table.Columns[i].ColumnName, row[i]); |
371 | } | 368 | } |
372 | } | 369 | } |
373 | } | 370 | } |
374 | } | 371 | } \ No newline at end of file |