diff options
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 4b0b13c..efa4a7b 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -35,7 +35,8 @@ using System.IO; | |||
35 | using System.IO.Compression; | 35 | using System.IO.Compression; |
36 | using System.Net; | 36 | using System.Net; |
37 | using System.Net.Sockets; | 37 | using System.Net.Sockets; |
38 | using System.Reflection; | 38 | using System.Reflection; |
39 | using System.Runtime.InteropServices; | ||
39 | using System.Runtime.Serialization; | 40 | using System.Runtime.Serialization; |
40 | using System.Runtime.Serialization.Formatters.Binary; | 41 | using System.Runtime.Serialization.Formatters.Binary; |
41 | using System.Security.Cryptography; | 42 | using System.Security.Cryptography; |
@@ -375,6 +376,50 @@ namespace OpenSim.Framework | |||
375 | } | 376 | } |
376 | 377 | ||
377 | return sb.ToString(); | 378 | return sb.ToString(); |
379 | } | ||
380 | |||
381 | /// <summary> | ||
382 | /// Is the platform Windows? | ||
383 | /// </summary> | ||
384 | /// <returns>true if so, false otherwise</returns> | ||
385 | public static bool IsWindows() | ||
386 | { | ||
387 | PlatformID platformId = Environment.OSVersion.Platform; | ||
388 | |||
389 | return (platformId == PlatformID.Win32NT | ||
390 | || platformId == PlatformID.Win32S | ||
391 | || platformId == PlatformID.Win32Windows | ||
392 | || platformId == PlatformID.WinCE); | ||
393 | } | ||
394 | |||
395 | public static bool LoadArchSpecificWindowsDll(string libraryName) | ||
396 | { | ||
397 | // We do this so that OpenSimulator on Windows loads the correct native library depending on whether | ||
398 | // it's running as a 32-bit process or a 64-bit one. By invoking LoadLibary here, later DLLImports | ||
399 | // will find it already loaded later on. | ||
400 | // | ||
401 | // This isn't necessary for other platforms (e.g. Mac OSX and Linux) since the DLL used can be | ||
402 | // controlled in config files. | ||
403 | string nativeLibraryPath; | ||
404 | |||
405 | if (Util.Is64BitProcess()) | ||
406 | nativeLibraryPath = "lib64/" + libraryName; | ||
407 | else | ||
408 | nativeLibraryPath = "lib32/" + libraryName; | ||
409 | |||
410 | m_log.DebugFormat("[UTIL]: Loading native Windows library at {0}", nativeLibraryPath); | ||
411 | |||
412 | if (Util.LoadLibrary(nativeLibraryPath) == IntPtr.Zero) | ||
413 | { | ||
414 | m_log.ErrorFormat( | ||
415 | "[UTIL]: Couldn't find native Windows library at {0}", nativeLibraryPath); | ||
416 | |||
417 | return false; | ||
418 | } | ||
419 | else | ||
420 | { | ||
421 | return true; | ||
422 | } | ||
378 | } | 423 | } |
379 | 424 | ||
380 | public static bool IsEnvironmentSupported(ref string reason) | 425 | public static bool IsEnvironmentSupported(ref string reason) |
@@ -1457,6 +1502,27 @@ namespace OpenSim.Framework | |||
1457 | } | 1502 | } |
1458 | 1503 | ||
1459 | return data; | 1504 | return data; |
1505 | } | ||
1506 | |||
1507 | /// <summary> | ||
1508 | /// Used to trigger an early library load on Windows systems. | ||
1509 | /// </summary> | ||
1510 | /// <remarks> | ||
1511 | /// Required to get 32-bit and 64-bit processes to automatically use the | ||
1512 | /// appropriate native library. | ||
1513 | /// </remarks> | ||
1514 | /// <param name="dllToLoad"></param> | ||
1515 | /// <returns></returns> | ||
1516 | [DllImport("kernel32.dll")] | ||
1517 | public static extern IntPtr LoadLibrary(string dllToLoad); | ||
1518 | |||
1519 | /// <summary> | ||
1520 | /// Determine whether the current process is 64 bit | ||
1521 | /// </summary> | ||
1522 | /// <returns>true if so, false if not</returns> | ||
1523 | public static bool Is64BitProcess() | ||
1524 | { | ||
1525 | return IntPtr.Size == 8; | ||
1460 | } | 1526 | } |
1461 | 1527 | ||
1462 | #region FireAndForget Threading Pattern | 1528 | #region FireAndForget Threading Pattern |