Example #1
0
        private uint CreateVersion(string name, string extension, uint base_version_id, bool create, bool is_protected)
        {
            extension = extension ?? VersionUri(base_version_id).GetExtension();
            SafeUri new_base_uri = DefaultVersion.BaseUri;
            string  filename     = GetFilenameForVersionName(name, extension);
            SafeUri original_uri = VersionUri(base_version_id);
            SafeUri new_uri      = new_base_uri.Append(filename);
            string  import_md5   = DefaultVersion.ImportMD5;

            if (VersionNameExists(name))
            {
                throw new Exception("This version name already exists");
            }

            if (create)
            {
                GLib.File destination = GLib.FileFactory.NewForUri(new_uri);
                if (destination.Exists)
                {
                    throw new Exception(string.Format("An object at this uri {0} already exists", new_uri));
                }

                //FIXME. or better, fix the copy api !
                GLib.File source = GLib.FileFactory.NewForUri(original_uri);
                source.Copy(destination, GLib.FileCopyFlags.None, null, null);
            }
            highest_version_id++;

            versions [highest_version_id] = new PhotoVersion(this, highest_version_id, new_base_uri, filename, import_md5, name, is_protected);

            changes.AddVersion(highest_version_id);

            return(highest_version_id);
        }
Example #2
0
        public void CopyIfNeeded(IPhoto item, SafeUri destinationBase)
        {
            // remember source uri for copying xmp file
            SafeUri defaultVersionUri = item.DefaultVersion.Uri;

            foreach (IPhotoVersion version in item.Versions)
            {
                // Copy into photo folder and update IPhotoVersion uri
                var source      = version.Uri;
                var destination = destinationBase.Append(source.GetFilename());
                if (!source.Equals(destination))
                {
                    destination = GetUniqueFilename(destination);
                    file_system.File.Copy(source, destination, false);
                    copied_files.Add(destination);
                    original_files.Add(source);
                    version.Uri = destination;
                }
            }

            // Copy XMP sidecar
            var xmp_original = defaultVersionUri.ReplaceExtension(".xmp");

            if (file_system.File.Exists(xmp_original))
            {
                var xmp_destination = item.DefaultVersion.Uri.ReplaceExtension(".xmp");
                file_system.File.Copy(xmp_original, xmp_destination, true);
                copied_files.Add(xmp_destination);
                original_files.Add(xmp_original);
            }
        }
Example #3
0
        static SafeUri ThumbUri(SafeUri uri, ThumbnailSize size)
        {
            var hash = CryptoUtil.Md5Encode(uri);

            return(home_dir.Append(".thumbnails")
                   .Append(size == ThumbnailSize.Normal ? "normal" : "large")
                   .Append(hash + ".png"));
        }
Example #4
0
        internal static SafeUri FindImportDestination(IPhoto item, SafeUri baseUri)
        {
            DateTime time = item.Time;

            return(baseUri
                   .Append(time.Year.ToString())
                   .Append(String.Format("{0:D2}", time.Month))
                   .Append(String.Format("{0:D2}", time.Day)));
        }
Example #5
0
        protected virtual string ImageName(int image_num)
        {
            var uri      = Collection [image_num].DefaultVersion.Uri;
            var dest_uri = new SafeUri(GalleryPath);

            // Find an unused name
            int i    = 1;
            var dest = dest_uri.Append(uri.GetFilename());
            var file = GLib.FileFactory.NewForUri(dest);

            while (file.Exists)
            {
                var filename  = uri.GetFilenameWithoutExtension();
                var extension = uri.GetExtension();
                dest = dest_uri.Append(String.Format("{0}-{1}{2}", filename, i++, extension));
                file = GLib.FileFactory.NewForUri(dest);
            }

            return(dest.GetFilename());
        }
Example #6
0
        void EnsureDirectory(SafeUri uri)
        {
            var     parts   = uri.AbsolutePath.Split('/');
            SafeUri current = new SafeUri(uri.Scheme + ":///", true);

            for (int i = 0; i < parts.Length; i++)
            {
                current = current.Append(parts [i]);
                var file = GLib.FileFactory.NewForUri(current);
                if (!file.Exists)
                {
                    file.MakeDirectory(null);
                }
            }
        }
Example #7
0
        public IEnumerable <SafeUri> Enumerate(SafeUri uri)
        {
            var directory = FileFactory.NewForUri(uri);

            if (!ExistsAndIsDirectory(directory))
            {
                yield break;
            }
            using (var fileEnumerator = directory.EnumerateChildren("standard::name", FileQueryInfoFlags.None, null)) {
                foreach (FileInfo fileInfo in fileEnumerator)
                {
                    yield return(uri.Append(fileInfo.Name));

                    fileInfo.Dispose();
                }
            }
        }