public void StringNames(string name)
            {
                string path       = CreateFile(name, 1024);
                string thumb_path = ThumbnailGenerator.ThumbnailPath(path);

                ThumbnailGenerator.Create(path);

                Assert.IsTrue(File.Exists(thumb_path), String.Format("Missing: {0} created from {1}", thumb_path, path));
                using (Gdk.Pixbuf thumb = new Gdk.Pixbuf(thumb_path)) {
                    Assert.IsNotNull(thumb);
                    Assert.AreEqual(thumb.GetOption(ThumbUri), UriList.PathToFileUriEscaped(path));
                    Assert.AreEqual(new Uri(thumb.GetOption(ThumbUri)), UriList.PathToFileUri(path));
                    Assert.IsTrue(ThumbnailGenerator.ThumbnailIsValid(thumb, UriList.PathToFileUri(path)));
                }

                File.Delete(path);
                File.Delete(thumb_path);
            }
Esempio n. 2
0
        public void DeleteVersion(uint version_id, bool remove_original, bool keep_file)
        {
            if (version_id == OriginalVersionId && !remove_original)
            {
                throw new Exception("Cannot delete original version");
            }

            System.Uri uri = VersionUri(version_id);

            if (!keep_file)
            {
                if ((new Gnome.Vfs.Uri(uri.ToString())).Exists)
                {
                    if ((new Gnome.Vfs.Uri(uri.ToString()).Unlink()) != Result.Ok)
                    {
                        throw new System.UnauthorizedAccessException();
                    }
                }

                try {
                    string thumb_path = ThumbnailGenerator.ThumbnailPath(uri);
                    System.IO.File.Delete(thumb_path);
                } catch (System.Exception) {
                    //ignore an error here we don't really care.
                }
                PhotoStore.DeleteThumbnail(uri);
            }
            Versions.Remove(version_id);

            changes.RemoveVersion(version_id);

            do
            {
                version_id--;
                if (Versions.ContainsKey(version_id))
                {
                    DefaultVersionId = version_id;
                    break;
                }
            } while (version_id > OriginalVersionId);
        }
Esempio n. 3
0
        public static string GenerateMD5(System.Uri uri)
        {
            try {
                if (md5_cache.ContainsKey(uri))
                {
                    return(md5_cache [uri]);
                }

                using (Gdk.Pixbuf pixbuf = ThumbnailGenerator.Create(uri))
                {
                    byte[] serialized = PixbufSerializer.Serialize(pixbuf);
                    byte[] md5        = MD5Generator.ComputeHash(serialized);
                    string md5_string = Convert.ToBase64String(md5);

                    md5_cache.Add(uri, md5_string);
                    return(md5_string);
                }
            } catch (Exception e) {
                Log.DebugFormat("Failed to create MD5Sum for Uri {0}; {1}", uri, e.Message);
            }

            return(string.Empty);
        }
            public void UriNames(string name)
            {
                string path = CreateFile(name, 768);
                Uri    uri  = new Uri(Gnome.Vfs.Uri.GetUriFromLocalPath(path));

                string string_path = ThumbnailGenerator.ThumbnailPath(path);
                string thumb_path  = ThumbnailGenerator.ThumbnailPath(uri);

                Assert.AreEqual(thumb_path, string_path);

                ThumbnailGenerator.Create(uri);

                Assert.IsTrue(File.Exists(thumb_path), String.Format("Missing: {0} created from {1}", thumb_path, uri));
                using (Gdk.Pixbuf thumb = new Gdk.Pixbuf(thumb_path)) {
                    Assert.IsNotNull(thumb);
                    Assert.AreEqual(thumb.GetOption(ThumbUri), UriList.UriToStringEscaped(uri));
                    Assert.AreEqual(new Uri(thumb.GetOption(ThumbUri)), uri);
                    Assert.IsTrue(ThumbnailGenerator.ThumbnailIsValid(thumb, uri));
                }

                File.Delete(thumb_path);
                File.Delete(path);
            }
        public void Load(Uri uri)
        {
            this.uri = uri;

            delay.Stop();

            if (!done_reading)
            {
                Close();
            }

            done_reading  = false;
            area_prepared = false;
            damage        = Gdk.Rectangle.Zero;

            using (ImageFile img = ImageFile.Create(uri)) {
                orientation = Accelerometer.GetViewOrientation(img.Orientation);

                try {
                    PixbufOrientation thumb_orientation = Accelerometer.GetViewOrientation(PixbufOrientation.TopLeft);
                    thumb = new Gdk.Pixbuf(ThumbnailGenerator.ThumbnailPath(uri));
                    thumb = PixbufUtils.TransformOrientation(thumb, thumb_orientation);

                    if (FSpot.ColorManagement.IsEnabled && !thumb.HasAlpha)
                    {
                        if (img.GetProfile() == null)
                        {
                            FSpot.ColorManagement.PhotoImageView.Transform = FSpot.ColorManagement.StandartTransform();
                        }
                        else
                        {
                            FSpot.ColorManagement.PhotoImageView.Transform = FSpot.ColorManagement.CreateTransform(thumb, img.GetProfile());
                        }
                    }
                    else
                    {
                        FSpot.ColorManagement.PhotoImageView.Transform = null;
                    }
                } catch (System.Exception e) {
                    //FSpot.ThumbnailGenerator.Default.Request (uri.ToString (), 0, 256, 256);
                    if (!(e is GLib.GException))
                    {
                        System.Console.WriteLine(e.ToString());
                    }
                }

                System.IO.Stream nstream = img.PixbufStream();
                if (nstream == null)
                {
                    FileLoad(img);
                    return;
                }
                else
                {
                    stream = new StreamWrapper(nstream);
                }

                loader = new Gdk.PixbufLoader();
                loader.AreaPrepared += ap;
                loader.AreaUpdated  += au;
                loader.Closed       += ev;

                if (AreaPrepared != null && thumb != null)
                {
                    pixbuf = thumb;
                    AreaPrepared(this, new AreaPreparedArgs(true));
                }

                ThumbnailGenerator.Default.PushBlock();
                //AsyncIORead (null);
                if (nstream is IOChannel)
                {
                    ((IOChannel)nstream).DataReady += IOChannelRead;
                }
                else
                {
                    delay.Start();
                }
            }
        }