|
From: <an...@us...> - 2007-03-06 02:54:43
|
Revision: 161
http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=161&view=rev
Author: and-81
Date: 2007-03-05 18:54:38 -0800 (Mon, 05 Mar 2007)
Log Message:
-----------
Added Paths:
-----------
trunk/plugins/IgorPlugUSB/
trunk/plugins/IgorPlugUSB/AssemblyInfo.cs
trunk/plugins/IgorPlugUSB/IgorPlug.dll
trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs
trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj
Removed Paths:
-------------
trunk/plugins/IgorPlugUSB/AssemblyInfo.cs
trunk/plugins/IgorPlugUSB/XBCDRC Plugin.csproj
trunk/plugins/IgorPlugUSB/XBCDRCPlugin.cs
Copied: trunk/plugins/IgorPlugUSB (from rev 151, trunk/plugins/XBCDRC)
Deleted: trunk/plugins/IgorPlugUSB/AssemblyInfo.cs
===================================================================
--- trunk/plugins/XBCDRC/AssemblyInfo.cs 2007-03-01 20:27:59 UTC (rev 151)
+++ trunk/plugins/IgorPlugUSB/AssemblyInfo.cs 2007-03-06 02:54:38 UTC (rev 161)
@@ -1,67 +0,0 @@
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Security.Permissions;
-
-//
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-//
-[assembly: AssemblyTitle("XBCDRC Plugin")]
-[assembly: AssemblyDescription("Supports the XBox 1 remote receiver using XBCDRC driver")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("and-81")]
-[assembly: AssemblyProduct("MediaPortal")]
-[assembly: AssemblyCopyright("Aaron Dinnage")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-//
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Revision and Build Numbers
-// by using the '*' as shown below:
-
-[assembly: AssemblyVersion("1.0.2.0")]
-
-//
-// In order to sign your assembly you must specify a key to use. Refer to the
-// Microsoft .NET Framework documentation for more information on assembly signing.
-//
-// Use the attributes below to control which key is used for signing.
-//
-// Notes:
-// (*) If no key is specified, the assembly is not signed.
-// (*) KeyName refers to a key that has been installed in the Crypto Service
-// Provider (CSP) on your machine. KeyFile refers to a file which contains
-// a key.
-// (*) If the KeyFile and the KeyName values are both specified, the
-// following processing occurs:
-// (1) If the KeyName can be found in the CSP, that key is used.
-// (2) If the KeyName does not exist and the KeyFile does exist, the key
-// in the KeyFile is installed into the CSP and used.
-// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
-// When specifying the KeyFile, the location of the KeyFile should be
-// relative to the project output directory which is
-// %Project Directory%\obj\<setupForm>. For example, if your KeyFile is
-// located in the project directory, you would specify the AssemblyKeyFile
-// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
-// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
-// documentation for more information on this.
-//
-[assembly: AssemblyDelaySign(false)]
-[assembly: AssemblyKeyFile("")]
-[assembly: AssemblyKeyName("")]
-[assembly: ComVisibleAttribute(false)]
-[assembly: AssemblyFileVersionAttribute("1.0.2.0")]
-
-[assembly: CLSCompliant(true)]
-
-[assembly: SecurityPermission(SecurityAction.RequestMinimum, UnmanagedCode = true)]
Copied: trunk/plugins/IgorPlugUSB/AssemblyInfo.cs (from rev 159, trunk/plugins/XBCDRC/AssemblyInfo.cs)
===================================================================
--- trunk/plugins/IgorPlugUSB/AssemblyInfo.cs (rev 0)
+++ trunk/plugins/IgorPlugUSB/AssemblyInfo.cs 2007-03-06 02:54:38 UTC (rev 161)
@@ -0,0 +1,67 @@
+using System;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Security.Permissions;
+
+//
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle("IgorPlugUSB Plugin")]
+[assembly: AssemblyDescription("Supports the Igor do-it-yourself IR receiver, USB version")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("and-81")]
+[assembly: AssemblyProduct("MediaPortal")]
+[assembly: AssemblyCopyright("Aaron Dinnage")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("1.0.2.0")]
+
+//
+// In order to sign your assembly you must specify a key to use. Refer to the
+// Microsoft .NET Framework documentation for more information on assembly signing.
+//
+// Use the attributes below to control which key is used for signing.
+//
+// Notes:
+// (*) If no key is specified, the assembly is not signed.
+// (*) KeyName refers to a key that has been installed in the Crypto Service
+// Provider (CSP) on your machine. KeyFile refers to a file which contains
+// a key.
+// (*) If the KeyFile and the KeyName values are both specified, the
+// following processing occurs:
+// (1) If the KeyName can be found in the CSP, that key is used.
+// (2) If the KeyName does not exist and the KeyFile does exist, the key
+// in the KeyFile is installed into the CSP and used.
+// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
+// When specifying the KeyFile, the location of the KeyFile should be
+// relative to the project output directory which is
+// %Project Directory%\obj\<setupForm>. For example, if your KeyFile is
+// located in the project directory, you would specify the AssemblyKeyFile
+// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
+// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
+// documentation for more information on this.
+//
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile("")]
+[assembly: AssemblyKeyName("")]
+[assembly: ComVisibleAttribute(false)]
+[assembly: AssemblyFileVersionAttribute("1.0.2.0")]
+
+[assembly: CLSCompliant(true)]
+
+[assembly: SecurityPermission(SecurityAction.RequestMinimum, UnmanagedCode = true)]
Added: trunk/plugins/IgorPlugUSB/IgorPlug.dll
===================================================================
(Binary files differ)
Property changes on: trunk/plugins/IgorPlugUSB/IgorPlug.dll
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs
===================================================================
--- trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs (rev 0)
+++ trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs 2007-03-06 02:54:38 UTC (rev 161)
@@ -0,0 +1,218 @@
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+using System.Threading;
+
+using Microsoft.Win32.SafeHandles;
+
+using MediaPortal.GUI.Library;
+using MediaPortal.InputDevices;
+
+namespace MediaPortal.Plugins
+{
+
+ public class IgorPlugUSB : IPlugin, ISetupForm, IDisposable
+ {
+
+ #region Variables
+
+ InputHandler _inputHandler;
+
+ Thread _readThread;
+
+ bool _disposed = false;
+
+ #endregion Variables
+
+ #region Interop
+
+ const int NO_ERROR = 0;
+ const int DEVICE_NOT_PRESENT = 1;
+ const int NO_DATA_AVAILABLE = 2;
+ const int INVALID_BAUDRATE = 3;
+ const int OVERRUN_ERROR = 4;
+
+ [DllImport("IgorPlug.dll", SetLastError = true)]
+ static extern int DoGetInfraCode(out byte[] TimeCodeDiagram, out int DiagramLength);
+
+ /*
+ static extern int DoSetDataPortDirection(uchar DirectionByte);
+ static extern int DoGetDataPortDirection(uchar* DataDirectionByte);
+ static extern int DoSetOutDataPort(uchar DataOutByte);
+ static extern int DoGetOutDataPort(uchar* DataOutByte);
+ static extern int DoGetInDataPort(uchar* DataInByte);
+ static extern int DoEEPROMRead(uchar Address, uchar* DataInByte);
+ static extern int DoEEPROMWrite(uchar Address, uchar DataOutByte);
+ static extern int DoRS232Send(uchar DataOutByte);
+ static extern int DoRS232Read(uchar* DataInByte);
+ static extern int DoSetRS232Baud(int BaudRate);
+ static extern int DoGetRS232Baud(int* BaudRate);
+ */
+
+ #endregion Interop
+
+ #region Deconstructor
+
+ ~IgorPlugUSB()
+ {
+ // call Dispose with false. Since we're in the
+ // destructor call, the managed resources will be
+ // disposed of anyways.
+ Dispose(false);
+ }
+
+ #endregion
+
+ #region IPlugin Members
+
+ public void Start()
+ {
+ Log.Info("IgorPlugUSB Plugin: Start");
+
+ try
+ {
+ _inputHandler = new InputHandler("IgorPlugUSB");
+
+ ThreadStart readThreadStart = new ThreadStart(ReadThread);
+ _readThread = new Thread(readThreadStart);
+ _readThread.Start();
+ }
+ catch (Exception ex)
+ {
+ Log.Error("IgorPlugUSB Plugin: {0}", ex.Message);
+ }
+ }
+
+ public void Stop()
+ {
+ Log.Info("IgorPlugUSB Plugin: Stop");
+
+ _readThread.Abort();
+ }
+
+ #endregion
+
+ #region ISetupForm Members
+
+ public string Author() { return "and-81"; }
+ public bool CanEnable() { return true; }
+ public bool DefaultEnabled() { return true; }
+ public string Description() { return "Supports the Igor USB remote receiver"; }
+ public int GetWindowId() { return 0; }
+ public bool HasSetup() { return true; }
+ public string PluginName() { return "IgorPlugUSB Plugin"; }
+
+ public void ShowPlugin()
+ {
+ InputMappingForm inputMappingForm = new InputMappingForm("IgorPlugUSB");
+ inputMappingForm.ShowDialog();
+ }
+
+ public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage)
+ {
+ strButtonText = strButtonImage = strButtonImageFocus = strPictureImage = "";
+ return false;
+ }
+
+ #endregion
+
+ #region IDisposable Members
+
+ public void Dispose()
+ {
+ // dispose of the managed and unmanaged resources
+ Dispose(true);
+
+ // tell the GC that the Finalize process no longer needs
+ // to be run for this object.
+ GC.SuppressFinalize(this);
+ }
+
+ #endregion
+
+ #region Implementation
+
+ protected virtual void Dispose(bool disposeManagedResources)
+ {
+ // process only if mananged and unmanaged resources have
+ // not been disposed of.
+ if (!this._disposed)
+ {
+ if (disposeManagedResources)
+ {
+
+ }
+
+ // dispose unmanaged resources
+ this._disposed = true;
+ }
+ }
+
+ void ReadThread()
+ {
+ try
+ {
+ byte[] deviceBuffer = new byte[256];
+ int codeLength;
+ int returnCode;
+ int keyCode;
+
+ int lastCode = -1;
+ DateTime lastCodeTime = DateTime.Now;
+ TimeSpan timeSpan;
+
+ while (true)
+ {
+ returnCode = DoGetInfraCode(out deviceBuffer, out codeLength);
+
+ switch (returnCode)
+ {
+ case NO_ERROR:
+ break;
+
+ case DEVICE_NOT_PRESENT:
+ throw new Exception("Device not present.");
+
+ case NO_DATA_AVAILABLE:
+ break;
+
+ case INVALID_BAUDRATE:
+ throw new Exception("Invalid baud rate.");
+
+ case OVERRUN_ERROR:
+ throw new Exception("Overrun error.");
+
+ default:
+ throw new Exception(string.Format("Unknown error ({0})", returnCode));
+ }
+
+ if (codeLength == 0)
+ continue;
+
+ keyCode = (int)deviceBuffer[3];
+ timeSpan = DateTime.Now - lastCodeTime;
+
+ if (keyCode != lastCode || timeSpan.Milliseconds > 250)
+ {
+ lastCode = keyCode;
+ lastCodeTime = DateTime.Now;
+ _inputHandler.MapAction(keyCode);
+ }
+
+ }
+ }
+ catch (ThreadAbortException)
+ {
+ Log.Info("IgorPlugUSB Plugin: IR read thread aborted.");
+ }
+ catch (Exception ex)
+ {
+ Log.Error("IgorPlugUSB Plugin: {0}", ex.Message);
+ }
+ }
+
+ #endregion Implementation
+
+ }
+
+}
Added: trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj
===================================================================
--- trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj (rev 0)
+++ trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj 2007-03-06 02:54:38 UTC (rev 161)
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{88520E4C-5C49-478A-8AFA-959B45075922}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>MediaPortal.Plugins</RootNamespace>
+ <AssemblyName>IgorPlugUSB</AssemblyName>
+ <StartupObject>
+ </StartupObject>
+ <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>false</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <UseVSHostingProcess>false</UseVSHostingProcess>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>
+ </DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <UseVSHostingProcess>false</UseVSHostingProcess>
+ </PropertyGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+ <ItemGroup>
+ <Compile Include="AssemblyInfo.cs" />
+ <Compile Include="IgorPlugUSB.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="Core, Version=1.0.2581.1884, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\MediaPortal\Core\bin\Release\Core.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="RemotePlugins, Version=1.0.2581.1913, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\MediaPortal\RemotePlugins\bin\Release\RemotePlugins.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml" />
+ <Reference Include="Utils, Version=1.0.2581.1867, Culture=neutral, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\MediaPortal\Utils\bin\Release\Utils.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ </ItemGroup>
+ <PropertyGroup>
+ <PostBuildEvent>copy "*.*" "\MediaPortal Development\Plugin Releases\IgorPlugUSB\"</PostBuildEvent>
+ </PropertyGroup>
+ <ItemGroup>
+ <Content Include="IgorPlug.dll">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+</Project>
\ No newline at end of file
Deleted: trunk/plugins/IgorPlugUSB/XBCDRC Plugin.csproj
===================================================================
--- trunk/plugins/XBCDRC/XBCDRC Plugin.csproj 2007-03-01 20:27:59 UTC (rev 151)
+++ trunk/plugins/IgorPlugUSB/XBCDRC Plugin.csproj 2007-03-06 02:54:38 UTC (rev 161)
@@ -1,75 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.50727</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{88520E4C-5C49-478A-8AFA-959B45075922}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>MediaPortal.Plugins</RootNamespace>
- <AssemblyName>XBCDRCPlugin</AssemblyName>
- <StartupObject>
- </StartupObject>
- <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>false</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
- <UseVSHostingProcess>false</UseVSHostingProcess>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>none</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>
- </DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
- <UseVSHostingProcess>false</UseVSHostingProcess>
- </PropertyGroup>
- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
- <ItemGroup>
- <Compile Include="AssemblyInfo.cs" />
- <Compile Include="XBCDRCPlugin.cs" />
- </ItemGroup>
- <ItemGroup>
- <Reference Include="Core, Version=1.0.2581.1884, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\MediaPortal\Core\bin\Release\Core.dll</HintPath>
- <Private>False</Private>
- </Reference>
- <Reference Include="RemotePlugins, Version=1.0.2581.1913, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\MediaPortal\RemotePlugins\bin\Release\RemotePlugins.dll</HintPath>
- <Private>False</Private>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Data" />
- <Reference Include="System.Windows.Forms" />
- <Reference Include="System.Xml" />
- <Reference Include="Utils, Version=1.0.2581.1867, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\MediaPortal\Utils\bin\Release\Utils.dll</HintPath>
- <Private>False</Private>
- </Reference>
- </ItemGroup>
- <PropertyGroup>
- <PostBuildEvent>copy "*.*" "\MediaPortal Development\Plugin Releases\XBCDRC Plugin\Release\"</PostBuildEvent>
- </PropertyGroup>
-</Project>
\ No newline at end of file
Deleted: trunk/plugins/IgorPlugUSB/XBCDRCPlugin.cs
===================================================================
--- trunk/plugins/XBCDRC/XBCDRCPlugin.cs 2007-03-01 20:27:59 UTC (rev 151)
+++ trunk/plugins/IgorPlugUSB/XBCDRCPlugin.cs 2007-03-06 02:54:38 UTC (rev 161)
@@ -1,383 +0,0 @@
-using System;
-using System.IO;
-using System.Runtime.InteropServices;
-
-using Microsoft.Win32.SafeHandles;
-
-using MediaPortal.GUI.Library;
-using MediaPortal.InputDevices;
-
-namespace MediaPortal.Plugins
-{
-
- public class XBCDRCPlugin : IPlugin, ISetupForm, IDisposable
- {
-
- #region Variables
-
- InputHandler _inputHandler;
- FileStream _deviceStream;
- byte[] _deviceBuffer;
-
- int _lastPacketID = 0;
- int _lastCode = -1;
- DateTime _lastCodeTime = DateTime.Now;
-
- bool _disposed = false;
-
- #endregion Variables
-
- #region Interop
-
- [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Auto)]
- static extern SafeFileHandle CreateFile(
- String fileName,
- [MarshalAs(UnmanagedType.U4)] FileAccess fileAccess,
- [MarshalAs(UnmanagedType.U4)] FileShare fileShare,
- IntPtr securityAttributes,
- [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
- [MarshalAs(UnmanagedType.U4)] EFileAttributes flags,
- IntPtr template);
-
- [Flags]
- enum EFileAttributes : uint
- {
- Readonly = 0x00000001,
- Hidden = 0x00000002,
- System = 0x00000004,
- Directory = 0x00000010,
- Archive = 0x00000020,
- Device = 0x00000040,
- Normal = 0x00000080,
- Temporary = 0x00000100,
- SparseFile = 0x00000200,
- ReparsePoint = 0x00000400,
- Compressed = 0x00000800,
- Offline = 0x00001000,
- NotContentIndexed = 0x00002000,
- Encrypted = 0x00004000,
- Write_Through = 0x80000000,
- Overlapped = 0x40000000,
- NoBuffering = 0x20000000,
- RandomAccess = 0x10000000,
- SequentialScan = 0x08000000,
- DeleteOnClose = 0x04000000,
- BackupSemantics = 0x02000000,
- PosixSemantics = 0x01000000,
- OpenReparsePoint = 0x00200000,
- OpenNoRecall = 0x00100000,
- FirstPipeInstance = 0x00080000
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct DeviceInfoData
- {
- public int Size;
- public Guid Class;
- public uint DevInst;
- public IntPtr Reserved;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- struct DeviceInterfaceData
- {
- public int Size;
- public Guid Class;
- public uint Flags;
- public uint Reserved;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- struct DeviceInterfaceDetailData
- {
- public int Size;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
- public string DevicePath;
- }
-
- [DllImport("hid")]
- static extern void HidD_GetHidGuid(
- ref Guid guid);
-
- [DllImport("setupapi", CharSet = CharSet.Auto)]
- static extern IntPtr SetupDiGetClassDevs(
- ref Guid ClassGuid,
- [MarshalAs(UnmanagedType.LPTStr)] string Enumerator,
- IntPtr hwndParent,
- UInt32 Flags);
-
- [DllImport("setupapi", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool SetupDiEnumDeviceInfo(
- IntPtr handle,
- int Index,
- ref DeviceInfoData deviceInfoData);
-
- [DllImport("setupapi", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool SetupDiEnumDeviceInterfaces(
- IntPtr handle,
- ref DeviceInfoData deviceInfoData,
- ref Guid guidClass,
- int MemberIndex,
- ref DeviceInterfaceData deviceInterfaceData);
-
- [DllImport("setupapi", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool SetupDiGetDeviceInterfaceDetail(
- IntPtr handle,
- ref DeviceInterfaceData deviceInterfaceData,
- IntPtr unused1,
- int unused2,
- ref uint requiredSize,
- IntPtr unused3);
-
- [DllImport("setupapi", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool SetupDiGetDeviceInterfaceDetail(
- IntPtr handle,
- ref DeviceInterfaceData deviceInterfaceData,
- ref DeviceInterfaceDetailData deviceInterfaceDetailData,
- uint detailSize,
- IntPtr unused1,
- IntPtr unused2);
-
- [DllImport("setupapi")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool SetupDiDestroyDeviceInfoList(IntPtr handle);
-
- #endregion Interop
-
- #region Deconstructor
-
- ~XBCDRCPlugin()
- {
- // call Dispose with false. Since we're in the
- // destructor call, the managed resources will be
- // disposed of anyways.
- Dispose(false);
- }
-
- #endregion
-
- #region IPlugin Members
-
- public void Start()
- {
- Log.Info("XBCDRC Plugin: Start");
-
- try
- {
- Guid guid = new Guid();
- HidD_GetHidGuid(ref guid);
-
- string devicePath = FindDevice(guid);
- if (devicePath == null)
- {
- Log.Error("XBCDRC Plugin: Could not find an Xbox remote receiver");
- return;
- }
-
- SafeFileHandle deviceHandle = CreateFile(devicePath, FileAccess.Read, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, EFileAttributes.Overlapped, IntPtr.Zero);
-
- if (deviceHandle.IsInvalid)
- Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
-
- //_deviceWatcher.RegisterDeviceRemoval(deviceHandle);
-
- _inputHandler = new InputHandler("XBox Remote");
-
- _deviceBuffer = new byte[7];
- _deviceStream = new FileStream(deviceHandle, FileAccess.Read, _deviceBuffer.Length, true);
- _deviceStream.BeginRead(_deviceBuffer, 0, _deviceBuffer.Length, new AsyncCallback(OnReadComplete), null);
- }
- catch (Exception ex)
- {
- Log.Error("XBCDRC Plugin: {0}", ex.Message);
- }
- }
-
- public void Stop()
- {
- Log.Info("XBCDRC Plugin: Stop");
-
- if (_deviceStream == null)
- return;
-
- try
- {
- _deviceStream.Close();
- }
- catch (IOException)
- {
- }
- }
-
- #endregion
-
- #region ISetupForm Members
-
- public string Author() { return "and-81"; }
- public bool CanEnable() { return true; }
- public bool DefaultEnabled() { return true; }
- public string Description() { return "Supports the XBox 1 remote receiver using XBCDRC driver"; }
- public int GetWindowId() { return 0; }
- public bool HasSetup() { return true; }
- public string PluginName() { return "XBCDRC Plugin"; }
-
- public void ShowPlugin()
- {
- InputMappingForm inputMappingForm = new InputMappingForm("XBox Remote");
- inputMappingForm.ShowDialog();
- }
-
- public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage)
- {
- strButtonText = strButtonImage = strButtonImageFocus = strPictureImage = "";
- return false;
- }
-
- #endregion
-
- #region IDisposable Members
-
- public void Dispose()
- {
- // dispose of the managed and unmanaged resources
- Dispose(true);
-
- // tell the GC that the Finalize process no longer needs
- // to be run for this object.
- GC.SuppressFinalize(this);
- }
-
- #endregion
-
- #region Implementation
-
- protected virtual void Dispose(bool disposeManagedResources)
- {
- // process only if mananged and unmanaged resources have
- // not been disposed of.
- if (!this._disposed)
- {
- if (disposeManagedResources)
- {
- // dispose managed resources
- if (_deviceStream != null)
- {
- _deviceStream.Dispose();
- _deviceStream = null;
- }
- }
-
- // dispose unmanaged resources
- this._disposed = true;
- }
- }
-
- static string FindDevice(Guid classGuid)
- {
- int lastError;
-
- // 0x12 = DIGCF_PRESENT or DIGCF_DEVICEINTERFACE
- IntPtr handle = SetupDiGetClassDevs(ref classGuid, "", IntPtr.Zero, 0x12);
- lastError = Marshal.GetLastWin32Error();
-
- if (handle.ToInt32() == -1)
- Marshal.ThrowExceptionForHR(lastError);
-
- string devicePath = null;
-
- for (int deviceIndex = 0; ; deviceIndex++)
- {
- DeviceInfoData deviceInfoData = new DeviceInfoData();
- deviceInfoData.Size = Marshal.SizeOf(deviceInfoData);
-
- if (SetupDiEnumDeviceInfo(handle, deviceIndex, ref deviceInfoData) == false)
- {
- // out of devices or do we have an error?
- lastError = Marshal.GetLastWin32Error();
- if (lastError != 0x0103 && lastError != 0x007E)
- {
- SetupDiDestroyDeviceInfoList(handle);
- Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
- }
-
- SetupDiDestroyDeviceInfoList(handle);
- break;
- }
-
- DeviceInterfaceData deviceInterfaceData = new DeviceInterfaceData();
- deviceInterfaceData.Size = Marshal.SizeOf(deviceInterfaceData);
-
- if (SetupDiEnumDeviceInterfaces(handle, ref deviceInfoData, ref classGuid, 0, ref deviceInterfaceData) == false)
- {
- SetupDiDestroyDeviceInfoList(handle);
- Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
- }
-
- uint cbData = 0;
-
- if (SetupDiGetDeviceInterfaceDetail(handle, ref deviceInterfaceData, IntPtr.Zero, 0, ref cbData, IntPtr.Zero) == false && cbData == 0)
- {
- SetupDiDestroyDeviceInfoList(handle);
- Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
- }
-
- DeviceInterfaceDetailData deviceInterfaceDetailData = new DeviceInterfaceDetailData();
- deviceInterfaceDetailData.Size = 5;
-
- if (SetupDiGetDeviceInterfaceDetail(handle, ref deviceInterfaceData, ref deviceInterfaceDetailData, cbData, IntPtr.Zero, IntPtr.Zero) == false)
- {
- SetupDiDestroyDeviceInfoList(handle);
- Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
- }
-
- if (deviceInterfaceDetailData.DevicePath.IndexOf("vid_045e&pid_0284") != -1)
- {
- SetupDiDestroyDeviceInfoList(handle);
- devicePath = deviceInterfaceDetailData.DevicePath;
- break;
- }
- }
-
- return devicePath;
- }
-
- void OnReadComplete(IAsyncResult asyncResult)
- {
- try
- {
- if (_deviceStream.EndRead(asyncResult) == 7 && _deviceBuffer[1] != 1)
- {
- int packetID = BitConverter.ToInt32(_deviceBuffer, 3);
-
- if (packetID != _lastPacketID)
- {
- _lastPacketID = packetID;
-
- TimeSpan timeSpan = DateTime.Now - _lastCodeTime;
- _lastCodeTime = DateTime.Now;
-
- int keyCode = (int)_deviceBuffer[3];
-
- if (keyCode != _lastCode || timeSpan.Milliseconds > 250)
- _inputHandler.MapAction(keyCode);
-
- _lastCode = keyCode;
- }
- }
-
- _deviceStream.BeginRead(_deviceBuffer, 0, _deviceBuffer.Length, new AsyncCallback(OnReadComplete), null);
- }
- catch (Exception)
- {
- }
- }
-
- #endregion Implementation
-
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|