v0.5.3.0
authorStephaneLenclud
Wed, 02 Sep 2015 22:35:47 +0200
changeset 155703daa997f59
parent 154 5ecbb2f57a16
child 156 f6d93a560a78
v0.5.3.0
Publishing version with eject drive selection.
Updating to newest SharpLibWin32.
Adding ejection error checks.
Server/MainForm.Hid.cs
Server/SharpDisplayManager.csproj
Server/packages.config
     1.1 --- a/Server/MainForm.Hid.cs	Wed Sep 02 19:50:34 2015 +0200
     1.2 +++ b/Server/MainForm.Hid.cs	Wed Sep 02 22:35:47 2015 +0200
     1.3 @@ -8,6 +8,7 @@
     1.4  using System.Runtime.InteropServices;
     1.5  using System.Windows.Forms;
     1.6  using Microsoft.Win32.SafeHandles;
     1.7 +using System.ComponentModel;
     1.8  //
     1.9  using Hid = SharpLib.Hid;
    1.10  using SharpLib.Win32;
    1.11 @@ -146,6 +147,16 @@
    1.12          /// <summary>
    1.13          /// 
    1.14          /// </summary>
    1.15 +        /// <param name="aPrefix"></param>
    1.16 +        private void CheckLastError(string aPrefix)
    1.17 +        {
    1.18 +            string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
    1.19 +            Debug.WriteLine(aPrefix + Marshal.GetLastWin32Error().ToString() + ": " + errorMessage);
    1.20 +        }
    1.21 +
    1.22 +        /// <summary>
    1.23 +        /// 
    1.24 +        /// </summary>
    1.25          /// <param name="data"></param>
    1.26          /// <returns></returns>
    1.27          private IntPtr MarshalToPointer(object data)
    1.28 @@ -196,6 +207,8 @@
    1.29                  tries++;
    1.30              }
    1.31  
    1.32 +            CheckLastError("Lock volume: ");
    1.33 +
    1.34              return success;
    1.35          }
    1.36  
    1.37 @@ -211,7 +224,9 @@
    1.38              //Should not be needed but I'm not sure how to pass NULL in there.
    1.39              OVERLAPPED overlapped=new OVERLAPPED();
    1.40  
    1.41 -            return Function.DeviceIoControl(aVolume, Const.FSCTL_DISMOUNT_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped);
    1.42 +            bool res = Function.DeviceIoControl(aVolume, Const.FSCTL_DISMOUNT_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped);
    1.43 +            CheckLastError("Dismount volume: ");
    1.44 +            return res;
    1.45          }
    1.46  
    1.47  
    1.48 @@ -234,7 +249,7 @@
    1.49              IntPtr preventMediaRemovalParam = MarshalToPointer(preventMediaRemoval);
    1.50  
    1.51              bool result = Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_MEDIA_REMOVAL, preventMediaRemovalParam, Convert.ToUInt32(Marshal.SizeOf(preventMediaRemoval)), IntPtr.Zero, 0, dwBytesReturned, ref overlapped);
    1.52 -
    1.53 +            CheckLastError("Media removal: ");
    1.54              Marshal.FreeHGlobal(preventMediaRemovalParam);
    1.55  
    1.56              return result;
    1.57 @@ -252,7 +267,9 @@
    1.58              //Should not be needed but I'm not sure how to pass NULL in there.
    1.59              OVERLAPPED overlapped=new OVERLAPPED();
    1.60  
    1.61 -            return Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped);
    1.62 +            bool res = Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped);
    1.63 +            CheckLastError("Media eject: ");
    1.64 +            return res;
    1.65          }
    1.66  
    1.67          /// <summary>
    1.68 @@ -267,7 +284,9 @@
    1.69              //Should not be needed but I'm not sure how to pass NULL in there.
    1.70              OVERLAPPED overlapped=new OVERLAPPED();
    1.71  
    1.72 -            return Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_LOAD_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped);
    1.73 +            bool res = Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_LOAD_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped);
    1.74 +            CheckLastError("Media load: ");
    1.75 +            return res;
    1.76          }
    1.77  
    1.78          /// <summary>
    1.79 @@ -284,7 +303,7 @@
    1.80  
    1.81              bool res = Function.DeviceIoControl(aVolume, Const.IOCTL_STORAGE_CHECK_VERIFY2, IntPtr.Zero, 0, IntPtr.Zero, 0, dwBytesReturned, ref overlapped);
    1.82  
    1.83 -            Debug.WriteLine("Check Verify: " + Marshal.GetLastWin32Error().ToString());
    1.84 +            CheckLastError("Check verify: ");
    1.85  
    1.86              return res;
    1.87          }        
    1.88 @@ -307,7 +326,7 @@
    1.89              SafeFileHandle handle = OpenVolume(drive);
    1.90              if (handle.IsInvalid)
    1.91              {
    1.92 -                Debug.WriteLine("ERROR: Failed to open volume.");
    1.93 +                CheckLastError("ERROR: Failed to open volume: ");
    1.94                  return;
    1.95              }
    1.96  
    1.97 @@ -317,7 +336,7 @@
    1.98  
    1.99                  if (PreventRemovalOfVolume(handle,false))
   1.100                  {
   1.101 -                    //StorageCheckVerify(handle);
   1.102 +                   StorageCheckVerify(handle);
   1.103  
   1.104                      if (MediaEject(handle))
   1.105                      {
     2.1 --- a/Server/SharpDisplayManager.csproj	Wed Sep 02 19:50:34 2015 +0200
     2.2 +++ b/Server/SharpDisplayManager.csproj	Wed Sep 02 22:35:47 2015 +0200
     2.3 @@ -33,7 +33,7 @@
     2.4      <WebPage>index.htm</WebPage>
     2.5      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     2.6      <ApplicationRevision>0</ApplicationRevision>
     2.7 -    <ApplicationVersion>0.5.2.%2a</ApplicationVersion>
     2.8 +    <ApplicationVersion>0.5.3.%2a</ApplicationVersion>
     2.9      <UseApplicationTrust>false</UseApplicationTrust>
    2.10      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    2.11      <PublishWizardCompleted>true</PublishWizardCompleted>
    2.12 @@ -121,7 +121,7 @@
    2.13      </Reference>
    2.14      <Reference Include="SharpLibWin32, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
    2.15        <SpecificVersion>False</SpecificVersion>
    2.16 -      <HintPath>..\packages\SharpLibWin32.0.0.6\lib\net20\SharpLibWin32.dll</HintPath>
    2.17 +      <HintPath>..\packages\SharpLibWin32.0.0.7\lib\net20\SharpLibWin32.dll</HintPath>
    2.18      </Reference>
    2.19      <Reference Include="System" />
    2.20      <Reference Include="System.Configuration" />
     3.1 --- a/Server/packages.config	Wed Sep 02 19:50:34 2015 +0200
     3.2 +++ b/Server/packages.config	Wed Sep 02 22:35:47 2015 +0200
     3.3 @@ -3,5 +3,5 @@
     3.4    <package id="LibMiniDisplay" version="1.1.4" targetFramework="net45" />
     3.5    <package id="NAudio" version="1.7.3" targetFramework="net45" />
     3.6    <package id="SharpLibHid" version="1.2.1" targetFramework="net45" />
     3.7 -  <package id="SharpLibWin32" version="0.0.6" targetFramework="net45" />
     3.8 +  <package id="SharpLibWin32" version="0.0.7" targetFramework="net45" />
     3.9  </packages>
    3.10 \ No newline at end of file