From 0298fc88ad00ad9797609889ad7eb448f8c9afd4 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 12 Jun 2010 10:42:37 +0100 Subject: [PATCH] cleanup ugly path concatenations and add some comments --- SparkleShare/SparkleHelpers.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/SparkleShare/SparkleHelpers.cs b/SparkleShare/SparkleHelpers.cs index 9207f8f0..1b01a65e 100644 --- a/SparkleShare/SparkleHelpers.cs +++ b/SparkleShare/SparkleHelpers.cs @@ -28,9 +28,10 @@ namespace SparkleShare { public static bool ShowDebugInfo = true; + // Get's the avatar for a specific email address and size public static Gdk.Pixbuf GetAvatar (string Email, int Size) { - string AvatarPath = Path.Combine (SparklePaths.SparkleAvatarPath, + string AvatarPath = CombineMore (SparklePaths.SparkleAvatarPath, Size + "x" + Size); if (!Directory.Exists (AvatarPath)) { @@ -39,7 +40,7 @@ namespace SparkleShare { "Created '" + AvatarPath + "'"); } - string AvatarFilePath = AvatarPath + Email; + string AvatarFilePath = CombineMore (AvatarPath, Email); if (File.Exists (AvatarFilePath)) return new Gdk.Pixbuf (AvatarFilePath); @@ -49,23 +50,25 @@ namespace SparkleShare { WebClient WebClient = new WebClient (); Uri GravatarUri = new Uri ("http://www.gravatar.com/avatar/" + GetMD5 (Email) + ".jpg?s=" + Size + "&d=404"); - // TODO: Clean paths - string TmpFile = SparklePaths.SparkleTmpPath + Email + Size; + + string TmpFile = + CombineMore (SparklePaths.SparkleTmpPath, Email + Size); if (!File.Exists (TmpFile)) { WebClient.DownloadFileAsync (GravatarUri, TmpFile); WebClient.DownloadFileCompleted += delegate { - File.Delete (AvatarPath + Email); + File.Delete (AvatarFilePath); FileInfo TmpFileInfo = new FileInfo (TmpFile); if (TmpFileInfo.Length > 255) - File.Move (TmpFile, AvatarPath + Email); + File.Move (TmpFile, AvatarFilePath); }; } - if (File.Exists (AvatarPath + Email)) - return new Gdk.Pixbuf (AvatarPath + Email); + // Fall back to a generic icon if there is no gravatar + if (File.Exists (AvatarFilePath)) + return new Gdk.Pixbuf (AvatarFilePath); else return GetIcon ("avatar-default", Size);