private void GetListing(System.IO.DirectoryInfo dirinfo, System.IO.FileInfo [] files, bool recurse)
    {
        Log.DebugFormat("Scanning {0} for new photos", dirinfo.FullName);
        List <Uri> existing_entries = new List <Uri> ();

        foreach (Photo p in store.Query(new Uri(dirinfo.FullName)))
        {
            foreach (uint id in p.VersionIds)
            {
                existing_entries.Add(p.VersionUri(id));
            }
        }

        foreach (System.IO.FileInfo f in files)
        {
            if (!existing_entries.Contains(UriUtils.PathToFileUri(f.FullName)) && !f.Name.StartsWith("."))
            {
                AddPath(f.FullName);
            }
        }

        if (recurse)
        {
            foreach (System.IO.DirectoryInfo d in dirinfo.GetDirectories())
            {
                if (!d.Name.StartsWith("."))
                {
                    GetListing(d);
                }
            }
        }
    }
示例#2
0
    public void AddUnknown(string unknown)
    {
        Uri uri;

        if (File.Exists(unknown) || Directory.Exists(unknown))
        {
            uri = UriUtils.PathToFileUri(unknown);
        }
        else
        {
            uri = new Uri(unknown);
        }

        Add(uri);
    }
示例#3
0
        public bool Convert(FilterRequest request)
        {
            //FIXME: make it works for uri (and use it in CDExport)
            int    i        = 1;
            string path     = destination.LocalPath;
            string filename = System.IO.Path.GetFileName(request.Source.LocalPath);
            string dest     = System.IO.Path.Combine(path, filename);

            while (System.IO.File.Exists(dest))
            {
                string numbered_name = String.Format("{0}-{1}{2}",
                                                     System.IO.Path.GetFileNameWithoutExtension(filename),
                                                     i++,
                                                     System.IO.Path.GetExtension(filename));
                dest = System.IO.Path.Combine(path, numbered_name);
            }

            System.IO.File.Copy(request.Current.LocalPath, dest);
            request.Current = UriUtils.PathToFileUri(dest);
            return(true);
        }
        public Uri TempUri(string extension)
        {
            string imgtemp;

            if (extension != null)
            {
                string temp = System.IO.Path.GetTempFileName();
                imgtemp = temp + "." + extension;
                System.IO.File.Move(temp, imgtemp);
            }
            else
            {
                imgtemp = System.IO.Path.GetTempFileName();
            }

            Uri uri = UriUtils.PathToFileUri(imgtemp);

            if (!temp_uris.Contains(uri))
            {
                temp_uris.Add(uri);
            }
            return(uri);
        }
示例#5
0
 public SingleView(string path) : this(UriUtils.PathToFileUri(path))
 {
 }
 public FilterRequest(string path) : this(UriUtils.PathToFileUri(path))
 {
 }
示例#7
0
 public UniqueNameFilter(string destination) : this(UriUtils.PathToFileUri(destination))
 {
 }
示例#8
0
 public Photo Create(string new_path, string orig_path, uint roll_id, out Pixbuf thumbnail)
 {
     return(Create(UriUtils.PathToFileUri(new_path), UriUtils.PathToFileUri(orig_path), roll_id, out thumbnail));
 }
示例#9
0
 public ImageFile(string path)
 {
     this.uri = UriUtils.PathToFileUri(path);
 }
示例#10
0
 public static bool HasLoader(string path)
 {
     return(HasLoader(UriUtils.PathToFileUri(path)));
 }
 public FileBrowsableItem(string path)
 {
     this.uri = UriUtils.PathToFileUri(path);
 }
