[f-spot] Don't crash in InfoBox if querying file info throws an Exception and/or metadata is null



commit 8762fbea43e66bdcc10a438119f083084ce90304
Author: Paul Wellner Bou <paul purecodes org>
Date:   Thu Dec 16 09:17:30 2010 +0100

    Don't crash in InfoBox if querying file info throws an Exception and/or metadata is null
    
    https://bugzilla.gnome.org/show_bug.cgi?id=637283

 src/Clients/MainApp/FSpot.Widgets/InfoBox.cs |    5 ++++-
 src/Core/FSpot.Utils/FSpot.Utils/Metadata.cs |   12 +++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/src/Clients/MainApp/FSpot.Widgets/InfoBox.cs b/src/Clients/MainApp/FSpot.Widgets/InfoBox.cs
index cb7fd87..42488c4 100644
--- a/src/Clients/MainApp/FSpot.Widgets/InfoBox.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/InfoBox.cs
@@ -119,7 +119,10 @@ namespace FSpot.Widgets
                                     Func<IPhoto[], string> multiple_string)
         {
             Action<Widget, IPhoto, TagLib.Image.File> set_single = (widget, photo, metadata) => {
-                (widget as Label).Text = single_string (photo, metadata);
+                if (metadata != null)
+                    (widget as Label).Text = single_string (photo, metadata);
+                else
+                    (widget as Label).Text = Catalog.GetString ("(Unknown)");
             };
             
             Action<Widget, IPhoto[]> set_multiple = (widget, photos) => {
diff --git a/src/Core/FSpot.Utils/FSpot.Utils/Metadata.cs b/src/Core/FSpot.Utils/FSpot.Utils/Metadata.cs
index 6b71cfd..bf65a31 100644
--- a/src/Core/FSpot.Utils/FSpot.Utils/Metadata.cs
+++ b/src/Core/FSpot.Utils/FSpot.Utils/Metadata.cs
@@ -39,9 +39,15 @@ namespace FSpot.Utils
         public static TagLib.Image.File Parse (SafeUri uri)
         {
             // Detect mime-type
-            var gfile = FileFactory.NewForUri (uri);
-            var info = gfile.QueryInfo ("standard::content-type", FileQueryInfoFlags.None, null);
-            var mime = info.ContentType;
+            string mime;
+            try {
+                var gfile = FileFactory.NewForUri (uri);
+                var info = gfile.QueryInfo ("standard::content-type", FileQueryInfoFlags.None, null);
+                mime = info.ContentType;
+            } catch (Exception e) {
+                Hyena.Log.DebugException (e);
+                return null;
+            }
 
             if (mime.StartsWith ("application/x-extension-")) {
                 // Works around broken metadata detection - https://bugzilla.gnome.org/show_bug.cgi?id=624781



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