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>
|
/// <para>Create a new <see cref="StorageDisk"/> from the letter</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="UnitMask"></param>
|
/// <param name="UnitMask"></param>
|
||||||
public StorageDisk(int UnitMask) : base("")
|
public StorageDisk(uint UnitMask) : base("")
|
||||||
{
|
{
|
||||||
char letter = FirstDriveFromMask(UnitMask);
|
char letter = FirstDriveFromMask(UnitMask);
|
||||||
this.Id = "";
|
this.Id = "";
|
||||||
|
@ -165,9 +165,9 @@ namespace Trigger.Classes.Device
|
||||||
/// </summary>
|
/// </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>
|
/// <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>
|
/// <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)
|
for (i = (char)0; i < 26; ++i)
|
||||||
{
|
{
|
||||||
|
@ -184,7 +184,7 @@ namespace Trigger.Classes.Device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="UnitMask"></param>
|
/// <param name="UnitMask"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal static StorageDisk FromUnitMask(int UnitMask)
|
internal static StorageDisk FromUnitMask(uint UnitMask)
|
||||||
{
|
{
|
||||||
if (UnitMask == 0)
|
if (UnitMask == 0)
|
||||||
return new StorageDisk(null, null, null);
|
return new StorageDisk(null, null, null);
|
||||||
|
@ -192,16 +192,21 @@ namespace Trigger.Classes.Device
|
||||||
char Letter = FirstDriveFromMask(UnitMask);
|
char Letter = FirstDriveFromMask(UnitMask);
|
||||||
StorageDisk sd = null;
|
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();
|
ManagementObjectCollection partitions = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_LogicalDisk.DeviceID='{0}:'}} WHERE AssocClass = Win32_LogicalDiskToPartition", Letter)).Get();
|
||||||
foreach (ManagementObject partition in partitions)
|
if (partitions != null)
|
||||||
{
|
{
|
||||||
ManagementObjectCollection disks = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{0}'}} WHERE AssocClass = Win32_DiskDriveToDiskPartition", partition["DeviceID"])).Get();
|
foreach (ManagementObject partition in partitions)
|
||||||
foreach (ManagementObject disk in disks)
|
{
|
||||||
{
|
ManagementObjectCollection disks = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{0}'}} WHERE AssocClass = Win32_DiskDriveToDiskPartition", partition["DeviceID"])).Get();
|
||||||
sd = CreateStorageDiskFromDrive(disk);
|
foreach (ManagementObject disk in disks)
|
||||||
break;
|
{
|
||||||
}
|
sd = CreateStorageDiskFromDrive(disk);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sd == null)
|
if (sd == null)
|
||||||
{
|
{
|
||||||
ManagementObjectCollection cdroms = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_CdRomDrive WHERE Drive = '{0}:\'", Letter)).Get();
|
ManagementObjectCollection cdroms = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_CdRomDrive WHERE Drive = '{0}:\'", Letter)).Get();
|
||||||
|
@ -212,12 +217,15 @@ namespace Trigger.Classes.Device
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ManagementObjectCollection volumes = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = '{0}:'", Letter)).Get();
|
if (sd != null)
|
||||||
foreach (ManagementObject volume in volumes)
|
{
|
||||||
{
|
ManagementObjectCollection volumes = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = '{0}:'", Letter)).Get();
|
||||||
sd.AddPartition(new Partition(volume));
|
foreach (ManagementObject volume in volumes)
|
||||||
break;
|
{
|
||||||
}
|
sd.AddPartition(new Partition(volume));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return sd;
|
return sd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,7 @@ namespace Trigger.Classes.System
|
||||||
/// <para>The size of this structure, in bytes.</para>
|
/// <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>
|
/// <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>
|
/// </summary>
|
||||||
public int dbcv_size;
|
public uint dbcv_size;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>The device type, which determines the event-specific information that follows the first three members.</para>
|
/// <para>The device type, which determines the event-specific information that follows the first three members.</para>
|
||||||
/// </summary>
|
/// </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_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>
|
/// <para>DBT_DEVTYP_VOLUME (0x2): Logical dbcv. This structure is a DEV_BROADCAST_VOLUME structure.</para>
|
||||||
/// </exexample>
|
/// </exexample>
|
||||||
public int dbcv_devicetype;
|
public uint dbcv_devicetype;
|
||||||
/// <summary><para>Reserved; do not use.</para></summary>
|
/// <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>
|
/// <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>
|
/// <summary><para>DBTF_MEDIA=0x01, DBTF_NET=0x02 (bitmask)</para></summary>
|
||||||
public short dbcv_flags;
|
public ushort dbcv_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -254,14 +254,14 @@ namespace Trigger.Events
|
||||||
{
|
{
|
||||||
#region case DBT.DEVICEARRIVLE:
|
#region case DBT.DEVICEARRIVLE:
|
||||||
case DBT.DEVICEARRIVAL:
|
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);
|
((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)
|
if (OnMediaInserted != null)
|
||||||
OnMediaInserted(null, new EventArgsValue<Classes.Device.Device>(device));
|
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)
|
if (OnNetworkVolumeArrived != null)
|
||||||
OnNetworkVolumeArrived(null, new EventArgsValue<Classes.Device.Device>(device));
|
OnNetworkVolumeArrived(null, new EventArgsValue<Classes.Device.Device>(device));
|
||||||
|
@ -293,9 +293,11 @@ namespace Trigger.Events
|
||||||
{
|
{
|
||||||
OnDeviceRemoved(null, new EventArgsValue<Classes.Device.Device>(oldDisk));
|
OnDeviceRemoved(null, new EventArgsValue<Classes.Device.Device>(oldDisk));
|
||||||
oldDisks.Remove(oldDisk);
|
oldDisks.Remove(oldDisk);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
StorageDisk unknownDisk = StorageDisk.FromUnitMask(dbcv.dbcv_unitmask);
|
||||||
|
OnDeviceRemoved(null, new EventArgsValue<Classes.Device.Device>(unknownDisk));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue