[f-spot/stable-0.8] Move the check for corruption such that metadata parsing happens only once.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/stable-0.8] Move the check for corruption such that metadata parsing happens only once.
- Date: Fri, 22 Oct 2010 21:05:00 +0000 (UTC)
commit 04c4da84b12d2dde996220aafdd965f7d0743244
Author: Ruben Vermeersch <ruben savanne be>
Date: Fri Oct 22 22:55:44 2010 +0200
Move the check for corruption such that metadata parsing happens only once.
Makes import much much faster yet still robust.
.../MainApp/FSpot.Import/ImportController.cs | 4 +-
.../FSpot.Widgets/ThumbnailDateCaptionRenderer.cs | 3 ++
src/Core/FSpot.Core/FSpot.Core/FilePhoto.cs | 18 +++++++++-
.../FSpot.Core/FSpot.Core/IInvalidPhotoCheck.cs | 36 ++++++++++++++++++++
src/Core/FSpot.Core/Makefile.am | 1 +
5 files changed, 59 insertions(+), 3 deletions(-)
---
diff --git a/src/Clients/MainApp/FSpot.Import/ImportController.cs b/src/Clients/MainApp/FSpot.Import/ImportController.cs
index 72f9cbd..efffa83 100644
--- a/src/Clients/MainApp/FSpot.Import/ImportController.cs
+++ b/src/Clients/MainApp/FSpot.Import/ImportController.cs
@@ -343,9 +343,9 @@ namespace FSpot.Import
void ImportPhoto (IPhoto item, Roll roll)
{
- var metadata = Metadata.Parse (item.DefaultVersion.Uri);
- if (metadata == null)
+ if (item is IInvalidPhotoCheck && (item as IInvalidPhotoCheck).IsInvalid) {
throw new Exception ("Failed to parse metadata, probably not a photo");
+ }
var destination = FindImportDestination (item);
diff --git a/src/Clients/MainApp/FSpot.Widgets/ThumbnailDateCaptionRenderer.cs b/src/Clients/MainApp/FSpot.Widgets/ThumbnailDateCaptionRenderer.cs
index a8b795d..ef2c661 100644
--- a/src/Clients/MainApp/FSpot.Widgets/ThumbnailDateCaptionRenderer.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/ThumbnailDateCaptionRenderer.cs
@@ -57,6 +57,9 @@ namespace FSpot.Widgets
{
string date_text = null;
+ if (photo is IInvalidPhotoCheck && (photo as IInvalidPhotoCheck).IsInvalid)
+ return;
+
if (cell_area.Width > 200) {
date_text = photo.Time.ToString ();
} else {
diff --git a/src/Core/FSpot.Core/FSpot.Core/FilePhoto.cs b/src/Core/FSpot.Core/FSpot.Core/FilePhoto.cs
index 08ef0e0..02b3b01 100644
--- a/src/Core/FSpot.Core/FSpot.Core/FilePhoto.cs
+++ b/src/Core/FSpot.Core/FSpot.Core/FilePhoto.cs
@@ -21,7 +21,7 @@ using Mono.Unix.Native;
namespace FSpot.Core
{
- public class FilePhoto : IPhoto
+ public class FilePhoto : IPhoto, IInvalidPhotoCheck
{
bool metadata_parsed = false;
@@ -30,6 +30,20 @@ namespace FSpot.Core
DefaultVersion = new FilePhotoVersion { Uri = uri };
}
+ public bool IsInvalid {
+ get {
+ if (metadata_parsed)
+ return false;
+
+ try {
+ EnsureMetadataParsed ();
+ return false;
+ } catch (Exception) {
+ return true;
+ }
+ }
+ }
+
private void EnsureMetadataParsed ()
{
if (metadata_parsed)
@@ -40,6 +54,8 @@ namespace FSpot.Core
var date = metadata.ImageTag.DateTime;
time = date.HasValue ? date.Value : CreateDate;
description = metadata.ImageTag.Comment;
+ } else {
+ throw new Exception ("Corrupt File!");
}
}
diff --git a/src/Core/FSpot.Core/FSpot.Core/IInvalidPhotoCheck.cs b/src/Core/FSpot.Core/FSpot.Core/IInvalidPhotoCheck.cs
new file mode 100644
index 0000000..9cd981c
--- /dev/null
+++ b/src/Core/FSpot.Core/FSpot.Core/IInvalidPhotoCheck.cs
@@ -0,0 +1,36 @@
+//
+// IInvalidPhotoCheck.cs
+//
+// Author:
+// Ruben Vermeersch <ruben savanne be>
+//
+// Copyright (C) 2010 Novell, Inc.
+// Copyright (C) 2010 Ruben Vermeersch
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace FSpot.Core
+{
+ public interface IInvalidPhotoCheck
+ {
+ bool IsInvalid { get; }
+ }
+}
diff --git a/src/Core/FSpot.Core/Makefile.am b/src/Core/FSpot.Core/Makefile.am
index 4f96f15..fbee367 100644
--- a/src/Core/FSpot.Core/Makefile.am
+++ b/src/Core/FSpot.Core/Makefile.am
@@ -14,6 +14,7 @@ SOURCES = \
FSpot.Core/Global.cs \
FSpot.Core/IBrowsableCollection.cs \
FSpot.Core/IBrowsableItemChanges.cs \
+ FSpot.Core/IInvalidPhotoCheck.cs \
FSpot.Core/ILoadable.cs \
FSpot.Core/IPhoto.cs \
FSpot.Core/IPhotoComparer.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]