[banshee] [PlatformDetection] more extensive probing
- From: Aaron Bockover <abock src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee] [PlatformDetection] more extensive probing
- Date: Sun, 7 Feb 2010 18:19:29 +0000 (UTC)
commit fa065289a9dd2d5a240898372e4ed1741c567416
Author: Aaron Bockover <abockover novell com>
Date: Sun Feb 7 12:52:56 2010 -0500
[PlatformDetection] more extensive probing
Renamed PlatformUtil to PlatformDetection, and implemented more
extensive probing. Detects Windows, Linux, Unix, and Mac OS X,
and will detect environments like Moblin, GNOME, etc. later.
src/Libraries/Hyena/Hyena.csproj | 4 +-
src/Libraries/Hyena/Hyena/PlatformDetection.cs | 90 ++++++++++++++++++++++++
src/Libraries/Hyena/Hyena/PlatformUtil.cs | 45 ------------
src/Libraries/Hyena/Makefile.am | 2 +-
4 files changed, 94 insertions(+), 47 deletions(-)
---
diff --git a/src/Libraries/Hyena/Hyena.csproj b/src/Libraries/Hyena/Hyena.csproj
index fa80869..867790a 100644
--- a/src/Libraries/Hyena/Hyena.csproj
+++ b/src/Libraries/Hyena/Hyena.csproj
@@ -34,6 +34,7 @@
</CustomCommands>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Windows|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -41,6 +42,7 @@
<PlatformTarget>x86</PlatformTarget>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
+ <OutputPath>bin\Windows</OutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="Hyena.Data\BaseListModel.cs" />
@@ -118,7 +120,6 @@
<Compile Include="Hyena.Data.Sqlite\SqliteUtils.cs" />
<Compile Include="Hyena\Log.cs" />
<Compile Include="Hyena\CryptoUtil.cs" />
- <Compile Include="Hyena\PlatformUtil.cs" />
<Compile Include="Hyena.Query\IntegerKeyedObjectQueryValue.cs" />
<Compile Include="Hyena\ConsoleCrayon.cs" />
<Compile Include="Hyena\ApplicationContext.cs" />
@@ -167,6 +168,7 @@
<Compile Include="Hyena\EventArgs.cs" />
<Compile Include="System.Web\Helpers.cs" />
<Compile Include="System.Web\HttpUtility.cs" />
+ <Compile Include="Hyena\PlatformDetection.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Mono.Posix">
diff --git a/src/Libraries/Hyena/Hyena/PlatformDetection.cs b/src/Libraries/Hyena/Hyena/PlatformDetection.cs
new file mode 100644
index 0000000..42418ee
--- /dev/null
+++ b/src/Libraries/Hyena/Hyena/PlatformDetection.cs
@@ -0,0 +1,90 @@
+//
+// PlatformUtil.cs
+//
+// Author:
+// Aaron Bockover <abockover novell com>
+//
+// Copyright 2010 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Hyena
+{
+ public static class PlatformDetection
+ {
+ public static readonly bool IsMac;
+ public static readonly bool IsWindows;
+ public static readonly bool IsLinux;
+ public static readonly bool IsUnix;
+ public static readonly bool IsPosix;
+ public static readonly bool IsMoblin;
+
+ public static readonly string PosixSystemName;
+
+ [DllImport ("libc")]
+ private static extern int uname (IntPtr utsname);
+
+ static PlatformDetection ()
+ {
+ // From http://www.mono-project.com/FAQ:_Technical
+ int p = (int)Environment.OSVersion.Platform;
+ IsUnix = p == 4 || p == 6 || p == 128;
+ IsWindows = p < 4;
+
+ if (IsWindows) {
+ return;
+ }
+
+ // uname expects a pointer to a utsname structure, but we are
+ // tricky here - this structure's first field is the field we
+ // care about (char sysname []); the size of the structure is
+ // unknown, as it varies on all platforms. Darwin uses only
+ // the five POSIX fields, each 256 bytes, so the total size is
+ // total size is 5 * 256 = 1280 bytes. Arbitrarily using 8192.
+ var utsname = IntPtr.Zero;
+ try {
+ utsname = Marshal.AllocHGlobal (8192);
+ if (uname (utsname) == 0) {
+ PosixSystemName = Marshal.PtrToStringAnsi (utsname);
+ }
+ } catch {
+ } finally {
+ if (utsname != IntPtr.Zero) {
+ Marshal.FreeHGlobal (utsname);
+ }
+ }
+
+ if (PosixSystemName == null) {
+ return;
+ }
+
+ switch (PosixSystemName) {
+ case "Darwin": IsMac = true; break;
+ case "Linux": IsLinux = true; break;
+ }
+
+ // FIXME: probe the root X11 window for Moblin properties
+ }
+ }
+}
diff --git a/src/Libraries/Hyena/Makefile.am b/src/Libraries/Hyena/Makefile.am
index 715b5bd..e36b92c 100644
--- a/src/Libraries/Hyena/Makefile.am
+++ b/src/Libraries/Hyena/Makefile.am
@@ -115,7 +115,7 @@ SOURCES = \
Hyena/EventArgs.cs \
Hyena/IUndoAction.cs \
Hyena/Log.cs \
- Hyena/PlatformUtil.cs \
+ Hyena/PlatformDetection.cs \
Hyena/StringUtil.cs \
Hyena/Tests/CryptoUtilTests.cs \
Hyena/Tests/StringUtilTests.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]