Bug fixes
This commit is contained in:
parent
86219f2650
commit
d0ca2edbfe
3 changed files with 39 additions and 29 deletions
|
@ -58,7 +58,7 @@ namespace Trigger.Classes.Device
|
|||
/// <para>Create a new <see cref="StorageDisk"/> from the letter</para>
|
||||
/// </summary>
|
||||
/// <param name="UnitMask"></param>
|
||||
public StorageDisk(int UnitMask) : base("")
|
||||
public StorageDisk(uint UnitMask) : base("")
|
||||
{
|
||||
char letter = FirstDriveFromMask(UnitMask);
|
||||
this.Id = "";
|
||||
|
@ -165,9 +165,9 @@ namespace Trigger.Classes.Device
|
|||
/// </summary>
|
||||
/// <param name="unitmask">The mask must be in the format bit 0 = A, bit 1 = B, bit 2 = C, and so on. A valid drive letter is defined when the corresponding bit is set to 1.</param>
|
||||
/// <returns>Returns the first drive letter that was found.</returns>
|
||||
internal static char FirstDriveFromMask(int unitmask)
|
||||
internal static char FirstDriveFromMask(uint unitmask)
|
||||
{
|
||||
int i;
|
||||
ushort i;
|
||||
|
||||
for (i = (char)0; i < 26; ++i)
|
||||
{
|
||||
|
@ -184,7 +184,7 @@ namespace Trigger.Classes.Device
|
|||
/// </summary>
|
||||
/// <param name="UnitMask"></param>
|
||||
/// <returns></returns>
|
||||
internal static StorageDisk FromUnitMask(int UnitMask)
|
||||
internal static StorageDisk FromUnitMask(uint UnitMask)
|
||||
{
|
||||
if (UnitMask == 0)
|
||||
return new StorageDisk(null, null, null);
|
||||
|
@ -192,7 +192,10 @@ namespace Trigger.Classes.Device
|
|||
char Letter = FirstDriveFromMask(UnitMask);
|
||||
StorageDisk sd = null;
|
||||
|
||||
// TODO: What if the disk is being removed?
|
||||
ManagementObjectCollection partitions = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_LogicalDisk.DeviceID='{0}:'}} WHERE AssocClass = Win32_LogicalDiskToPartition", Letter)).Get();
|
||||
if (partitions != null)
|
||||
{
|
||||
foreach (ManagementObject partition in partitions)
|
||||
{
|
||||
ManagementObjectCollection disks = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{0}'}} WHERE AssocClass = Win32_DiskDriveToDiskPartition", partition["DeviceID"])).Get();
|
||||
|
@ -202,6 +205,8 @@ namespace Trigger.Classes.Device
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sd == null)
|
||||
{
|
||||
ManagementObjectCollection cdroms = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_CdRomDrive WHERE Drive = '{0}:\'", Letter)).Get();
|
||||
|
@ -212,11 +217,14 @@ namespace Trigger.Classes.Device
|
|||
}
|
||||
}
|
||||
|
||||
if (sd != null)
|
||||
{
|
||||
ManagementObjectCollection volumes = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = '{0}:'", Letter)).Get();
|
||||
foreach (ManagementObject volume in volumes)
|
||||
{
|
||||
sd.AddPartition(new Partition(volume));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sd;
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ namespace Trigger.Classes.System
|
|||
/// <para>The size of this structure, in bytes.</para>
|
||||
/// <para>If this is a user-defined event, this member must be the size of this header, plus the size of the variable-length data in the DEV_BROADCAST_USERDEFINED structure.</para>
|
||||
/// </summary>
|
||||
public int dbcv_size;
|
||||
public uint dbcv_size;
|
||||
/// <summary>
|
||||
/// <para>The device type, which determines the event-specific information that follows the first three members.</para>
|
||||
/// </summary>
|
||||
|
@ -213,13 +213,13 @@ namespace Trigger.Classes.System
|
|||
/// <para>DBT_DEVTYP_PORT (0x3): Port device (serial or parallel). This structure is a DEV_BROADCAST_PORT structure.</para>
|
||||
/// <para>DBT_DEVTYP_VOLUME (0x2): Logical dbcv. This structure is a DEV_BROADCAST_VOLUME structure.</para>
|
||||
/// </exexample>
|
||||
public int dbcv_devicetype;
|
||||
public uint dbcv_devicetype;
|
||||
/// <summary><para>Reserved; do not use.</para></summary>
|
||||
public int dbcv_reserved;
|
||||
public uint dbcv_reserved;
|
||||
/// <summary><para>Bit 0=A, bit 1=B, and so on (bitmask)</para></summary>
|
||||
public int dbcv_unitmask;
|
||||
public uint dbcv_unitmask;
|
||||
/// <summary><para>DBTF_MEDIA=0x01, DBTF_NET=0x02 (bitmask)</para></summary>
|
||||
public short dbcv_flags;
|
||||
public ushort dbcv_flags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -254,14 +254,14 @@ namespace Trigger.Events
|
|||
{
|
||||
#region case DBT.DEVICEARRIVLE:
|
||||
case DBT.DEVICEARRIVAL:
|
||||
StorageDisk device = StorageDisk.FromUnitMask(dbcv.dbcv_unitmask);
|
||||
StorageDisk device = StorageDisk.FromUnitMask(dbcv.dbcv_unitmask); // Bug: unitmask = 0 when media inserted, flags passen auch nicht
|
||||
((List<StorageDisk>)oldStaticValues[EventType.DeviceRemoved]).Add(device);
|
||||
if (dbcv.dbcv_flags == 1 /*DBFT_MEDIA*/)
|
||||
if ((dbcv.dbcv_flags & 1 /*DBFT_MEDIA*/) == 1)
|
||||
{
|
||||
if (OnMediaInserted != null)
|
||||
OnMediaInserted(null, new EventArgsValue<Classes.Device.Device>(device));
|
||||
}
|
||||
else if (dbcv.dbcv_flags == 2 /*DBFT_NET*/)
|
||||
else if ((dbcv.dbcv_flags & 2 /*DBFT_NET*/) == 2)
|
||||
{
|
||||
if (OnNetworkVolumeArrived != null)
|
||||
OnNetworkVolumeArrived(null, new EventArgsValue<Classes.Device.Device>(device));
|
||||
|
@ -293,8 +293,10 @@ namespace Trigger.Events
|
|||
{
|
||||
OnDeviceRemoved(null, new EventArgsValue<Classes.Device.Device>(oldDisk));
|
||||
oldDisks.Remove(oldDisk);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
StorageDisk unknownDisk = StorageDisk.FromUnitMask(dbcv.dbcv_unitmask);
|
||||
OnDeviceRemoved(null, new EventArgsValue<Classes.Device.Device>(unknownDisk));
|
||||
}
|
||||
break;
|
||||
#endregion
|
||||
|
|
Loading…
Reference in a new issue