# HG changeset patch
# User StephaneLenclud
# Date 1441133826 -7200
# Node ID 728fe28168e22b609c64a3f92663ab4a6af26412
# Parent 8d169afc8bf5c62952eb4bf71b49d0b4e0c2cea9
Optical Drive Eject: ground work.
diff -r 8d169afc8bf5 -r 728fe28168e2 Server/MainForm.Hid.cs
--- a/Server/MainForm.Hid.cs Wed Aug 12 21:02:43 2015 +0200
+++ b/Server/MainForm.Hid.cs Tue Sep 01 20:57:06 2015 +0200
@@ -7,6 +7,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
+using Microsoft.Win32.SafeHandles;
//
using Hid = SharpLib.Hid;
using SharpLib.Win32;
@@ -112,44 +113,81 @@
}
else
{
+ if (aHidEvent.Usages.Count == 0)
+ {
+ //No usage, nothing to do then
+ return;
+ }
+
//We are in the proper thread
- if (aHidEvent.Usages.Count > 0
- && aHidEvent.UsagePage == (ushort)Hid.UsagePage.WindowsMediaCenterRemoteControl
- && aHidEvent.Usages[0] == (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.GreenStart)
- //&& aHidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer
- //&& aHidEvent.Usages[0] == (ushort)Hid.Usage.ConsumerControl.ThinkPadFullscreenMagnifier)
+ if (aHidEvent.UsagePage == (ushort) Hid.UsagePage.WindowsMediaCenterRemoteControl)
{
- //First check if the process we want to launch already exists
- string procName = Path.GetFileNameWithoutExtension(Properties.Settings.Default.StartFileName);
- Process[] existingProcesses = Process.GetProcessesByName(procName);
- if (existingProcesses == null || existingProcesses.Length == 0)
+ switch (aHidEvent.Usages[0])
{
- // Process do not exists just try to launch it
- ProcessStartInfo start = new ProcessStartInfo();
- // Enter in the command line arguments, everything you would enter after the executable name itself
- //start.Arguments = arguments;
- // Enter the executable to run, including the complete path
- start.FileName = Properties.Settings.Default.StartFileName;
- start.WindowStyle = ProcessWindowStyle.Normal;
- start.CreateNoWindow = true;
- start.UseShellExecute = true;
- // Run the external process & wait for it to finish
- Process proc = Process.Start(start);
-
- //SL: We could have used that too
- //Shell32.Shell shell = new Shell32.Shell();
- //shell.ShellExecute(Properties.Settings.Default.StartFileName);
- }
- else
- {
- //This won't work properly until we have a manifest that enables uiAccess.
- //However uiAccess just won't work with ClickOnce so we will have to use a different deployment system.
- SwitchToThisWindow(existingProcesses[0].MainWindowHandle, true);
+ case (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.GreenStart:
+ HandleGreenStart();
+ break;
+ case (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.Eject:
+ case (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.Ext2:
+ HandleEject();
+ break;
}
}
}
}
+ private SafeFileHandle OpenVolume()
+ {
+ return Function.CreateFile( "E:",
+ SharpLib.Win32.FileAccess.GENERIC_READ,
+ SharpLib.Win32.FileShare.FILE_SHARE_READ | SharpLib.Win32.FileShare.FILE_SHARE_WRITE,
+ IntPtr.Zero,
+ CreationDisposition.OPEN_EXISTING,
+ 0,
+ IntPtr.Zero);
+ }
+
+ ///
+ ///
+ ///
+ private void HandleEject()
+ {
+ SafeFileHandle handle = OpenVolume();
+ }
+
+ ///
+ ///
+ ///
+ private void HandleGreenStart()
+ {
+ //First check if the process we want to launch already exists
+ string procName = Path.GetFileNameWithoutExtension(Properties.Settings.Default.StartFileName);
+ Process[] existingProcesses = Process.GetProcessesByName(procName);
+ if (existingProcesses == null || existingProcesses.Length == 0)
+ {
+ // Process do not exists just try to launch it
+ ProcessStartInfo start = new ProcessStartInfo();
+ // Enter in the command line arguments, everything you would enter after the executable name itself
+ //start.Arguments = arguments;
+ // Enter the executable to run, including the complete path
+ start.FileName = Properties.Settings.Default.StartFileName;
+ start.WindowStyle = ProcessWindowStyle.Normal;
+ start.CreateNoWindow = true;
+ start.UseShellExecute = true;
+ // Run the external process & wait for it to finish
+ Process proc = Process.Start(start);
+
+ //SL: We could have used that too
+ //Shell32.Shell shell = new Shell32.Shell();
+ //shell.ShellExecute(Properties.Settings.Default.StartFileName);
+ }
+ else
+ {
+ //This won't work properly until we have a manifest that enables uiAccess.
+ //However uiAccess just won't work with ClickOnce so we will have to use a different deployment system.
+ SwitchToThisWindow(existingProcesses[0].MainWindowHandle, true);
+ }
+ }
///
/// We need to handle WM_INPUT.
///
diff -r 8d169afc8bf5 -r 728fe28168e2 Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj Wed Aug 12 21:02:43 2015 +0200
+++ b/Server/SharpDisplayManager.csproj Tue Sep 01 20:57:06 2015 +0200
@@ -115,12 +115,13 @@
False
..\packages\NAudio.1.7.3\lib\net35\NAudio.dll
-
+
+ ..\packages\SharpLibHid.1.2.1\lib\net20\SharpLibHid.dll
+ True
+
+
False
- ..\packages\SharpLibHid.1.2.0\lib\net20\SharpLibHid.dll
-
-
- ..\packages\SharpLibWin32.0.0.3\lib\net20\SharpLibWin32.dll
+ ..\packages\SharpLibWin32.0.0.4\lib\net20\SharpLibWin32.dll
diff -r 8d169afc8bf5 -r 728fe28168e2 Server/packages.config
--- a/Server/packages.config Wed Aug 12 21:02:43 2015 +0200
+++ b/Server/packages.config Tue Sep 01 20:57:06 2015 +0200
@@ -2,6 +2,6 @@
-
-
+
+
\ No newline at end of file