Fix some paths and add multi-combine method

This commit is contained in:
Hylke Bons 2010-05-08 15:31:44 +01:00
parent 8e59a35160
commit 83800af5d8
4 changed files with 47 additions and 39 deletions

View file

@ -26,8 +26,8 @@ namespace SparkleShare {
public static string GetAvatarFileName (string Email, int Size) { public static string GetAvatarFileName (string Email, int Size) {
string AvatarPath = SparklePaths.SparkleAvatarsDir + string AvatarPath = Path.Combine (SparklePaths.SparkleAvatarPath,
Size + "x" + Size + "/"; Size + "x" + Size);
if (!Directory.Exists (AvatarPath)) { if (!Directory.Exists (AvatarPath)) {
Directory.CreateDirectory (AvatarPath); Directory.CreateDirectory (AvatarPath);
@ -35,10 +35,10 @@ namespace SparkleShare {
} }
string AvatarFile = AvatarPath + Email; string AvatarFilePath = AvatarPath + Email;
if (File.Exists (AvatarFile)) if (File.Exists (AvatarFilePath))
return AvatarFile; return AvatarFilePath;
else { else {
@ -48,7 +48,7 @@ namespace SparkleShare {
Uri GravatarUri = new Uri ("http://www.gravatar.com/avatar/" + Uri GravatarUri = new Uri ("http://www.gravatar.com/avatar/" +
GetMD5 (Email) + ".jpg?s=" + Size + "&d=404"); GetMD5 (Email) + ".jpg?s=" + Size + "&d=404");
string TmpFile = SparklePaths.SparkleTmpDir + Email + Size; string TmpFile = SparklePaths.SparkleTmpPath + Email + Size;
if (!File.Exists (TmpFile)) { if (!File.Exists (TmpFile)) {
@ -62,14 +62,15 @@ namespace SparkleShare {
} }
string FallbackFileName = "/usr/share/icons/hicolor/" + string FallbackFileName = CombineMore (SparklePaths.SparkleIconPath,
Size + "x" + Size + Size + "x" + Size,
"/status/avatar-default.png"; "status",
"avatar-default.png");
if (File.Exists (FallbackFileName)) if (File.Exists (FallbackFileName))
return FallbackFileName; return FallbackFileName;
else else
return "/usr/share/icons/hicolor/16x16/status/avatar-default.png"; return "";
} }
} }
@ -84,6 +85,13 @@ namespace SparkleShare {
return BitConverter.ToString(EncodedBytes).ToLower ().Replace ("-", ""); return BitConverter.ToString(EncodedBytes).ToLower ().Replace ("-", "");
} }
public static string CombineMore (params string [] Parts) {
string NewPath = "";
foreach (string Part in Parts)
NewPath = Path.Combine(NewPath, Part);
return NewPath;
}
} }

View file

@ -15,27 +15,26 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using System; using System;
using System.IO;
namespace SparkleShare { namespace SparkleShare {
public static class SparklePaths { public static class SparklePaths {
public static string SparkleTmpDir = "/tmp/sparkleshare"; public static string SparkleTmpPath = "/tmp/sparkleshare";
public static string SparkleDir = public static string HomePath =
Environment.GetEnvironmentVariable("HOME") + Environment.GetEnvironmentVariable("HOME");
"/" + "SparkleShare/";
public static string SparklePath = Path.Combine (HomePath ,"SparkleShare");
public static string SparkleConfigDir = public static string SparkleConfigPath =
Environment.GetEnvironmentVariable("HOME") + Path.Combine (HomePath, Path.Combine (".config", "sparkleshare"));
"/" + ".config/sparkleshare/";
public static string SparkleAvatarsDir = public static string SparkleAvatarPath =
Environment.GetEnvironmentVariable("HOME") + Path.Combine (SparkleConfigPath, "avatars");
"/" + ".config/sparkleshare/" +
"avatars/";
public static string SparkleIconsDir = "/usr/share/icons/hicolor/"; public static string SparkleIconPath = "/usr/share/icons/hicolor";
} }

View file

@ -36,16 +36,16 @@ namespace SparkleShare {
Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.RedirectStandardOutput = true;
Process.StartInfo.UseShellExecute = false; Process.StartInfo.UseShellExecute = false;
string SparkleDir = SparklePaths.SparkleDir; string SparklePath = SparklePaths.SparklePath;
// Create 'SparkleShare' folder in the user's home folder // Create 'SparkleShare' folder in the user's home folder
// if it's not there already // if it's not there already
if (!Directory.Exists (SparkleDir)) { if (!Directory.Exists (SparklePath)) {
Directory.CreateDirectory (SparkleDir); Directory.CreateDirectory (SparklePath);
Console.WriteLine ("[Config] Created '" + SparkleDir + "'"); Console.WriteLine ("[Config] Created '" + SparklePath + "'");
Process.StartInfo.FileName = "gvfs-set-attribute"; Process.StartInfo.FileName = "gvfs-set-attribute";
Process.StartInfo.Arguments = SparkleDir + Process.StartInfo.Arguments = SparklePath +
" metadata::custom-icon " + " metadata::custom-icon " +
"file:///usr/share/icons/hicolor/" + "file:///usr/share/icons/hicolor/" +
"48x48/places/" + "48x48/places/" +
@ -55,21 +55,21 @@ namespace SparkleShare {
} }
// Create place to store configuration user's home folder // Create place to store configuration user's home folder
string ConfigDir = SparklePaths.SparkleConfigDir; string ConfigPath = SparklePaths.SparkleConfigPath;
string AvatarDir = SparklePaths.SparkleAvatarsDir; string AvatarPath = SparklePaths.SparkleAvatarPath;
if (!Directory.Exists (ConfigDir)) { if (!Directory.Exists (ConfigPath)) {
Directory.CreateDirectory (ConfigDir); Directory.CreateDirectory (ConfigPath);
Console.WriteLine ("[Config] Created '" + ConfigDir + "'"); Console.WriteLine ("[Config] Created '" + ConfigPath + "'");
// Create a place to store the avatars // Create a place to store the avatars
Directory.CreateDirectory (AvatarDir); Directory.CreateDirectory (AvatarPath);
Console.WriteLine ("[Config] Created '" + AvatarDir + "avatars'"); Console.WriteLine ("[Config] Created '" + AvatarPath + "avatars'");
} }
// Get all the repos in ~/SparkleShare // Get all the repos in ~/SparkleShare
string [] Repos = Directory.GetDirectories (SparkleDir); string [] Repos = Directory.GetDirectories (SparklePath);
Repositories = new SparkleRepo [Repos.Length]; Repositories = new SparkleRepo [Repos.Length];
int i = 0; int i = 0;

View file

@ -92,6 +92,7 @@ namespace SparkleShare {
LayoutVertical.PackStart (Notebook, true, true, 0); LayoutVertical.PackStart (Notebook, true, true, 0);
HButtonBox DialogButtons = new HButtonBox (); HButtonBox DialogButtons = new HButtonBox ();
DialogButtons.Layout = ButtonBoxStyle.End;
DialogButtons.BorderWidth = 6; DialogButtons.BorderWidth = 6;
Button CloseButton = new Button (Stock.Close); Button CloseButton = new Button (Stock.Close);
@ -507,7 +508,7 @@ namespace SparkleShare {
Process.StartInfo.UseShellExecute = false; Process.StartInfo.UseShellExecute = false;
Process.StartInfo.FileName = "git"; Process.StartInfo.FileName = "git";
Process.StartInfo.WorkingDirectory = Process.StartInfo.WorkingDirectory =
SparklePaths.SparkleTmpDir; SparklePaths.SparkleTmpPath;
Process.StartInfo.Arguments = "clone " + Process.StartInfo.Arguments = "clone " +
RepoRemoteUrl + " " + RepoRemoteUrl + " " +
@ -515,8 +516,8 @@ namespace SparkleShare {
Process.Start (); Process.Start ();
Process.Exited += delegate { Process.Exited += delegate {
Directory.Move (SparklePaths.SparkleTmpDir + RepoName, Directory.Move (SparklePaths.SparkleTmpPath + RepoName,
SparklePaths.SparkleDir + "Sticky"); SparklePaths.SparklePath + "Sticky");
AddDialog.Destroy (); AddDialog.Destroy ();
}; };
@ -557,7 +558,7 @@ namespace SparkleShare {
} }
public void Quit (object o, EventArgs args) { public void Quit (object o, EventArgs args) {
File.Delete (SparklePaths.SparkleTmpDir + "sparkleshare.pid"); File.Delete (SparklePaths.SparkleTmpPath + "sparkleshare.pid");
Application.Quit (); Application.Quit ();
} }