[f-spot/FSPOT_0_6_0_STABLE] copy files directly from camera to file system



commit c45bc4f5657101c20155dbbdf855a48959b4be90
Author: Stephane Delcroix <stephane delcroix org>
Date:   Fri Sep 25 22:37:13 2009 +0200

    copy files directly from camera to file system
    
    this avoids filling gigs of memory for video files. reauires libgphoto2 > 2.4, doesn't work on the directory driver.
    
    fixes bgo #596196

 lib/libgphoto2-sharp/Camera.cs   |   11 ++++++++++-
 lib/libgphoto2-sharp/Makefile.am |    2 +-
 lib/libgphoto2-sharp/Port.cs     |    7 ++++++-
 src/GPhotoCamera.cs              |   17 +++++++++++++++--
 4 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/lib/libgphoto2-sharp/Camera.cs b/lib/libgphoto2-sharp/Camera.cs
index 7179eab..8cfb8ea 100644
--- a/lib/libgphoto2-sharp/Camera.cs
+++ b/lib/libgphoto2-sharp/Camera.cs
@@ -4,6 +4,9 @@
  * Author(s):
  *	Ewen Cheslack-Postava <echeslack gmail com>
  *	Larry Ewing <lewing novell com>
+ *	Stephane Delcroix <stephane delcroix org>
+ *
+ * Copyright (c) 2005-2009 Novell, Inc.
  *
  * This is free software. See COPYING for details.
  */
@@ -299,7 +302,7 @@ namespace LibGPhoto2
 		
 
 		[DllImport ("libgphoto2.so")]
-		internal static extern ErrorCode gp_camera_file_get (HandleRef camera, string folder, string file, CameraFileType type, HandleRef camera_file, HandleRef context);
+		internal static extern ErrorCode gp_camera_file_get (HandleRef camera, [MarshalAs(UnmanagedType.LPTStr)] string folder, [MarshalAs(UnmanagedType.LPTStr)] string file, CameraFileType type, HandleRef camera_file, HandleRef context);
 		
 		public CameraFile GetFile (string folder, string name, CameraFileType type, Context context)
 		{
@@ -309,6 +312,12 @@ namespace LibGPhoto2
 
 			return file;
 		}
+
+		public void GetFile (string folder, string name, CameraFileType type, CameraFile camera_file, Context context)
+		{
+			Error.CheckError (gp_camera_file_get(this.Handle, folder, name, type, camera_file.Handle, context.Handle));
+			
+		}
 		
 		[DllImport ("libgphoto2.so")]
 		internal static extern ErrorCode gp_camera_file_delete (HandleRef camera, string folder, string file, HandleRef context);
diff --git a/lib/libgphoto2-sharp/Makefile.am b/lib/libgphoto2-sharp/Makefile.am
index 938b3e4..bd920e5 100644
--- a/lib/libgphoto2-sharp/Makefile.am
+++ b/lib/libgphoto2-sharp/Makefile.am
@@ -17,7 +17,7 @@ ASSEMBLY_SOURCES =			\
 	$(srcdir)/PortInfo.cs		\
 	$(srcdir)/PortInfoList.cs
 
-REFS =
+REFS =	-r:Mono.Posix
 
 PKGS =
 
diff --git a/lib/libgphoto2-sharp/Port.cs b/lib/libgphoto2-sharp/Port.cs
index 6dc87ff..cae8bc4 100644
--- a/lib/libgphoto2-sharp/Port.cs
+++ b/lib/libgphoto2-sharp/Port.cs
@@ -4,6 +4,9 @@
  * Author(s):
  *	Ewen Cheslack-Postava <echeslack gmail com>
  *	Larry Ewing <lewing novell com>
+ *	Stephane Delcroix <stephane delcroix org>
+ *
+ * Copyright (c) 2005-2009 Novell, Inc.
  *
  * This is free software. See COPYING for details.
  */
@@ -16,7 +19,9 @@ namespace LibGPhoto2
 	{
 		None = 0,
 		Serial = 1 << 0,
-		USB = 1 << 2
+		USB = 1 << 2,
+		Disk = 1 << 3,
+		
 	}
 
 	public enum PortSerialParity
diff --git a/src/GPhotoCamera.cs b/src/GPhotoCamera.cs
index 14ef388..4486bcc 100644
--- a/src/GPhotoCamera.cs
+++ b/src/GPhotoCamera.cs
@@ -5,7 +5,9 @@ using LibGPhoto2;
 using Gdk;
 using FSpot.Utils;
 using FSpot;
-
+#if GPHOTO2_2_4
+using Mono.Unix.Native;
+#endif
 public class GPhotoCamera
 {
 	Context context;
@@ -210,7 +212,18 @@ public class GPhotoCamera
 		//check if the directory exists
 		if (!Directory.Exists (Path.GetDirectoryName (filename))) 
 			throw new Exception (String.Format ("Directory \"{0}\"does not exist", filename)); //FIXME
-		
+#if GPHOTO2_2_4
+		//gp_file_new_from_fd is broken on the directory driver
+		//but using gp_file_new_from_fd doesn't move the files to memory
+		if (camera_abilities.port != PortType.Disk) {
+			GPhotoCameraFile selected_file = (GPhotoCameraFile) files [index];		
+			using (var f = new CameraFile (Syscall.open (filename, OpenFlags.O_CREAT|OpenFlags.O_RDWR, FilePermissions.ALLPERMS))) {
+				camera.GetFile (selected_file.Directory, selected_file.FileName, CameraFileType.Normal, f, context);
+			}
+			return;
+		}
+#endif
+	
 		using (CameraFile camfile = GetFile (index)) {
 			if (camfile == null) 
 				throw new Exception ("Unable to claim file"); //FIXME



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