[banshee] Hardware.Gio: Avoid NREs when getting bus number etc



commit 41b100fb5b8c2b5023ba5e3887ed9536d60c58ac
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Mon Mar 28 15:30:54 2011 -0500

    Hardware.Gio: Avoid NREs when getting bus number etc

 .../Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs  |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
index ff1b496..45afb85 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
@@ -72,20 +72,33 @@ namespace Banshee.Hardware.Gio
 
         public static int GetBusNumber (IUsbDevice device)
         {
+            int num = 0;
             var raw = device as IRawDevice;
-            return raw == null ? 0 : int.Parse (raw.Device.UdevMetadata.GetPropertyString (UdevUsbBusNumber));
+
+            if (raw != null && Int32.TryParse (raw.Device.UdevMetadata.GetPropertyString (UdevUsbBusNumber), out num)) {
+                return num;
+            }
+            return 0;
         }
 
         public static int GetDeviceNumber (IUsbDevice device)
         {
             var raw = device as IRawDevice;
-            return raw ==  null ? 0 : int.Parse (raw.Device.UdevMetadata.GetPropertyString (UdevUsbDeviceNumber));
+            int num = 0;
+            if (raw != null && Int32.TryParse (raw.Device.UdevMetadata.GetPropertyString (UdevUsbDeviceNumber), out num)) {
+                return num;
+            }
+            return 0;
         }
 
         public static int GetProductId (IUsbDevice device)
         {
             var raw = device as IRawDevice;
-            return raw == null ? 0 : int.Parse (raw.Device.UdevMetadata.GetPropertyString (UdevProductId), NumberStyles.HexNumber);
+            int num = 0;
+            if (raw != null && Int32.TryParse (raw.Device.UdevMetadata.GetPropertyString (UdevProductId), NumberStyles.HexNumber, null, out num)) {
+                return num;
+            }
+            return 0;
         }
 
         public static int GetSpeed (IUsbDevice device)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]