VersionUri() public method

public VersionUri ( uint version_id ) : SafeUri
version_id uint
return Hyena.SafeUri
Exemplo n.º 1
0
 private static string DirectoryPath(Photo p)
 {
     System.Uri uri = p.VersionUri (Photo.OriginalVersionId);
                 return uri.Scheme + "://" + uri.Host + System.IO.Path.GetDirectoryName (uri.AbsolutePath);
 }
Exemplo n.º 2
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);
		}
Exemplo n.º 3
0
 private static string DirectoryPath(Photo p)
 {
     return p.VersionUri (Photo.OriginalVersionId).GetBaseUri ();
 }
Exemplo n.º 4
0
 private static string GetNextVersionFileName(Photo p, int i)
 {
     Console.WriteLine ("New New "+ GetNextIntelligentVersionFileNames(p)[0].ToString());
     Regex exiflowpat = new Regex(@"^(\d{8}(-\d{6})?-.{3}\d{4}-.{2})(\d)(.{2})\.([^.]*)$");
     Match exiflowpatmatch = exiflowpat.Match(System.IO.Path.GetFileName(p.VersionUri(p.DefaultVersionId).LocalPath));
     // besser mit UnixPath.GetFileName()
     string filename = String.Format("{0}{1}00.{2}", exiflowpatmatch.Groups[1], i, exiflowpatmatch.Groups[5]);
     System.Uri developed = GetUriForVersionFileName (p, filename);
     if (p.VersionNameExists (GetVersionName(filename)) || System.IO.File.Exists(CheapEscape(developed.LocalPath)))
         return GetNextVersionFileName (p, i + 1);
     return filename;
 }
Exemplo n.º 5
0
 private static string GetNextIntelligentVersionFileNames(Photo p, int x, int y, int z)
 {
     Regex exiflowpat = new Regex(@"^(\d{8}(-\d{6})?-.{3}\d{4}-.{2})(.)(.)(.)(.*)\.([^.]*)$");
     Match exiflowpatmatch = exiflowpat.Match(System.IO.Path.GetFileName(p.VersionUri(p.DefaultVersionId).LocalPath));
     string filename = null;
     if (x > 0)
         filename = String.Format("{0}{1}{2}{3}.{4}",
          exiflowpatmatch.Groups[1],
          GetNextValidChar(exiflowpatmatch.Groups[3].ToString(),x),
          0,
          0,
          exiflowpatmatch.Groups[7]);
     if (y > 0)
         filename = String.Format("{0}{1}{2}{3}.{4}",
          exiflowpatmatch.Groups[1],
          exiflowpatmatch.Groups[3],
          GetNextValidChar(exiflowpatmatch.Groups[4].ToString(),y),
          0,
          exiflowpatmatch.Groups[7]);
     if (z > 0)
         filename = String.Format("{0}{1}{2}{3}.{4}",
          exiflowpatmatch.Groups[1],
          exiflowpatmatch.Groups[3],
          exiflowpatmatch.Groups[4],
          GetNextValidChar(exiflowpatmatch.Groups[5].ToString(),z),
          exiflowpatmatch.Groups[7]);
     System.Uri developed = GetUriForVersionFileName (p, filename);
         Console.WriteLine (developed);
     if (p.VersionNameExists (GetVersionName(filename)) || System.IO.File.Exists(CheapEscape(developed.LocalPath))){
         if (x > 0)
             return GetNextIntelligentVersionFileNames (p, x+1, y, z);
         if (y > 0)
             return GetNextIntelligentVersionFileNames (p, x, y+1, z);
         if (z > 0)
             return GetNextIntelligentVersionFileNames (p, x, y, z+1);
     }
     return filename;
 }
Exemplo n.º 6
0
 private static string[] GetNextIntelligentVersionFileNames(Photo p)
 {
     Regex exiflowpat = new Regex(@"^(\d{8}(-\d{6})?-.{3}\d{4}-.{2})(\d)(.)(.)(.*)\.([^.]*)$");
     Match exiflowpatmatch = exiflowpat.Match(System.IO.Path.GetFileName(p.VersionUri(p.DefaultVersionId).LocalPath));
     if ( (exiflowpatmatch.Groups[3].ToString() == "0") &&
           (exiflowpatmatch.Groups[4].ToString() == "0") &&
           (exiflowpatmatch.Groups[5].ToString() == "0" )) {
         string [] possibleversions = { GetNextIntelligentVersionFileNames (p, 1, 0 , 0)};
         return possibleversions;
     }
     else if ( (exiflowpatmatch.Groups[3].ToString() != "0") &&
           (exiflowpatmatch.Groups[4].ToString() == "0") &&
           (exiflowpatmatch.Groups[5].ToString() == "0" )) {
         string [] possibleversions = {
           GetNextIntelligentVersionFileNames (p, 0, 1, 0),
           GetNextIntelligentVersionFileNames (p, 1, 0, 0)
         };
         return possibleversions;
     }
     else
     {
         string [] possibleversions = {
           GetNextIntelligentVersionFileNames (p, 0, 0, 1),
           GetNextIntelligentVersionFileNames (p, 0, 1, 0),
           GetNextIntelligentVersionFileNames (p, 1, 0, 0)
         };
         return possibleversions;
     }
 }
Exemplo n.º 7
0
		void ImportPhoto (Photo photo, bool copy)
		{
			Log.WarningFormat ("Importing {0}", photo.Name);
			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
					Log.Debug ("point me to the file");
				Log.DebugFormat ("FNF: {0}", photo_path);

			}

			string destination;
			Photo newp;

			if (copy)
				destination = FindImportDestination (new Hyena.SafeUri (photo_path), photo.Time).AbsolutePath;
			else
				destination = photo_path;
			var dest_uri = new SafeUri (photo_path);

			photo.DefaultVersionId = 1;
			photo.DefaultVersion.Uri = dest_uri;

			if (photo.DefaultVersion.ImportMD5 == String.Empty) {
				(photo.DefaultVersion as PhotoVersion).ImportMD5 = HashUtils.GenerateMD5 (photo.DefaultVersion.Uri);
			}

			if (photo_path != destination) {
				System.IO.File.Copy (photo_path, destination);

				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.
				}
			}

			//FIXME simplify the following code by letting CreateFrom import all versions
			//      instead of looping over all versions here
			newp = to_store.CreateFrom (photo, true, roll_map [photo.RollId]);

			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.BaseUri, version.Filename, 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);
		}