uint CreateVersion(string name, string extension, uint baseVersionId, bool create, bool isProtected) { extension = extension ?? VersionUri(baseVersionId).GetExtension(); var newBaseUri = DefaultVersion.BaseUri; string filename = GetFilenameForVersionName(name, extension); var originalUri = VersionUri(baseVersionId); var newUri = newBaseUri.Append(filename); string importMd5 = DefaultVersion.ImportMD5; if (VersionNameExists(name)) { throw new Exception("This version name already exists"); } if (create) { var destination = newUri.AbsolutePath; if (File.Exists(destination)) { throw new Exception(string.Format("An object at this uri {0} already exists", newUri)); } File.Copy(originalUri.AbsolutePath, destination); } highestVersionId++; versions[highestVersionId] = new PhotoVersion(this, highestVersionId, newBaseUri, filename, importMd5, name, isProtected); changes.AddVersion(highestVersionId); return(highestVersionId); }
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); }
// This doesn't check if a version of that name already exists, // it's supposed to be used only within the Photo and PhotoStore classes. public void AddVersionUnsafely(uint version_id, Uri base_uri, string filename, string import_md5, string name, bool is_protected) { versions[version_id] = new PhotoVersion(this, version_id, base_uri, filename, import_md5, name, is_protected); highestVersionId = Math.Max(version_id, highestVersionId); changes.AddVersion(version_id); }
public uint CreateReparentedVersion(PhotoVersion version, bool is_protected) { // Try to derive version name from its filename string filename = Uri.UnescapeDataString(Path.GetFileNameWithoutExtension(version.Uri.AbsolutePath)); string parent_filename = Path.GetFileNameWithoutExtension(Name); string name = null; if (filename.StartsWith(parent_filename)) { name = filename.Substring(parent_filename.Length).Replace("(", "").Replace(")", "").Replace("_", " ").Trim(); } if (string.IsNullOrEmpty(name)) { // Note for translators: Reparented is a picture becoming a version of another one string rep = name = Catalog.GetString("Reparented"); for (int num = 1; VersionNameExists(name); num++) { name = string.Format(rep + " ({0})", num); } } highest_version_id++; versions [highest_version_id] = new PhotoVersion(this, highest_version_id, version.BaseUri, version.Filename, version.ImportMD5, name, is_protected); changes.AddVersion(highest_version_id); return(highest_version_id); }
public uint CreateReparentedVersion(PhotoVersion version, bool isProtected = false) { // Try to derive version name from its filename string filename = Uri.UnescapeDataString(Path.GetFileNameWithoutExtension(version.Uri.AbsolutePath)); string parentFilename = Path.GetFileNameWithoutExtension(Name); string name = null; if (filename.StartsWith(parentFilename)) { name = filename.Substring(parentFilename.Length).Replace("(", "").Replace(")", "").Replace("_", " ").Trim(); } if (string.IsNullOrEmpty(name)) { string rep = name = Resources.Reparented; for (int num = 1; VersionNameExists(name); num++) { name = $"rep ({num})"; } } highestVersionId++; versions[highestVersionId] = new PhotoVersion(this, highestVersionId, version.BaseUri, version.Filename, version.ImportMD5, name, isProtected); changes.AddVersion(highestVersionId); return(highestVersionId); }
// This doesn't check if a version of that name already exists, // it's supposed to be used only within the Photo and PhotoStore classes. internal void AddVersionUnsafely(uint version_id, System.Uri uri, string md5_sum, string name, bool is_protected) { Versions [version_id] = new PhotoVersion(this, version_id, uri, md5_sum, name, is_protected); highest_version_id = Math.Max(version_id, highest_version_id); changes.AddVersion(version_id); }
public void SetDefaultVersion(IPhotoVersion version) { PhotoVersion photo_version = version as PhotoVersion; if (photo_version == null) { throw new ArgumentException("Not a valid version for this photo"); } DefaultVersionId = photo_version.VersionId; }
public SafeUri VersionUri(uint version_id) { if (!versions.ContainsKey(version_id)) { return(null); } PhotoVersion v = versions [version_id]; return(v != null ? v.Uri : null); }
void InsertVersion(DbItem photo, PhotoVersion version) { Database.Execute(new HyenaSqliteCommand( "INSERT OR IGNORE INTO photo_versions (photo_id, version_id, name, base_uri, filename, protected, import_md5) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", photo.Id, version.VersionId, version.Name, version.BaseUri.ToString(), version.Filename, version.IsProtected, (version.ImportMD5 != String.Empty ? version.ImportMD5 : null))); }
public uint AddVersion(System.Uri uri, string name, bool is_protected) { if (VersionNameExists(name)) { throw new ApplicationException("A version with that name already exists"); } highest_version_id++; string md5_sum = GenerateMD5(uri); Versions [highest_version_id] = new PhotoVersion(this, highest_version_id, uri, md5_sum, name, is_protected); changes.AddVersion(highest_version_id); return(highest_version_id); }
public uint AddVersion(SafeUri base_uri, string filename, string name, bool is_protected) { if (VersionNameExists(name)) { throw new ApplicationException("A version with that name already exists"); } highest_version_id++; string import_md5 = string.Empty; // Modified version versions [highest_version_id] = new PhotoVersion(this, highest_version_id, base_uri, filename, import_md5, name, is_protected); changes.AddVersion(highest_version_id); return(highest_version_id); }
private uint CreateVersion(string name, uint base_version_id, bool create, bool is_protected) { System.Uri new_uri = GetUriForVersionName(name, System.IO.Path.GetExtension(VersionUri(base_version_id).AbsolutePath)); System.Uri original_uri = VersionUri(base_version_id); string md5_sum = MD5Sum; if (VersionNameExists(name)) { throw new Exception("This version name already exists"); } if (create) { if ((new Gnome.Vfs.Uri(new_uri.ToString())).Exists) { throw new Exception(String.Format("An object at this uri {0} already exists", new_uri.ToString())); } Xfer.XferUri( new Gnome.Vfs.Uri(original_uri.ToString()), new Gnome.Vfs.Uri(new_uri.ToString()), XferOptions.Default, XferErrorMode.Abort, XferOverwriteMode.Abort, delegate(Gnome.Vfs.XferProgressInfo info) { return(1); }); // Mono.Unix.Native.Stat stat; // int stat_err = Mono.Unix.Native.Syscall.stat (original_path, out stat); // File.Copy (original_path, new_path); FSpot.ThumbnailGenerator.Create(new_uri).Dispose(); // // if (stat_err == 0) // try { // Mono.Unix.Native.Syscall.chown(new_path, Mono.Unix.Native.Syscall.getuid (), stat.st_gid); // } catch (Exception) {} // } else { md5_sum = Photo.GenerateMD5(new_uri); } highest_version_id++; Versions [highest_version_id] = new PhotoVersion(this, highest_version_id, new_uri, md5_sum, name, is_protected); changes.AddVersion(highest_version_id); return(highest_version_id); }
public System.Uri VersionUri(uint version_id) { if (!Versions.ContainsKey(version_id)) { return(null); } PhotoVersion v = Versions [version_id]; if (v != null) { return(v.Uri); } return(null); }
public bool IsDetected(PhotoVersion version) { SqliteDataReader reader = Database.Query ( new DbCommand ("SELECT is_auto_detected FROM photo_versions " + "WHERE photo_id = :photo_id, version_id = :version_id", "photo_id", version.Photo.Id, "version_id",version.VersionId) ); if (reader.Read ()) { return Convert.ToBoolean( reader["is_auto_detected"] ); } reader.Close(); //TODO consider whether to throw exception throw new Exception("Version Not Found!"); //return false; }
public void CalculateMD5Sum(Photo photo) { foreach (uint version_id in photo.VersionIds) { PhotoVersion version = photo.GetVersion(version_id); // Don't overwrite MD5 sums that are already calculated. if (version.ImportMD5 != String.Empty && version.ImportMD5 != null) { continue; } string version_md5_sum = HashUtils.GenerateMD5(version.Uri); version.ImportMD5 = version_md5_sum; photo.Changes.ChangeVersion(version_id); } Commit(photo); }
public uint CreateReparentedVersion(PhotoVersion version, bool is_protected) { int num = 0; while (true) { num++; // Note for translators: Reparented is a picture becoming a version of another one string name = (num == 1) ? Catalog.GetString("Reparented") : String.Format(Catalog.GetString("Reparented ({0})"), num); name = String.Format(name, num); if (VersionNameExists(name)) { continue; } highest_version_id++; Versions [highest_version_id] = new PhotoVersion(this, highest_version_id, version.Uri, version.MD5Sum, name, is_protected); changes.AddVersion(highest_version_id); return(highest_version_id); } }
public uint CreateReparentedVersion(PhotoVersion version) { return(CreateReparentedVersion(version, false)); }
PhotoChanges Update(Photo photo) { PhotoChanges changes = photo.Changes; // Update photo. if (changes.DescriptionChanged || changes.DefaultVersionIdChanged || changes.TimeChanged || changes.UriChanged || changes.RatingChanged || changes.MD5SumChanged) { Database.Execute( new HyenaSqliteCommand( "UPDATE photos " + "SET description = ?, " + " default_version_id = ?, " + " time = ?, " + " base_uri = ?, " + " filename = ?, " + " rating = ? " + "WHERE id = ? ", photo.Description, photo.DefaultVersionId, DateTimeUtil.FromDateTime(photo.Time), photo.VersionUri(Photo.OriginalVersionId).GetBaseUri().ToString(), photo.VersionUri(Photo.OriginalVersionId).GetFilename(), String.Format("{0}", photo.Rating), photo.Id ) ); } // Update tags. if (changes.TagsRemoved != null) { foreach (Tag tag in changes.TagsRemoved) { Database.Execute(new HyenaSqliteCommand( "DELETE FROM photo_tags WHERE photo_id = ? AND tag_id = ?", photo.Id, tag.Id)); } } if (changes.TagsAdded != null) { foreach (Tag tag in changes.TagsAdded) { Database.Execute(new HyenaSqliteCommand( "INSERT OR IGNORE INTO photo_tags (photo_id, tag_id) " + "VALUES (?, ?)", photo.Id, tag.Id)); } } // Update versions. if (changes.VersionsRemoved != null) { foreach (uint version_id in changes.VersionsRemoved) { Database.Execute(new HyenaSqliteCommand( "DELETE FROM photo_versions WHERE photo_id = ? AND version_id = ?", photo.Id, version_id)); } } if (changes.VersionsAdded != null) { foreach (uint version_id in changes.VersionsAdded) { PhotoVersion version = photo.GetVersion(version_id); InsertVersion(photo, version); } } if (changes.VersionsModified != null) { foreach (uint version_id in changes.VersionsModified) { PhotoVersion version = photo.GetVersion(version_id); Database.Execute(new HyenaSqliteCommand( "UPDATE photo_versions SET name = ?, " + "base_uri = ?, filename = ?, protected = ?, import_md5 = ? " + "WHERE photo_id = ? AND version_id = ?", version.Name, version.BaseUri.ToString(), version.Filename, version.IsProtected, (version.ImportMD5 != String.Empty ? version.ImportMD5 : null), photo.Id, version_id)); } } photo.Changes = null; return(changes); }
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; }
public uint CreateReparentedVersion(PhotoVersion version, bool is_protected) { // Try to derive version name from its filename string filename = Uri.UnescapeDataString (Path.GetFileNameWithoutExtension (version.Uri.AbsolutePath)); string parent_filename = Path.GetFileNameWithoutExtension (Name); string name = null; if (filename.StartsWith (parent_filename)) name = filename.Substring (parent_filename.Length).Replace ("(", "").Replace (")", "").Replace ("_", " "). Trim (); if (String.IsNullOrEmpty (name)) { // Note for translators: Reparented is a picture becoming a version of another one string rep = name = Catalog.GetString ("Reparented"); for (int num = 1; VersionNameExists (name); num++) { name = String.Format (rep + " ({0})", num); } } highest_version_id ++; versions [highest_version_id] = new PhotoVersion (this, highest_version_id, version.BaseUri, version.Filename, version.ImportMD5, name, is_protected); changes.AddVersion (highest_version_id); return highest_version_id; }
// This doesn't check if a version of that name already exists, // it's supposed to be used only within the Photo and PhotoStore classes. internal void AddVersionUnsafely(uint version_id, SafeUri base_uri, string filename, string import_md5, string name, bool is_protected) { versions [version_id] = new PhotoVersion (this, version_id, base_uri, filename, import_md5, name, is_protected); highest_version_id = Math.Max (version_id, highest_version_id); changes.AddVersion (version_id); }
public uint CreateReparentedVersion(PhotoVersion version) { return CreateReparentedVersion (version, false); }
public uint AddVersion(SafeUri base_uri, string filename, string name, bool is_protected) { if (VersionNameExists (name)) throw new ApplicationException ("A version with that name already exists"); highest_version_id ++; string import_md5 = String.Empty; // Modified version versions [highest_version_id] = new PhotoVersion (this, highest_version_id, base_uri, filename, import_md5, name, is_protected); changes.AddVersion (highest_version_id); return highest_version_id; }
public void SetIsDetected(PhotoVersion version,bool val) { //Log.Debug("SetIsDetected isnull :: " + (version==null)); try { Database.ExecuteNonQuery( new DbCommand("UPDATE photo_versions SET is_auto_detected = :is_auto_detected " + "WHERE photo_id = :photo_id AND version_id = :version_id", "is_auto_detected",val, "photo_id",version.Photo.Id, "version_id",version.VersionId)); } catch (Exception ex){ Log.Exception(ex); } }
private bool ChangeThisVersionUri(PhotoVersion version, string old_base, string new_base) { // Change to path from URI, since easier to compare with old_base which is not in URI format. string tmp_path = System.IO.Path.GetDirectoryName (version.Uri.AbsolutePath); return ( tmp_path.StartsWith (old_base) ); }
private string CreateNewPath(string old_base, string new_base, PhotoVersion version) { return string.Format ("{0}{1}", new_base, version.Uri.AbsolutePath.Substring(old_base.Length)); }