示例#12
0
 static public Gdk.Pixbuf ValidateThumbnail(string photo_path, Gdk.Pixbuf pixbuf)
 {
     System.Uri uri = UriUtils.PathToFileUri(photo_path);
     return(ValidateThumbnail(uri, pixbuf));
 }
    public override bool Step(out StepStatusInfo status_info)
    {
        Photo  photo        = null;
        Pixbuf thumbnail    = null;
        bool   is_duplicate = false;

        if (import_info == null)
        {
            throw new ImportException("Prepare() was not called");
        }

        if (this.count == import_info.Count)
        {
            throw new ImportException("Already finished");
        }

        // FIXME Need to get the EXIF info etc.
        ImportInfo info         = (ImportInfo)import_info [this.count];
        bool       needs_commit = false;
        bool       abort        = false;

        try {
            string destination = info.OriginalPath;
            if (copy)
            {
                destination = ChooseLocation(info.OriginalPath, directories);
            }

            // Don't copy if we are already home
            if (info.OriginalPath == destination)
            {
                info.DestinationPath = destination;

                if (detect_duplicates)
                {
                    photo = store.CheckForDuplicate(UriUtils.PathToFileUri(destination));
                }

                if (photo == null)
                {
                    photo = store.Create(info.DestinationPath, roll.Id, out thumbnail);
                }
                else
                {
                    is_duplicate = true;
                }
            }
            else
            {
                System.IO.File.Copy(info.OriginalPath, destination);
                info.DestinationPath = destination;

                if (detect_duplicates)
                {
                    photo = store.CheckForDuplicate(UriUtils.PathToFileUri(destination));
                }

                if (photo == null)
                {
                    photo = store.Create(info.DestinationPath, info.OriginalPath, roll.Id, out thumbnail);


                    try {
                        File.SetAttributes(destination, File.GetAttributes(info.DestinationPath) & ~FileAttributes.ReadOnly);
                        DateTime create = File.GetCreationTime(info.OriginalPath);
                        File.SetCreationTime(info.DestinationPath, create);
                        DateTime mod = File.GetLastWriteTime(info.OriginalPath);
                        File.SetLastWriteTime(info.DestinationPath, mod);
                    } catch (IOException) {
                        // we don't want an exception here to be fatal.
                    }
                }
                else
                {
                    is_duplicate = true;
                    System.IO.File.Delete(destination);
                }
            }

            if (!is_duplicate)
            {
                if (tags != null)
                {
                    foreach (Tag t in tags)
                    {
                        photo.AddTag(t);
                    }
                    needs_commit = true;
                }

                needs_commit |= xmptags.Import(photo, info.DestinationPath, info.OriginalPath);

                if (needs_commit)
                {
                    store.Commit(photo);
                }

                info.Photo = photo;
            }
        } catch (System.Exception e) {
            System.Console.WriteLine("Error importing {0}{2}{1}", info.OriginalPath, e.ToString(), Environment.NewLine);
            if (thumbnail != null)
            {
                thumbnail.Dispose();
            }

            thumbnail = null;
            photo     = null;

            HigMessageDialog errordialog = new HigMessageDialog(parent,
                                                                Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent,
                                                                Gtk.MessageType.Error,
                                                                Gtk.ButtonsType.Cancel,
                                                                Catalog.GetString("Import error"),
                                                                String.Format(Catalog.GetString("Error importing {0}{2}{2}{1}"), info.OriginalPath, e.Message, Environment.NewLine));
            errordialog.AddButton(Catalog.GetString("Skip"), Gtk.ResponseType.Reject, false);
            ResponseType response = (ResponseType)errordialog.Run();
            errordialog.Destroy();
            if (response == ResponseType.Cancel)
            {
                abort = true;
            }
        }

        this.count++;

        if (is_duplicate)
        {
            this.duplicate_count++;
        }

        status_info = new StepStatusInfo(photo, thumbnail, this.count, is_duplicate);

        return(!abort && count != import_info.Count);
    }
示例#14
0
 public Photo GetByPath(string path)
 {
     return(GetByUri(UriUtils.PathToFileUri(path)));
 }
示例#15
0
 public static Gdk.Pixbuf Create(string path)
 {
     return(Create(UriUtils.PathToFileUri(path)));
 }
示例#16
0
 public static ImageFile Create(string path)
 {
     return(Create(UriUtils.PathToFileUri(path)));
 }
示例#17
0
 public static string ThumbnailPath(string path)
 {
     return(ThumbnailPath(UriUtils.PathToFileUri(path)));
 }
示例#18
0
 public static void MoveThumbnail(string old_path, string new_path)
 {
     System.IO.File.Move(ThumbnailGenerator.ThumbnailPath(UriUtils.PathToFileUri(old_path)),
                         ThumbnailGenerator.ThumbnailPath(UriUtils.PathToFileUri(new_path)));
 }