예제 #1
0
        private string MoveFile(string orig)
        {
            string dest = FileImportBackend.ChooseLocation(orig);

            System.IO.File.Move(orig, dest);
            return(dest);
        }
예제 #2
0
        public int ImportPhoto(string path, bool copy, string [] tags)
        {
            if (current_roll == null)
            {
                throw new DBusException("You must use PrepareRoll before you can import a photo.");
            }

            // add tags that exist in tag store
            List <Tag> tag_list = GetTagsByNames(tags);

            Gdk.Pixbuf pixbuf = null;

            // FIXME: this is more or less a copy of the file import backend code
            // this should be streamlined
            try {
                string new_path = path;

                if (copy)
                {
                    new_path = FileImportBackend.ChooseLocation(path);
                }

                if (new_path != path)
                {
                    System.IO.File.Copy(path, new_path);
                }

                Photo created = db.Photos.CreateOverDBus(new_path, path, current_roll.Id, out pixbuf);

                try {
                    File.SetAttributes(new_path, File.GetAttributes(new_path) & ~FileAttributes.ReadOnly);
                    DateTime create = File.GetCreationTime(path);
                    File.SetCreationTime(new_path, create);
                    DateTime mod = File.GetLastWriteTime(path);
                    File.SetLastWriteTime(new_path, mod);
                } catch (IOException) {
                    // we don't want an exception here to be fatal.
                }

                // attach tags we got
                if (tag_list.Count > 0)
                {
                    created.AddTag(tag_list.ToArray());
                    db.Photos.Commit(created);
                }

                return((int)created.Id);
                // indicate failure
            } catch {
                throw new DBusException("Failed to import the photo.");
            }
        }
        private SaveResult SaveFile(int index)
        {
            GPhotoCameraFile camfile = (GPhotoCameraFile)camera.FileList [index];
            string           tempdir = FSpot.Global.PhotoDirectory;

            if (!Directory.Exists(tempdir))
            {
                Directory.CreateDirectory(tempdir);
            }

            string orig = Path.Combine(tempdir, camfile.FileName.ToLower());
            string path = orig;

            int i = 0;

            while (File.Exists(path))
            {
                string name = String.Format("{0}-{1}{2}",
                                            Path.GetFileNameWithoutExtension(orig),
                                            i, Path.GetExtension(orig));

                path = System.IO.Path.Combine(Path.GetDirectoryName(orig), name);
                i++;
            }

            string msg = String.Format(Catalog.GetString("Transferring \"{0}\" from camera"),
                                       Path.GetFileName(path));

            progress_dialog.Message = msg;

            camera.SaveFile(index, path);

            if (duplicate_check.Active && db.Photos.CheckForDuplicate(FSpot.Utils.UriUtils.PathToFileUri(path)) != null)
            {
                System.IO.File.Delete(path);

                return(new SaveResult(path, true));
            }
            else
            {
                string dest = FileImportBackend.ChooseLocation(path);
                System.IO.File.Move(path, dest);

                return(new SaveResult(dest, false));
            }
        }
    public static void Main(string [] args)
    {
        Program program = new Program("FileImportTest", "0.0", Modules.UI, args);

        const string path = "/tmp/FileImportTest.db";

        try {
            File.Delete(path);
        } catch {}

        Db db = new Db(path, true);

        FileImportBackend import = new FileImportBackend(db.Photos, args [0], true, this);

        Console.WriteLine("Preparing...");

        int total_count = import.Prepare();

        if (total_count == 0)
        {
            Console.WriteLine("(No pictures)");
        }

        Console.WriteLine("Prepared: {0} picture(s)", total_count);

        bool ongoing;

        do
        {
            Photo  photo;
            Pixbuf thumbnail;
            int    count;

            ongoing = import.Step(out photo, out thumbnail, out count);

            Console.WriteLine("{0}/{1} - {2}", count, total_count, photo.Path);

            if (thumbnail != null)
            {
                thumbnail.Dispose();
            }
        } while (ongoing);

        import.Finish();
    }
        private string SaveFile(int index)
        {
            GPhotoCameraFile camfile = (GPhotoCameraFile)camera.FileList [index];
            string           tempdir = FSpot.Global.PhotoDirectory;

            if (!Directory.Exists(tempdir))
            {
                Directory.CreateDirectory(tempdir);
            }

            string orig = Path.Combine(tempdir, camfile.FileName.ToLower());
            string path = orig;

            int i = 0;

            while (File.Exists(path))
            {
                string name = String.Format("{0}-{1}{2}",
                                            Path.GetFileNameWithoutExtension(orig),
                                            i, Path.GetExtension(orig));

                path = System.IO.Path.Combine(Path.GetDirectoryName(orig), name);
                i++;
            }

            string msg = String.Format(Catalog.GetString("Transferring \"{0}\" from camera"),
                                       Path.GetFileName(path));

            progress_dialog.Message = msg;

            camera.SaveFile(index, path);

            string dest = FileImportBackend.ChooseLocation(path);

            System.IO.File.Move(path, dest);
            path = dest;

            return(path);
        }
	public static void Main (string [] args)
	{
		Program program = new Program ("FileImportTest", "0.0", Modules.UI, args);

		const string path = "/tmp/FileImportTest.db";

		try {
			File.Delete (path);
		} catch {}

		Db db = new Db (path, true);

		FileImportBackend import = new FileImportBackend (db.Photos, args [0],true, this);

		Console.WriteLine ("Preparing...");

		int total_count = import.Prepare();
		if (total_count == 0)
			Console.WriteLine ("(No pictures)");

		Console.WriteLine ("Prepared: {0} picture(s)", total_count);

		bool ongoing;
		do {
			Photo photo;
			Pixbuf thumbnail;
			int count;

			ongoing = import.Step (out photo, out thumbnail, out count);

			Console.WriteLine ("{0}/{1} - {2}", count, total_count, photo.Path);

			if (thumbnail != null)
				thumbnail.Dispose ();
		} while (ongoing);

		import.Finish ();
	}
