private int SafelyGetInt(string name, int def)
 {
     try {
         if (device.PropertyExists(name))
         {
             return(device.GetPropertyInteger(name));
         }
     } catch {}
     return(def);
 }
Exemplo n.º 2
0
        private static Stack <Hal.Device> CollectUsbDeviceStack(Hal.Device device)
        {
            Stack <Hal.Device> device_stack = new Stack <Hal.Device> ();
            int usb_vendor_id  = -1;
            int usb_product_id = -1;

            Hal.Device tmp_device = device;

            while (tmp_device != null)
            {
                // Skip the SCSI parents of the volume if they are in the tree
                if ((tmp_device.PropertyExists("info.bus") && tmp_device["info.bus"] == "scsi") ||
                    (tmp_device.PropertyExists("info.category") && tmp_device["info.category"] == "scsi_host"))
                {
                    device_stack.Push(tmp_device);
                    tmp_device = tmp_device.Parent;
                    continue;
                }

                bool have_usb_ids    = false;
                int  _usb_vendor_id  = -1;
                int  _usb_product_id = -1;

                // Figure out the IDs if they exist
                if (tmp_device.PropertyExists("usb.vendor_id") &&
                    tmp_device.PropertyExists("usb.product_id"))
                {
                    _usb_vendor_id  = tmp_device.GetPropertyInteger("usb.vendor_id");
                    _usb_product_id = tmp_device.GetPropertyInteger("usb.product_id");
                    have_usb_ids    = true;
                }
                else if (tmp_device.PropertyExists("usb_device.vendor_id") &&
                         tmp_device.PropertyExists("usb_device.product_id"))
                {
                    _usb_vendor_id  = tmp_device.GetPropertyInteger("usb_device.vendor_id");
                    _usb_product_id = tmp_device.GetPropertyInteger("usb_device.product_id");
                    have_usb_ids    = true;
                }

                if (have_usb_ids)
                {
                    if (usb_vendor_id == -1 && usb_product_id == -1)
                    {
                        // We found the first raw USB device, remember it
                        usb_vendor_id  = _usb_vendor_id;
                        usb_product_id = _usb_product_id;
                    }
                    else if (usb_vendor_id != _usb_vendor_id || usb_product_id != _usb_product_id)
                    {
                        // We are no longer looking at the device we care about (could now be at a hub or something)
                        break;
                    }
                }
                else if (usb_vendor_id != -1 || usb_product_id != -1)
                {
                    // We are no longer even looking at USB devices
                    break;
                }

                device_stack.Push(tmp_device);
                tmp_device = tmp_device.Parent;
            }

            return(device_stack);
        }
Exemplo n.º 3
0
 public int GetPropertyInteger(string key)
 {
     return(device.GetPropertyInteger(key));
 }