コード例 #1
0
        private void ComboBox_Devices_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            button_GenerateData.IsEnabled = false;
            button_WriteData.IsEnabled    = false;

            if (e.AddedItems.OfType <UsbDeviceArrivedEventArgs>().SingleOrDefault() is UsbDeviceArrivedEventArgs args)
            {
                var diskSpaceLayout = args.USBDeviceInfo.DiskSpaceLayout;
                var bootSectorInfo  = args.USBDeviceInfo.BootSectorInfo;


                textBox_Serial.Text = args.USBDeviceInfo.DeviceInfo?.DeviceSerialNumber;

                textBox_VolumeSerial.Text = bootSectorInfo?.VolumeSerialNumber.ToString();

                textBox_FileSystemQ.Text = bootSectorInfo?.FileSystemName_Query;
                textBox_FileSystemM.Text = bootSectorInfo?.FileSystemName_Parsed;

                textBox_BytesPerSectorQ.Text = diskSpaceLayout?.lpBytesPerSector.ToString();
                textBox_BytesPerSectorM.Text = bootSectorInfo?.BytesPerSector.ToString();

                textBox_SectorsPerClusterQ.Text = diskSpaceLayout?.lpSectorsPerCluster.ToString();
                textBox_SectorsPerClusterM.Text = bootSectorInfo?.SectorsPerCluster.ToString();

                textBox_ReservedSectorsM.Text = bootSectorInfo?.ReservedSectors.ToString();


                if (TryGetData(args, out var data))
                {
                    bool dataFound = false;

                    button_GenerateData.IsEnabled = true;
                    button_WriteData.IsEnabled    = true;

                    for (int x = 0; x < data.Length; x++)
                    {
                        if (data[x] != 0)
                        {
                            dataFound = true;
                            break;
                        }
                    }

                    if (dataFound)
                    {
                        textBox_DataSector.Text = Win32Utils.ReadNullTerminatedString(data, 0, Encoding.ASCII);
                    }
                    else
                    {
                        textBox_DataSector.Text = "";
                    }
                }
            }
            else
            {
                textBox_Serial.Text = "";

                textBox_VolumeSerial.Text = "";

                textBox_FileSystemQ.Text = "";
                textBox_FileSystemM.Text = "";

                textBox_BytesPerSectorQ.Text = "";
                textBox_BytesPerSectorM.Text = "";

                textBox_SectorsPerClusterQ.Text = "";
                textBox_SectorsPerClusterM.Text = "";

                textBox_ReservedSectorsM.Text = "";

                textBox_DataSector.Text = "";
            }
        }