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) {
string AvatarPath = SparklePaths.SparkleAvatarsDir +
Size + "x" + Size + "/";
string AvatarPath = Path.Combine (SparklePaths.SparkleAvatarPath,
Size + "x" + Size);
if (!Directory.Exists (AvatarPath)) {
Directory.CreateDirectory (AvatarPath);
@ -35,10 +35,10 @@ namespace SparkleShare {
}
string AvatarFile = AvatarPath + Email;
string AvatarFilePath = AvatarPath + Email;
if (File.Exists (AvatarFile))
return AvatarFile;
if (File.Exists (AvatarFilePath))
return AvatarFilePath;
else {
@ -48,7 +48,7 @@ namespace SparkleShare {
Uri GravatarUri = new Uri ("http://www.gravatar.com/avatar/" +
GetMD5 (Email) + ".jpg?s=" + Size + "&d=404");
string TmpFile = SparklePaths.SparkleTmpDir + Email + Size;
string TmpFile = SparklePaths.SparkleTmpPath + Email + Size;
if (!File.Exists (TmpFile)) {
@ -62,14 +62,15 @@ namespace SparkleShare {
}
string FallbackFileName = "/usr/share/icons/hicolor/" +
Size + "x" + Size +
"/status/avatar-default.png";
string FallbackFileName = CombineMore (SparklePaths.SparkleIconPath,
Size + "x" + Size,
"status",
"avatar-default.png");
if (File.Exists (FallbackFileName))
return FallbackFileName;
else
return "/usr/share/icons/hicolor/16x16/status/avatar-default.png";
return "";
}
}
@ -84,6 +85,13 @@ namespace SparkleShare {
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/>.
using System;
using System.IO;
namespace SparkleShare {
public static class SparklePaths {
public static string SparkleTmpDir = "/tmp/sparkleshare";
public static string SparkleTmpPath = "/tmp/sparkleshare";
public static string SparkleDir =
Environment.GetEnvironmentVariable("HOME") +
"/" + "SparkleShare/";
public static string HomePath =
Environment.GetEnvironmentVariable("HOME");
public static string SparklePath = Path.Combine (HomePath ,"SparkleShare");
public static string SparkleConfigDir =
Environment.GetEnvironmentVariable("HOME") +
"/" + ".config/sparkleshare/";
public static string SparkleConfigPath =
Path.Combine (HomePath, Path.Combine (".config", "sparkleshare"));
public static string SparkleAvatarsDir =
Environment.GetEnvironmentVariable("HOME") +
"/" + ".config/sparkleshare/" +
"avatars/";
public static string SparkleAvatarPath =
Path.Combine (SparkleConfigPath, "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.UseShellExecute = false;
string SparkleDir = SparklePaths.SparkleDir;
string SparklePath = SparklePaths.SparklePath;
// Create 'SparkleShare' folder in the user's home folder
// if it's not there already
if (!Directory.Exists (SparkleDir)) {
Directory.CreateDirectory (SparkleDir);
Console.WriteLine ("[Config] Created '" + SparkleDir + "'");
if (!Directory.Exists (SparklePath)) {
Directory.CreateDirectory (SparklePath);
Console.WriteLine ("[Config] Created '" + SparklePath + "'");
Process.StartInfo.FileName = "gvfs-set-attribute";
Process.StartInfo.Arguments = SparkleDir +
Process.StartInfo.Arguments = SparklePath +
" metadata::custom-icon " +
"file:///usr/share/icons/hicolor/" +
"48x48/places/" +
@ -55,21 +55,21 @@ namespace SparkleShare {
}
// Create place to store configuration user's home folder
string ConfigDir = SparklePaths.SparkleConfigDir;
string AvatarDir = SparklePaths.SparkleAvatarsDir;
if (!Directory.Exists (ConfigDir)) {
string ConfigPath = SparklePaths.SparkleConfigPath;
string AvatarPath = SparklePaths.SparkleAvatarPath;
if (!Directory.Exists (ConfigPath)) {
Directory.CreateDirectory (ConfigDir);
Console.WriteLine ("[Config] Created '" + ConfigDir + "'");
Directory.CreateDirectory (ConfigPath);
Console.WriteLine ("[Config] Created '" + ConfigPath + "'");
// Create a place to store the avatars
Directory.CreateDirectory (AvatarDir);
Console.WriteLine ("[Config] Created '" + AvatarDir + "avatars'");
Directory.CreateDirectory (AvatarPath);
Console.WriteLine ("[Config] Created '" + AvatarPath + "avatars'");
}
// Get all the repos in ~/SparkleShare
string [] Repos = Directory.GetDirectories (SparkleDir);
string [] Repos = Directory.GetDirectories (SparklePath);
Repositories = new SparkleRepo [Repos.Length];
int i = 0;

View file

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