예제 #7
0
        void ImportPhoto(Photo photo, bool copy)
        {
            Log.WarningFormat("Importing {0}", photo.Name);
            PhotoStore from_store = from_db.Photos;
            PhotoStore to_store   = to_db.Photos;

            string photo_path = photo.VersionUri(Photo.OriginalVersionId).AbsolutePath;

            while (!System.IO.File.Exists(photo_path))
            {
                Log.Debug("Not found, trying the mappings...");
                foreach (string key in PathMap.Keys)
                {
                    string path = photo_path;
                    path = path.Replace(key, PathMap [key]);
                    Log.DebugFormat("Replaced path {0}", path);
                    if (System.IO.File.Exists(path))
                    {
                        photo_path = path;
                        break;;
                    }
                }

                if (System.IO.File.Exists(photo_path))
                {
                    Log.Debug("Exists!!!");
                    continue;
                }

                string [] parts = photo_path.Split(new char[] { '/' });
                if (parts.Length > 6)
                {
                    string           folder     = String.Join("/", parts, 0, parts.Length - 4);
                    PickFolderDialog pfd        = new PickFolderDialog(mdd.Dialog, folder);
                    string           new_folder = pfd.Run();
                    pfd.Dialog.Destroy();
                    if (new_folder == null)                     //Skip
                    {
                        return;
                    }
                    Log.DebugFormat("{0} maps to {1}", folder, new_folder);

                    PathMap[folder] = new_folder;
                }
                else
                {
                    Console.WriteLine("point me to the file");
                }
                Console.WriteLine("FNF: {0}", photo_path);
            }

            string destination;

            Gdk.Pixbuf pixbuf;
            Photo      newp;

            if (copy)
            {
                destination = FileImportBackend.ChooseLocation(photo_path, null);
            }
            else
            {
                destination = photo_path;
            }

            // Don't copy if we are already home
            if (photo_path == destination)
            {
                newp = to_store.Create(destination, roll_map [photo.RollId], out pixbuf);
            }
            else
            {
                System.IO.File.Copy(photo_path, destination);

                newp = to_store.Create(destination, photo_path, roll_map [photo.RollId], out pixbuf);
                try {
                    File.SetAttributes(destination, File.GetAttributes(destination) & ~FileAttributes.ReadOnly);
                    DateTime create = File.GetCreationTime(photo_path);
                    File.SetCreationTime(destination, create);
                    DateTime mod = File.GetLastWriteTime(photo_path);
                    File.SetLastWriteTime(destination, mod);
                } catch (IOException) {
                    // we don't want an exception here to be fatal.
                }
            }

            if (newp == null)
            {
                return;
            }

            foreach (Tag t in photo.Tags)
            {
                Log.WarningFormat("Tagging with {0}", t.Name);
                newp.AddTag(tag_map [t.Id]);
            }

            foreach (uint version_id in photo.VersionIds)
            {
                if (version_id != Photo.OriginalVersionId)
                {
                    PhotoVersion version = photo.GetVersion(version_id) as PhotoVersion;
                    uint         newv    = newp.AddVersion(version.Uri, version.Name, version.IsProtected);
                    if (version_id == photo.DefaultVersionId)
                    {
                        newp.DefaultVersionId = newv;
                    }
                }
            }

            //FIXME Import extra info (time, description, rating)
            newp.Time        = photo.Time;
            newp.Description = photo.Description;
            newp.Rating      = photo.Rating;

            to_store.Commit(newp);
        }
 protected virtual string ImageName(int image_num)
 {
     return(System.IO.Path.GetFileName(FileImportBackend.UniqueName(gallery_path, System.IO.Path.GetFileName(collection [image_num].DefaultVersionUri.LocalPath))));
 }