Fixed the spacing

This commit is contained in:
Konstantinos Vaggelakos 2011-10-10 01:43:33 +02:00
parent 940c5ae159
commit 7f4234a18d
2 changed files with 215 additions and 198 deletions

View file

@ -45,19 +45,19 @@ namespace SparkleShare {
public event FolderFetchedEventHandler FolderFetched; public event FolderFetchedEventHandler FolderFetched;
public delegate void FolderFetchedEventHandler (); public delegate void FolderFetchedEventHandler ();
public event FolderFetchErrorEventHandler FolderFetchError; public event FolderFetchErrorEventHandler FolderFetchError;
public delegate void FolderFetchErrorEventHandler (string remote_url); public delegate void FolderFetchErrorEventHandler (string remote_url);
public event FolderFetchingEventHandler FolderFetching; public event FolderFetchingEventHandler FolderFetching;
public delegate void FolderFetchingEventHandler (double percentage); public delegate void FolderFetchingEventHandler (double percentage);
public event FolderListChangedEventHandler FolderListChanged; public event FolderListChangedEventHandler FolderListChanged;
public delegate void FolderListChangedEventHandler (); public delegate void FolderListChangedEventHandler ();
public event FolderSizeChangedEventHandler FolderSizeChanged; public event FolderSizeChangedEventHandler FolderSizeChanged;
public delegate void FolderSizeChangedEventHandler (string folder_size); public delegate void FolderSizeChangedEventHandler (string folder_size);
public event AvatarFetchedEventHandler AvatarFetched; public event AvatarFetchedEventHandler AvatarFetched;
public delegate void AvatarFetchedEventHandler (); public delegate void AvatarFetchedEventHandler ();
@ -98,7 +98,7 @@ namespace SparkleShare {
{ {
} }
public virtual void Initialize () public virtual void Initialize ()
{ {
InstallLauncher (); InstallLauncher ();
@ -118,8 +118,8 @@ namespace SparkleShare {
// Watch the SparkleShare folder // Watch the SparkleShare folder
FileSystemWatcher watcher = new FileSystemWatcher (SparkleConfig.DefaultConfig.FoldersPath) { FileSystemWatcher watcher = new FileSystemWatcher (SparkleConfig.DefaultConfig.FoldersPath) {
IncludeSubdirectories = false, IncludeSubdirectories = false,
EnableRaisingEvents = true, EnableRaisingEvents = true,
Filter = "*" Filter = "*"
}; };
// Remove the repository when a delete event occurs // Remove the repository when a delete event occurs
@ -142,13 +142,13 @@ namespace SparkleShare {
// Handle invitations when the user saves an // Handle invitations when the user saves an
// invitation into the SparkleShare folder // invitation into the SparkleShare folder
if (args.Name.EndsWith (".sparkle") && !FirstRun) { if (args.Name.EndsWith (".sparkle") && !FirstRun) {
XmlDocument xml_doc = new XmlDocument (); XmlDocument xml_doc = new XmlDocument ();
xml_doc.Load (args.Name); xml_doc.Load (args.Name);
string server = xml_doc.GetElementsByTagName ("server") [0].InnerText; string server = xml_doc.GetElementsByTagName ("server") [0].InnerText;
string folder = xml_doc.GetElementsByTagName ("folder") [0].InnerText; string folder = xml_doc.GetElementsByTagName ("folder") [0].InnerText;
string token = xml_doc.GetElementsByTagName ("token") [0].InnerText; string token = xml_doc.GetElementsByTagName ("token") [0].InnerText;
// FIXME: this is broken :\ // FIXME: this is broken :\
if (OnInvitation != null) if (OnInvitation != null)
OnInvitation (server, folder, token); OnInvitation (server, folder, token);
@ -162,8 +162,10 @@ namespace SparkleShare {
} }
public bool FirstRun { public bool FirstRun
get { {
get
{
return SparkleConfig.DefaultConfig.User.Email.Equals ("Unknown"); return SparkleConfig.DefaultConfig.User.Email.Equals ("Unknown");
} }
} }
@ -188,8 +190,8 @@ namespace SparkleShare {
SparkleHelpers.DebugInfo ("WebRequest", url); SparkleHelpers.DebugInfo ("WebRequest", url);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url); HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);
HttpWebResponse response = (HttpWebResponse) request.GetResponse(); HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
if (response.StatusCode == HttpStatusCode.OK) { if (response.StatusCode == HttpStatusCode.OK) {
response.Close (); response.Close ();
@ -202,8 +204,10 @@ namespace SparkleShare {
} }
public List<string> Folders { public List<string> Folders
get { {
get
{
List<string> folders = SparkleConfig.DefaultConfig.Folders; List<string> folders = SparkleConfig.DefaultConfig.Folders;
folders.Sort (); folders.Sort ();
return folders; return folders;
@ -211,24 +215,28 @@ namespace SparkleShare {
} }
public List<string> PreviousHosts { public List<string> PreviousHosts
get { {
get
{
List<string> hosts = SparkleConfig.DefaultConfig.HostsWithUsername; List<string> hosts = SparkleConfig.DefaultConfig.HostsWithUsername;
hosts.AddRange(SparkleConfig.DefaultConfig.Hosts); hosts.AddRange (SparkleConfig.DefaultConfig.Hosts);
hosts.Sort (); hosts.Sort ();
return hosts; return hosts;
} }
} }
public List<string> UnsyncedFolders { public List<string> UnsyncedFolders
get { {
get
{
List<string> unsynced_folders = new List<string> (); List<string> unsynced_folders = new List<string> ();
foreach (SparkleRepoBase repo in Repositories) { foreach (SparkleRepoBase repo in Repositories) {
if (repo.HasUnsyncedChanges) if (repo.HasUnsyncedChanges)
unsynced_folders.Add (repo.Name); unsynced_folders.Add (repo.Name);
} }
return unsynced_folders; return unsynced_folders;
} }
@ -263,26 +271,26 @@ namespace SparkleShare {
if (name == null) if (name == null)
return GetLog (); return GetLog ();
string path = new string [] {SparkleConfig.DefaultConfig.FoldersPath, name}.Combine (); string path = new string [] { SparkleConfig.DefaultConfig.FoldersPath, name }.Combine ();
int log_size = 50; int log_size = 50;
foreach (SparkleRepoBase repo in Repositories) { foreach (SparkleRepoBase repo in Repositories) {
if (repo.LocalPath.Equals (path)) if (repo.LocalPath.Equals (path))
return repo.GetChangeSets (log_size); return repo.GetChangeSets (log_size);
} }
return null; return null;
} }
public abstract string EventLogHTML { get; } public abstract string EventLogHTML { get; }
public abstract string DayEntryHTML { get; } public abstract string DayEntryHTML { get; }
public abstract string EventEntryHTML { get; } public abstract string EventEntryHTML { get; }
public string GetHTMLLog (List<SparkleChangeSet> change_sets) public string GetHTMLLog (List<SparkleChangeSet> change_sets)
{ {
List <ActivityDay> activity_days = new List <ActivityDay> (); List<ActivityDay> activity_days = new List<ActivityDay> ();
List<string> emails = new List<string> (); List<string> emails = new List<string> ();
change_sets.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp))); change_sets.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp)));
@ -297,9 +305,9 @@ namespace SparkleShare {
bool change_set_inserted = false; bool change_set_inserted = false;
foreach (ActivityDay stored_activity_day in activity_days) { foreach (ActivityDay stored_activity_day in activity_days) {
if (stored_activity_day.DateTime.Year == change_set.Timestamp.Year && if (stored_activity_day.DateTime.Year == change_set.Timestamp.Year &&
stored_activity_day.DateTime.Month == change_set.Timestamp.Month && stored_activity_day.DateTime.Month == change_set.Timestamp.Month &&
stored_activity_day.DateTime.Day == change_set.Timestamp.Day) { stored_activity_day.DateTime.Day == change_set.Timestamp.Day) {
bool squash = false; bool squash = false;
foreach (SparkleChangeSet existing_set in stored_activity_day) { foreach (SparkleChangeSet existing_set in stored_activity_day) {
@ -314,8 +322,8 @@ namespace SparkleShare {
existing_set.MovedTo.AddRange (change_set.MovedTo); existing_set.MovedTo.AddRange (change_set.MovedTo);
existing_set.Notes.AddRange (change_set.Notes); existing_set.Notes.AddRange (change_set.Notes);
existing_set.Added = existing_set.Added.Distinct ().ToList (); existing_set.Added = existing_set.Added.Distinct ().ToList ();
existing_set.Edited = existing_set.Edited.Distinct ().ToList (); existing_set.Edited = existing_set.Edited.Distinct ().ToList ();
existing_set.Deleted = existing_set.Deleted.Distinct ().ToList (); existing_set.Deleted = existing_set.Deleted.Distinct ().ToList ();
if (DateTime.Compare (existing_set.Timestamp, change_set.Timestamp) < 1) { if (DateTime.Compare (existing_set.Timestamp, change_set.Timestamp) < 1) {
@ -350,10 +358,10 @@ namespace SparkleShare {
FetchAvatars (emails, 48); FetchAvatars (emails, 48);
})).Start (); })).Start ();
string event_log_html = EventLogHTML; string event_log_html = EventLogHTML;
string day_entry_html = DayEntryHTML; string day_entry_html = DayEntryHTML;
string event_entry_html = EventEntryHTML; string event_entry_html = EventEntryHTML;
string event_log = ""; string event_log = "";
foreach (ActivityDay activity_day in activity_days) { foreach (ActivityDay activity_day in activity_days) {
string event_entries = ""; string event_entries = "";
@ -369,31 +377,31 @@ namespace SparkleShare {
foreach (string file_path in change_set.Edited) { foreach (string file_path in change_set.Edited) {
string absolute_file_path = new string [] {SparkleConfig.DefaultConfig.FoldersPath, string absolute_file_path = new string [] {SparkleConfig.DefaultConfig.FoldersPath,
change_set.Folder, file_path}.Combine (); change_set.Folder, file_path}.Combine ();
if (File.Exists (absolute_file_path)) if (File.Exists (absolute_file_path))
event_entry += "<dd class='document edited'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>"; event_entry += "<dd class='document edited'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>";
else else
event_entry += "<dd class='document edited'>" + file_path + "</dd>"; event_entry += "<dd class='document edited'>" + file_path + "</dd>";
} }
} }
if (change_set.Added.Count > 0) { if (change_set.Added.Count > 0) {
foreach (string file_path in change_set.Added) { foreach (string file_path in change_set.Added) {
string absolute_file_path = new string [] {SparkleConfig.DefaultConfig.FoldersPath, string absolute_file_path = new string [] {SparkleConfig.DefaultConfig.FoldersPath,
change_set.Folder, file_path}.Combine (); change_set.Folder, file_path}.Combine ();
if (File.Exists (absolute_file_path)) if (File.Exists (absolute_file_path))
event_entry += "<dd class='document added'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>"; event_entry += "<dd class='document added'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>";
else else
event_entry += "<dd class='document added'>" + file_path + "</dd>"; event_entry += "<dd class='document added'>" + file_path + "</dd>";
} }
} }
if (change_set.Deleted.Count > 0) { if (change_set.Deleted.Count > 0) {
foreach (string file_path in change_set.Deleted) { foreach (string file_path in change_set.Deleted) {
string absolute_file_path = new string [] {SparkleConfig.DefaultConfig.FoldersPath, string absolute_file_path = new string [] {SparkleConfig.DefaultConfig.FoldersPath,
change_set.Folder, file_path}.Combine (); change_set.Folder, file_path}.Combine ();
if (File.Exists (absolute_file_path)) if (File.Exists (absolute_file_path))
event_entry += "<dd class='document deleted'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>"; event_entry += "<dd class='document deleted'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>";
else else
@ -444,7 +452,7 @@ namespace SparkleShare {
comments += "<div class=\"comment-text\">" + comments += "<div class=\"comment-text\">" +
"<p class=\"comment-author\"" + "<p class=\"comment-author\"" +
" style=\"background-image: url('" + note_avatar + "');\">" + " style=\"background-image: url('" + note_avatar + "');\">" +
note.User.Name + "</p>" + note.User.Name + "</p>" +
note.Body + note.Body +
"</div>"; "</div>";
} }
@ -458,7 +466,7 @@ namespace SparkleShare {
else else
change_set_avatar = "<!-- $no-buddy-icon-background-image -->"; change_set_avatar = "<!-- $no-buddy-icon-background-image -->";
event_entry += "</dl>"; event_entry += "</dl>";
string timestamp = change_set.Timestamp.ToString ("H:mm"); string timestamp = change_set.Timestamp.ToString ("H:mm");
@ -476,19 +484,19 @@ namespace SparkleShare {
.Replace ("<!-- $event-comments -->", comments); .Replace ("<!-- $event-comments -->", comments);
} }
string day_entry = ""; string day_entry = "";
DateTime today = DateTime.Now; DateTime today = DateTime.Now;
DateTime yesterday = DateTime.Now.AddDays (-1); DateTime yesterday = DateTime.Now.AddDays (-1);
if (today.Day == activity_day.DateTime.Day && if (today.Day == activity_day.DateTime.Day &&
today.Month == activity_day.DateTime.Month && today.Month == activity_day.DateTime.Month &&
today.Year == activity_day.DateTime.Year) { today.Year == activity_day.DateTime.Year) {
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->", "Today"); day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->", "Today");
} else if (yesterday.Day == activity_day.DateTime.Day && } else if (yesterday.Day == activity_day.DateTime.Day &&
yesterday.Month == activity_day.DateTime.Month && yesterday.Month == activity_day.DateTime.Month &&
yesterday.Year == activity_day.DateTime.Year) { yesterday.Year == activity_day.DateTime.Year) {
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->", "Yesterday"); day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->", "Yesterday");
@ -497,20 +505,20 @@ namespace SparkleShare {
// TRANSLATORS: This is the date in the event logs // TRANSLATORS: This is the date in the event logs
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->", day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
activity_day.DateTime.ToString (_("dddd, MMMM d, yyyy"))); activity_day.DateTime.ToString (_ ("dddd, MMMM d, yyyy")));
} else { } else {
// TRANSLATORS: This is the date in the event logs, without the year // TRANSLATORS: This is the date in the event logs, without the year
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->", day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
activity_day.DateTime.ToString (_("dddd, MMMM d"))); activity_day.DateTime.ToString (_ ("dddd, MMMM d")));
} }
} }
event_log += day_entry.Replace ("<!-- $day-entry-content -->", event_entries); event_log += day_entry.Replace ("<!-- $day-entry-content -->", event_entries);
} }
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log) string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log)
.Replace ("<!-- $username -->", UserName) .Replace ("<!-- $username -->", UserName)
.Replace ("<!-- $user-avatar-url -->", "file://" + GetAvatar (UserEmail, 48)); .Replace ("<!-- $user-avatar-url -->", "file://" + GetAvatar (UserEmail, 48));
@ -542,7 +550,7 @@ namespace SparkleShare {
{ {
foreach (SparkleRepoBase repo in Repositories) { foreach (SparkleRepoBase repo in Repositories) {
if (repo.Status == SyncStatus.SyncDown || if (repo.Status == SyncStatus.SyncDown ||
repo.Status == SyncStatus.SyncUp || repo.Status == SyncStatus.SyncUp ||
repo.IsBuffering) { repo.IsBuffering) {
if (OnSyncing != null) if (OnSyncing != null)
@ -579,7 +587,7 @@ namespace SparkleShare {
if (backend == null) if (backend == null)
return; return;
SparkleRepoBase repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend); SparkleRepoBase repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
repo.NewChangeSet += delegate (SparkleChangeSet change_set) { repo.NewChangeSet += delegate (SparkleChangeSet change_set) {
@ -601,13 +609,13 @@ namespace SparkleShare {
}; };
repo.SyncStatusChanged += delegate (SyncStatus status) { repo.SyncStatusChanged += delegate (SyncStatus status) {
/* if (status == SyncStatus.SyncUp) { /* if (status == SyncStatus.SyncUp) {
foreach (string path in repo.UnsyncedFilePaths) foreach (string path in repo.UnsyncedFilePaths)
Console.WriteLine (path); Console.WriteLine (path);
} }
*/ */
if (status == SyncStatus.Idle || if (status == SyncStatus.Idle ||
status == SyncStatus.SyncUp || status == SyncStatus.SyncUp ||
status == SyncStatus.SyncDown || status == SyncStatus.SyncDown ||
status == SyncStatus.Error) { status == SyncStatus.Error) {
@ -661,7 +669,7 @@ namespace SparkleShare {
if (FolderListChanged != null) if (FolderListChanged != null)
FolderListChanged (); FolderListChanged ();
FolderSize = GetFolderSize (); FolderSize = GetFolderSize ();
if (FolderSizeChanged != null) if (FolderSizeChanged != null)
@ -669,8 +677,10 @@ namespace SparkleShare {
} }
public bool NotificationsEnabled { public bool NotificationsEnabled
get { {
get
{
string notifications_enabled = string notifications_enabled =
SparkleConfig.DefaultConfig.GetConfigOption ("notifications"); SparkleConfig.DefaultConfig.GetConfigOption ("notifications");
@ -682,10 +692,11 @@ namespace SparkleShare {
return notifications_enabled.Equals (bool.TrueString); return notifications_enabled.Equals (bool.TrueString);
} }
} }
} }
public void ToggleNotifications () { public void ToggleNotifications ()
{
bool notifications_enabled = bool notifications_enabled =
SparkleConfig.DefaultConfig.GetConfigOption ("notifications") SparkleConfig.DefaultConfig.GetConfigOption ("notifications")
.Equals (bool.TrueString); .Equals (bool.TrueString);
@ -709,26 +720,26 @@ namespace SparkleShare {
private string FormatMessage (SparkleChangeSet change_set) private string FormatMessage (SparkleChangeSet change_set)
{ {
string file_name = ""; string file_name = "";
string message = ""; string message = "";
if (change_set.Added.Count > 0) { if (change_set.Added.Count > 0) {
file_name = change_set.Added [0]; file_name = change_set.Added [0];
message = String.Format (_("added {0}"), file_name); message = String.Format (_ ("added {0}"), file_name);
} }
if (change_set.MovedFrom.Count > 0) { if (change_set.MovedFrom.Count > 0) {
file_name = change_set.MovedFrom [0]; file_name = change_set.MovedFrom [0];
message = String.Format (_("moved {0}"), file_name); message = String.Format (_ ("moved {0}"), file_name);
} }
if (change_set.Edited.Count > 0) { if (change_set.Edited.Count > 0) {
file_name = change_set.Edited [0]; file_name = change_set.Edited [0];
message = String.Format (_("edited {0}"), file_name); message = String.Format (_ ("edited {0}"), file_name);
} }
if (change_set.Deleted.Count > 0) { if (change_set.Deleted.Count > 0) {
file_name = change_set.Deleted [0]; file_name = change_set.Deleted [0];
message = String.Format (_("deleted {0}"), file_name); message = String.Format (_ ("deleted {0}"), file_name);
} }
int changes_count = (change_set.Added.Count + int changes_count = (change_set.Added.Count +
@ -745,7 +756,7 @@ namespace SparkleShare {
#endif #endif
} else if (changes_count < 0) { } else if (changes_count < 0) {
message += _("did something magical"); message += _ ("did something magical");
} }
return message; return message;
@ -767,14 +778,14 @@ namespace SparkleShare {
return 0; return 0;
try { try {
foreach (FileInfo file in parent.GetFiles()) { foreach (FileInfo file in parent.GetFiles ()) {
if (!file.Exists) if (!file.Exists)
return 0; return 0;
size += file.Length; size += file.Length;
} }
foreach (DirectoryInfo directory in parent.GetDirectories()) foreach (DirectoryInfo directory in parent.GetDirectories ())
size += CalculateFolderSize (directory); size += CalculateFolderSize (directory);
} catch (Exception) { } catch (Exception) {
@ -807,7 +818,7 @@ namespace SparkleShare {
OpenSparkleShareFolder (""); OpenSparkleShareFolder ("");
} }
// Adds the user's SparkleShare key to the ssh-agent, // Adds the user's SparkleShare key to the ssh-agent,
// so all activity is done with this key // so all activity is done with this key
public void AddKey () public void AddKey ()
@ -817,16 +828,18 @@ namespace SparkleShare {
Process process = new Process (); Process process = new Process ();
process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false; process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "ssh-add"; process.StartInfo.FileName = "ssh-add";
process.StartInfo.Arguments = "\"" + Path.Combine (keys_path, key_file_name) + "\""; process.StartInfo.Arguments = "\"" + Path.Combine (keys_path, key_file_name) + "\"";
process.Start (); process.Start ();
process.WaitForExit (); process.WaitForExit ();
} }
public bool BackendIsPresent { public bool BackendIsPresent
get { {
get
{
return SparkleBackend.DefaultBackend.IsPresent; return SparkleBackend.DefaultBackend.IsPresent;
} }
} }
@ -835,11 +848,13 @@ namespace SparkleShare {
// Looks up the user's name from the global configuration // Looks up the user's name from the global configuration
public string UserName public string UserName
{ {
get { get
{
return SparkleConfig.DefaultConfig.User.Name; return SparkleConfig.DefaultConfig.User.Name;
} }
set { set
{
SparkleConfig.DefaultConfig.User = new SparkleUser (value, UserEmail); SparkleConfig.DefaultConfig.User = new SparkleUser (value, UserEmail);
} }
} }
@ -848,20 +863,22 @@ namespace SparkleShare {
// Looks up the user's email from the global configuration // Looks up the user's email from the global configuration
public string UserEmail public string UserEmail
{ {
get { get
{
return SparkleConfig.DefaultConfig.User.Email; return SparkleConfig.DefaultConfig.User.Email;
} }
set { set
{
SparkleConfig.DefaultConfig.User = new SparkleUser (UserName, value); SparkleConfig.DefaultConfig.User = new SparkleUser (UserName, value);
} }
} }
// Generates and installs an RSA keypair to identify this system // Generates and installs an RSA keypair to identify this system
public void GenerateKeyPair () public void GenerateKeyPair ()
{ {
string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath); string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath);
string key_file_name = "sparkleshare." + UserEmail + ".key"; string key_file_name = "sparkleshare." + UserEmail + ".key";
string key_file_path = Path.Combine (keys_path, key_file_name); string key_file_path = Path.Combine (keys_path, key_file_name);
@ -878,7 +895,7 @@ namespace SparkleShare {
Process process = new Process () { Process process = new Process () {
EnableRaisingEvents = true EnableRaisingEvents = true
}; };
process.StartInfo.WorkingDirectory = keys_path; process.StartInfo.WorkingDirectory = keys_path;
process.StartInfo.UseShellExecute = false; process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardOutput = true;
@ -898,7 +915,7 @@ namespace SparkleShare {
File.Copy (key_file_path + ".pub", File.Copy (key_file_path + ".pub",
Path.Combine (SparklePath, UserName + "'s key.txt")); Path.Combine (SparklePath, UserName + "'s key.txt"));
}; };
process.Start (); process.Start ();
process.WaitForExit (); process.WaitForExit ();
} }
@ -909,8 +926,8 @@ namespace SparkleShare {
public void FetchAvatars (List<string> emails, int size) public void FetchAvatars (List<string> emails, int size)
{ {
List<string> old_avatars = new List<string> (); List<string> old_avatars = new List<string> ();
bool avatar_fetched = false; bool avatar_fetched = false;
string avatar_path = new string [] { string avatar_path = new string [] {
Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath), Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath),
"icons", size + "x" + size, "status"}.Combine (); "icons", size + "x" + size, "status"}.Combine ();
@ -922,7 +939,7 @@ namespace SparkleShare {
foreach (string raw_email in emails) { foreach (string raw_email in emails) {
// Gravatar wants lowercase emails // Gravatar wants lowercase emails
string email = raw_email.ToLower (); string email = raw_email.ToLower ();
string avatar_file_path = Path.Combine (avatar_path, "avatar-" + email); string avatar_file_path = Path.Combine (avatar_path, "avatar-" + email);
if (File.Exists (avatar_file_path)) { if (File.Exists (avatar_file_path)) {
@ -935,30 +952,30 @@ namespace SparkleShare {
} }
} else { } else {
WebClient client = new WebClient (); WebClient client = new WebClient ();
string url = "http://gravatar.com/avatar/" + GetMD5 (email) + string url = "http://gravatar.com/avatar/" + GetMD5 (email) +
".jpg?s=" + size + "&d=404"; ".jpg?s=" + size + "&d=404";
try { try {
// Fetch the avatar // Fetch the avatar
byte [] buffer = client.DownloadData (url); byte [] buffer = client.DownloadData (url);
// Write the avatar data to a // Write the avatar data to a
// if not empty // if not empty
if (buffer.Length > 255) { if (buffer.Length > 255) {
avatar_fetched = true; avatar_fetched = true;
File.WriteAllBytes (avatar_file_path, buffer); File.WriteAllBytes (avatar_file_path, buffer);
SparkleHelpers.DebugInfo ("Controller", "Fetched gravatar for " + email); SparkleHelpers.DebugInfo ("Controller", "Fetched gravatar for " + email);
} }
} catch (WebException e) { } catch (WebException e) {
SparkleHelpers.DebugInfo ("Controller", "Failed fetching gravatar for " + email); SparkleHelpers.DebugInfo ("Controller", "Failed fetching gravatar for " + email);
// Stop downloading further avatars if we have no internet access // Stop downloading further avatars if we have no internet access
if (e.Status == WebExceptionStatus.Timeout) if (e.Status == WebExceptionStatus.Timeout)
break; break;
} }
} }
} }
// Fetch new versions of the avatars that we // Fetch new versions of the avatars that we
@ -992,23 +1009,23 @@ namespace SparkleShare {
// Strip the '.git' from the name // Strip the '.git' from the name
string canonical_name = Path.GetFileNameWithoutExtension (remote_folder); string canonical_name = Path.GetFileNameWithoutExtension (remote_folder);
string tmp_folder = Path.Combine (tmp_path, canonical_name); string tmp_folder = Path.Combine (tmp_path, canonical_name);
string backend = null; string backend = null;
/* if (remote_folder.EndsWith (".hg")) { /* if (remote_folder.EndsWith (".hg")) {
remote_folder = remote_folder.Substring (0, (remote_folder.Length - 3)); remote_folder = remote_folder.Substring (0, (remote_folder.Length - 3));
fetcher = new SparkleFetcherHg (server, remote_folder, tmp_folder); fetcher = new SparkleFetcherHg (server, remote_folder, tmp_folder);
backend = "Hg"; backend = "Hg";
} else if (remote_folder.EndsWith (".scp")) { } else if (remote_folder.EndsWith (".scp")) {
remote_folder = remote_folder.Substring (0, (remote_folder.Length - 4)); remote_folder = remote_folder.Substring (0, (remote_folder.Length - 4));
fetcher = new SparkleFetcherScp (server, remote_folder, tmp_folder); fetcher = new SparkleFetcherScp (server, remote_folder, tmp_folder);
backend = "Scp"; backend = "Scp";
} else {*/ } else {*/
this.fetcher = new SparkleFetcherGit (server, remote_folder, tmp_folder); this.fetcher = new SparkleFetcherGit (server, remote_folder, tmp_folder);
backend = "Git"; backend = "Git";
//} //}
bool target_folder_exists = Directory.Exists ( bool target_folder_exists = Directory.Exists (
@ -1070,8 +1087,8 @@ namespace SparkleShare {
if (Directory.Exists (tmp_path)) if (Directory.Exists (tmp_path))
Directory.Delete (tmp_path, true); Directory.Delete (tmp_path, true);
}; };
this.fetcher.ProgressChanged += delegate (double percentage) { this.fetcher.ProgressChanged += delegate (double percentage) {
if (FolderFetching != null) if (FolderFetching != null)
FolderFetching (percentage); FolderFetching (percentage);
@ -1093,8 +1110,8 @@ namespace SparkleShare {
private string GetMD5 (string s) private string GetMD5 (string s)
{ {
MD5 md5 = new MD5CryptoServiceProvider (); MD5 md5 = new MD5CryptoServiceProvider ();
Byte[] bytes = ASCIIEncoding.Default.GetBytes (s); Byte [] bytes = ASCIIEncoding.Default.GetBytes (s);
Byte[] encoded_bytes = md5.ComputeHash (bytes); Byte [] encoded_bytes = md5.ComputeHash (bytes);
return BitConverter.ToString (encoded_bytes).ToLower ().Replace ("-", ""); return BitConverter.ToString (encoded_bytes).ToLower ().Replace ("-", "");
} }
@ -1104,17 +1121,17 @@ namespace SparkleShare {
public void TryQuit () public void TryQuit ()
{ {
foreach (SparkleRepoBase repo in Repositories) { foreach (SparkleRepoBase repo in Repositories) {
if (repo.Status == SyncStatus.SyncUp || if (repo.Status == SyncStatus.SyncUp ||
repo.Status == SyncStatus.SyncDown || repo.Status == SyncStatus.SyncDown ||
repo.IsBuffering) { repo.IsBuffering) {
if (OnQuitWhileSyncing != null) if (OnQuitWhileSyncing != null)
OnQuitWhileSyncing (); OnQuitWhileSyncing ();
return; return;
} }
} }
Quit (); Quit ();
} }
@ -1132,7 +1149,7 @@ namespace SparkleShare {
// Also kill the SSH_AGENT // Also kill the SSH_AGENT
try { try {
// Check if we created the process, if so bring it down. Else leave it running // Check if we created the process, if so bring it down. Else leave it running
if (!System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK").Equals("unknown")) { if (!System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK").Equals ("unknown")) {
int pid = Int32.Parse (System.Environment.GetEnvironmentVariable ("SSH_AGENT_PID")); int pid = Int32.Parse (System.Environment.GetEnvironmentVariable ("SSH_AGENT_PID"));
Process.GetProcessById (pid).Kill (); Process.GetProcessById (pid).Kill ();
} }
@ -1153,7 +1170,7 @@ namespace SparkleShare {
public void AddNoteToFolder (string folder_name, string revision, string note) public void AddNoteToFolder (string folder_name, string revision, string note)
{ {
folder_name = folder_name.Replace ("%20", " "); folder_name = folder_name.Replace ("%20", " ");
note = note.Replace ("%20", " "); note = note.Replace ("%20", " ");
foreach (SparkleRepoBase repo in Repositories) { foreach (SparkleRepoBase repo in Repositories) {
if (repo.Name.Equals (folder_name)) if (repo.Name.Equals (folder_name))
@ -1168,20 +1185,19 @@ namespace SparkleShare {
private string AssignColor (string s) private string AssignColor (string s)
{ {
string hash = GetMD5 (s).Substring (0, 8); string hash = GetMD5 (s).Substring (0, 8);
string numbers = Regex.Replace (hash, "[a-z]", ""); string numbers = Regex.Replace (hash, "[a-z]", "");
int number = 3 + int.Parse (numbers); int number = 3 + int.Parse (numbers);
return this.tango_palette [number % this.tango_palette.Length]; return this.tango_palette [number % this.tango_palette.Length];
} }
} }
public class ChangeSet : SparkleChangeSet { } public class ChangeSet : SparkleChangeSet { }
// All change sets that happened on a day // All change sets that happened on a day
public class ActivityDay : List <SparkleChangeSet> public class ActivityDay : List<SparkleChangeSet> {
{
public DateTime DateTime; public DateTime DateTime;
public ActivityDay (DateTime date_time) public ActivityDay (DateTime date_time)

View file

@ -30,12 +30,13 @@ namespace SparkleShare {
public class SparkleController : SparkleControllerBase { public class SparkleController : SparkleControllerBase {
public SparkleController () : base () public SparkleController ()
{ : base ()
} {
}
public override void Initialize () public override void Initialize ()
{ {
Settings settings = new Settings (); Settings settings = new Settings ();
BrowserSettings browserSettings = new BrowserSettings (); BrowserSettings browserSettings = new BrowserSettings ();
@ -46,28 +47,28 @@ namespace SparkleShare {
CEF.RegisterScheme ("application", "sparkleshare", new ApplicationSchemeHandlerFactory ()); CEF.RegisterScheme ("application", "sparkleshare", new ApplicationSchemeHandlerFactory ());
CEF.RegisterScheme ("application", "file", new FileSchemeHandlerFactory ()); CEF.RegisterScheme ("application", "file", new FileSchemeHandlerFactory ());
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault (false);
// Add msysgit to path, as we cannot asume it is added to the path Application.EnableVisualStyles ();
// Asume it is installed in @"C:\msysgit\bin" for now Application.SetCompatibleTextRenderingDefault (false);
string MSysGit=@"C:\msysgit";
string newPath = MSysGit + @"\bin" + ";" // Add msysgit to path, as we cannot asume it is added to the path
+ MSysGit + @"\mingw\bin" + ";" // Asume it is installed in @"C:\msysgit\bin" for now
+ MSysGit + @"\cmd" + ";" string MSysGit = @"C:\msysgit";
+ System.Environment.ExpandEnvironmentVariables ("%PATH%");
System.Environment.SetEnvironmentVariable ("PATH", newPath);
System.Environment.SetEnvironmentVariable ("PLINK_PROTOCOL", "ssh");
if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("HOME"))) string newPath = MSysGit + @"\bin" + ";"
System.Environment.SetEnvironmentVariable ("HOME", Environment.ExpandEnvironmentVariables ("%HOMEDRIVE%%HOMEPATH%")); + MSysGit + @"\mingw\bin" + ";"
+ MSysGit + @"\cmd" + ";"
+ System.Environment.ExpandEnvironmentVariables ("%PATH%");
System.Environment.SetEnvironmentVariable ("PATH", newPath);
System.Environment.SetEnvironmentVariable ("PLINK_PROTOCOL", "ssh");
StartSshAgent(); if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("HOME")))
System.Environment.SetEnvironmentVariable ("HOME", Environment.ExpandEnvironmentVariables ("%HOMEDRIVE%%HOMEPATH%"));
base.Initialize (); StartSshAgent ();
}
base.Initialize ();
}
public override string EventLogHTML public override string EventLogHTML
{ {
@ -111,53 +112,53 @@ namespace SparkleShare {
} }
// Creates a .desktop entry in autostart folder to // Creates a .desktop entry in autostart folder to
// start SparkleShare automatically at login // start SparkleShare automatically at login
public override void EnableSystemAutostart () public override void EnableSystemAutostart ()
{ {
} }
// Installs a launcher so the user can launch SparkleShare
// from the Internet category if needed
public override void InstallLauncher ()
{
}
// Adds the SparkleShare folder to the user's // Installs a launcher so the user can launch SparkleShare
// list of bookmarked places // from the Internet category if needed
public override void AddToBookmarks () public override void InstallLauncher ()
{ {
} }
// Creates the SparkleShare folder in the user's home folder // Adds the SparkleShare folder to the user's
public override bool CreateSparkleShareFolder () // list of bookmarked places
{ public override void AddToBookmarks ()
if (!Directory.Exists (SparklePaths.SparklePath)) { {
}
Directory.CreateDirectory (SparklePaths.SparklePath);
SparkleHelpers.DebugInfo ("Config", "Created '" + SparklePaths.SparklePath + "'");
return true; // Creates the SparkleShare folder in the user's home folder
public override bool CreateSparkleShareFolder ()
{
if (!Directory.Exists (SparklePaths.SparklePath)) {
} Directory.CreateDirectory (SparklePaths.SparklePath);
SparkleHelpers.DebugInfo ("Config", "Created '" + SparklePaths.SparklePath + "'");
return false; return true;
}
public override void OpenSparkleShareFolder (string subfolder) }
{
Process process = new Process();
process.StartInfo.Arguments = ",/root," + SparkleHelpers.CombineMore(SparklePaths.SparklePath, subfolder);
process.StartInfo.FileName = "explorer";
process.Start();
}
private void StartSshAgent () return false;
{ }
public override void OpenSparkleShareFolder (string subfolder)
{
Process process = new Process ();
process.StartInfo.Arguments = ",/root," + SparkleHelpers.CombineMore (SparklePaths.SparklePath, subfolder);
process.StartInfo.FileName = "explorer";
process.Start ();
}
private void StartSshAgent ()
{
// Check to see if the process is running // Check to see if the process is running
Process [] ProcessList = Process.GetProcesses (); Process [] ProcessList = Process.GetProcesses ();
foreach (Process p in ProcessList) { foreach (Process p in ProcessList) {
@ -196,9 +197,9 @@ namespace SparkleShare {
SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, PID=unknown"); SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, PID=unknown");
} }
} }
} }
} }
} }