From 9df6eef30f17c29dce029457b8f1419d507bd7eb Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 18 Nov 2012 15:29:22 +0000 Subject: [PATCH 01/14] linux: fix compile error --- SparkleShare/Linux/SparkleStatusIcon.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SparkleShare/Linux/SparkleStatusIcon.cs b/SparkleShare/Linux/SparkleStatusIcon.cs index ecc42d7e..f06cf034 100644 --- a/SparkleShare/Linux/SparkleStatusIcon.cs +++ b/SparkleShare/Linux/SparkleStatusIcon.cs @@ -176,7 +176,7 @@ namespace SparkleShare { try_again_item.Activated += Controller.TryAgainDelegate (folder_name); (item.Submenu as Menu).Add (error_item); - (item.Submenu as Menu).Add (new SeparatorMenuItem (); + (item.Submenu as Menu).Add (new SeparatorMenuItem ()); (item.Submenu as Menu).Add (try_again_item); } else { From cdf28e8d203f64ca3b2f98d39f5d7d46cb48df17 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 18 Nov 2012 18:49:57 +0000 Subject: [PATCH 02/14] repo git: reuse regex objects --- SparkleLib/Git/SparkleRepoGit.cs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index f452b2cc..d50afc6b 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -34,6 +34,16 @@ namespace SparkleLib.Git { private string cached_branch; + private Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled); + private Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled); + + private Regex log_regex = new Regex (@"commit ([a-z0-9]{40})\n" + + "Author: (.+) <(.+)>\n" + + "*" + + "Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " + + "([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" + + "*", RegexOptions.Compiled); + private string branch { get { if (string.IsNullOrEmpty (this.cached_branch)) { @@ -224,11 +234,10 @@ namespace SparkleLib.Git { git.Start (); double percentage = 1.0; - Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled); while (!git.StandardError.EndOfStream) { string line = git.StandardError.ReadLine (); - Match match = progress_regex.Match (line); + Match match = this.progress_regex.Match (line); double speed = 0.0; double number = 0.0; @@ -245,9 +254,7 @@ namespace SparkleLib.Git { } else { // "Writing objects" stage number = (number / 100 * 80 + 20); - - Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled); - Match speed_match = speed_regex.Match (line); + Match speed_match = this.speed_regex.Match (line); if (speed_match.Success) { speed = double.Parse (speed_match.Groups [1].Value) * 1024; @@ -309,11 +316,10 @@ namespace SparkleLib.Git { git.Start (); double percentage = 1.0; - Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled); while (!git.StandardError.EndOfStream) { string line = git.StandardError.ReadLine (); - Match match = progress_regex.Match (line); + Match match = this.progress_regex.Match (line); double speed = 0.0; double number = 0.0; @@ -330,9 +336,7 @@ namespace SparkleLib.Git { } else { // "Writing objects" stage number = (number / 100 * 80 + 20); - - Regex speed_regex = new Regex (@"([0-9\.]+) ([KM])iB/s", RegexOptions.Compiled); - Match speed_match = speed_regex.Match (line); + Match speed_match = this.speed_regex.Match (line); if (speed_match.Success) { speed = double.Parse (speed_match.Groups [1].Value) * 1024; @@ -732,15 +736,9 @@ namespace SparkleLib.Git { entries.Add (last_entry); - Regex regex = new Regex (@"commit ([a-z0-9]{40})\n" + - "Author: (.+) <(.+)>\n" + - "*" + - "Date: ([0-9]{4})-([0-9]{2})-([0-9]{2}) " + - "([0-9]{2}):([0-9]{2}):([0-9]{2}) (.[0-9]{4})\n" + - "*", RegexOptions.Compiled); foreach (string log_entry in entries) { - Match match = regex.Match (log_entry); + Match match = this.log_regex.Match (log_entry); if (match.Success) { SparkleChangeSet change_set = new SparkleChangeSet (); From aae243374188df4db1aa8fc1906478c20262a2b8 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 19 Nov 2012 12:16:57 +0000 Subject: [PATCH 03/14] controller: try moving projects from .tmp twice and add more debug output --- SparkleShare/SparkleControllerBase.cs | 19 +++++++++++++------ SparkleShare/SparkleEventLogController.cs | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 1ee73f95..a89a4578 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -455,7 +455,7 @@ namespace SparkleShare { } - private void ClearFolderAttributes (string path) + private void ClearDirectoryAttributes (string path) { if (!Directory.Exists (path)) return; @@ -463,7 +463,7 @@ namespace SparkleShare { string [] folders = Directory.GetDirectories (path); foreach (string folder in folders) - ClearFolderAttributes (folder); + ClearDirectoryAttributes (folder); string [] files = Directory.GetFiles(path); @@ -652,13 +652,20 @@ namespace SparkleShare { string target_folder_path = Path.Combine (this.config.FoldersPath, target_folder_name); try { - ClearFolderAttributes (this.fetcher.TargetFolder); Directory.Move (this.fetcher.TargetFolder, target_folder_path); } catch (Exception e) { - SparkleLogger.LogInfo ("Controller", "Error moving directory: " + e.Message); - this.watcher.EnableRaisingEvents = true; - return; + SparkleLogger.LogInfo ("Controller", "Error moving directory: \"" + e.Message + "\", trying again..."); + + try { + ClearDirectoryAttributes (this.fetcher.TargetFolder); + Directory.Move (this.fetcher.TargetFolder, target_folder_path); + + } catch (Exception x) { + SparkleLogger.LogInfo ("Controller", "Error moving directory: " + x.Message); + this.watcher.EnableRaisingEvents = true; + return; + } } string backend = SparkleFetcherBase.GetBackend (this.fetcher.RemoteUrl.AbsolutePath); diff --git a/SparkleShare/SparkleEventLogController.cs b/SparkleShare/SparkleEventLogController.cs index de596df6..0a5014bc 100755 --- a/SparkleShare/SparkleEventLogController.cs +++ b/SparkleShare/SparkleEventLogController.cs @@ -241,7 +241,7 @@ namespace SparkleShare { Program.Controller.OpenWebsite (url); } else if (url.StartsWith ("restore://") && this.restore_revision_info == null) { - Regex regex = new Regex ("restore://(.+)/([a-f0-9]+)/(.+)/(.{3} [0-9]+ [0-9]+h[0-9]+)/(.+)", RegexOptions.Compiled); + Regex regex = new Regex ("restore://(.+)/([a-f0-9]+)/(.+)/(.{3} [0-9]+ [0-9]+h[0-9]+)/(.+)"); Match match = regex.Match (url); if (match.Success) { From c865e71d122b5801302fe158648c1f84f4a9bdaa Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 19 Nov 2012 15:06:56 +0000 Subject: [PATCH 04/14] clean up --- SparkleLib/Makefile.am | 1 - SparkleLib/SparkleExceptions.cs | 37 --- SparkleLib/SparkleLib.csproj | 12 +- SparkleShare/Mac/SparkleAbout.cs | 1 - SparkleShare/Mac/SparkleSetupWindow.cs | 1 - SparkleShare/SparkleControllerBase.cs | 361 ++++++++++++------------- SparkleShare/SparkleKeys.cs | 53 ++-- 7 files changed, 199 insertions(+), 267 deletions(-) delete mode 100644 SparkleLib/SparkleExceptions.cs diff --git a/SparkleLib/Makefile.am b/SparkleLib/Makefile.am index 9d0cf6a5..aee6a0e3 100755 --- a/SparkleLib/Makefile.am +++ b/SparkleLib/Makefile.am @@ -6,7 +6,6 @@ ASSEMBLY_INFO_SOURCE = Defines.cs SOURCES = \ SparkleBackend.cs \ SparkleConfig.cs \ - SparkleExceptions.cs \ SparkleExtensions.cs \ SparkleFetcherBase.cs \ SparkleListenerBase.cs \ diff --git a/SparkleLib/SparkleExceptions.cs b/SparkleLib/SparkleExceptions.cs deleted file mode 100644 index 78e24d9c..00000000 --- a/SparkleLib/SparkleExceptions.cs +++ /dev/null @@ -1,37 +0,0 @@ -// SparkleShare, a collaboration and sharing tool. -// Copyright (C) 2010 Hylke Bons -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - - -using System; - -namespace SparkleLib { - - public class QuotaExceededException : Exception { - - public readonly int QuotaLimit = -1; - - - public QuotaExceededException () - { - } - - - public QuotaExceededException (string message, int quota_limit) : base (message) - { - QuotaLimit = quota_limit; - } - } -} diff --git a/SparkleLib/SparkleLib.csproj b/SparkleLib/SparkleLib.csproj index 61fb76a1..1b0cf693 100644 --- a/SparkleLib/SparkleLib.csproj +++ b/SparkleLib/SparkleLib.csproj @@ -13,15 +13,15 @@ none - false + False ..\bin prompt 4 - false + False none - false + False bin\Debug 4 @@ -40,17 +40,15 @@ - - - - + + diff --git a/SparkleShare/Mac/SparkleAbout.cs b/SparkleShare/Mac/SparkleAbout.cs index dd7cff60..963aa457 100755 --- a/SparkleShare/Mac/SparkleAbout.cs +++ b/SparkleShare/Mac/SparkleAbout.cs @@ -22,7 +22,6 @@ using System.IO; using MonoMac.AppKit; using MonoMac.Foundation; using MonoMac.ObjCRuntime; -using MonoMac.WebKit; namespace SparkleShare { diff --git a/SparkleShare/Mac/SparkleSetupWindow.cs b/SparkleShare/Mac/SparkleSetupWindow.cs index 364501a0..0b396131 100755 --- a/SparkleShare/Mac/SparkleSetupWindow.cs +++ b/SparkleShare/Mac/SparkleSetupWindow.cs @@ -23,7 +23,6 @@ using System.IO; using MonoMac.Foundation; using MonoMac.AppKit; using MonoMac.ObjCRuntime; -using MonoMac.WebKit; namespace SparkleShare { diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index a89a4578..de4ae5cc 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -22,9 +22,7 @@ using System.Linq; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; -using System.Text.RegularExpressions; using System.Threading; -using System.Security.Cryptography; using SparkleLib; @@ -40,8 +38,6 @@ namespace SparkleShare { } public bool RepositoriesLoaded { get; private set;} - - private List repositories = new List (); public string FoldersPath { get; private set; } public double ProgressPercentage = 0.0; @@ -63,10 +59,9 @@ namespace SparkleShare { public event FolderFetchingHandler FolderFetching = delegate { }; public delegate void FolderFetchingHandler (double percentage); - + + public event Action FolderListChanged = delegate { }; - - public event Action OnIdle = delegate { }; public event Action OnSyncing = delegate { }; public event Action OnError = delegate { }; @@ -126,10 +121,6 @@ namespace SparkleShare { } - public abstract string EventLogHTML { get; } - public abstract string DayEntryHTML { get; } - public abstract string EventEntryHTML { get; } - // Path where the plugins are kept public abstract string PluginsPath { get; } @@ -155,13 +146,18 @@ namespace SparkleShare { // Opens a file with the appropriate application public abstract void OpenWebsite (string url); + public abstract string EventLogHTML { get; } + public abstract string DayEntryHTML { get; } + public abstract string EventEntryHTML { get; } + private SparkleConfig config; private SparkleFetcherBase fetcher; private FileSystemWatcher watcher; - private Object repo_lock = new Object (); + private Object repo_lock = new Object (); private Object check_repos_lock = new Object (); - + private List skipped_avatars = new List (); + private List repositories = new List (); private bool lost_folders_path = false; @@ -247,7 +243,7 @@ namespace SparkleShare { { if (this.lost_folders_path) { Program.UI.Bubbles.Controller.ShowBubble ("Where's your SparkleShare folder?", - "Did you put it on a disattached drive?", null); + "Did you put it on a detached drive?", null); Environment.Exit (-1); } @@ -282,6 +278,105 @@ namespace SparkleShare { } + public void ShowSetupWindow (PageType page_type) + { + ShowSetupWindowEvent (page_type); + } + + + public void ShowAboutWindow () + { + ShowAboutWindowEvent (); + } + + + public void ShowEventLogWindow () + { + ShowEventLogWindowEvent (); + } + + + public void OpenSparkleShareFolder () + { + OpenFolder (this.config.FoldersPath); + } + + + public void OpenSparkleShareFolder (string name) + { + OpenFolder (new SparkleFolder (name).FullPath); + } + + + public void ToggleNotifications () + { + bool notifications_enabled = this.config.GetConfigOption ("notifications").Equals (bool.TrueString); + this.config.SetConfigOption ("notifications", (!notifications_enabled).ToString ()); + } + + + private void CheckRepositories () + { + lock (this.check_repos_lock) { + string path = this.config.FoldersPath; + + // Detect any renames + foreach (string folder_path in Directory.GetDirectories (path)) { + string folder_name = Path.GetFileName (folder_path); + + if (folder_name.Equals (".tmp")) + continue; + + if (this.config.GetIdentifierForFolder (folder_name) == null) { + string identifier_file_path = Path.Combine (folder_path, ".sparkleshare"); + + if (!File.Exists (identifier_file_path)) + continue; + + string identifier = File.ReadAllText (identifier_file_path).Trim (); + + if (this.config.IdentifierExists (identifier)) { + RemoveRepository (folder_path); + this.config.RenameFolder (identifier, folder_name); + + string new_folder_path = Path.Combine (path, folder_name); + AddRepository (new_folder_path); + + SparkleLogger.LogInfo ("Controller", + "Renamed folder with identifier " + identifier + " to '" + folder_name + "'"); + } + } + } + + // Remove any deleted folders + foreach (string folder_name in this.config.Folders) { + string folder_path = new SparkleFolder (folder_name).FullPath; + + if (!Directory.Exists (folder_path)) { + this.config.RemoveFolder (folder_name); + RemoveRepository (folder_path); + + SparkleLogger.LogInfo ("Controller", "Removed folder '" + folder_name + "' from config"); + + } else { + AddRepository (folder_path); + } + } + + // Remove any duplicate folders + string previous_name = ""; + foreach (string folder_name in this.config.Folders) { + if (!string.IsNullOrEmpty (previous_name) && folder_name.Equals (previous_name)) + this.config.RemoveFolder (folder_name); + else + previous_name = folder_name; + } + + FolderListChanged (); + } + } + + private void AddRepository (string folder_path) { SparkleRepoBase repo = null; @@ -349,8 +444,7 @@ namespace SparkleShare { repo.ConflictResolved += delegate { if (NotificationsEnabled) - AlertNotificationRaised ("Conflict detected", - "Don't worry, SparkleShare made a copy of each conflicting file."); + AlertNotificationRaised ("Conflict happened", "Don't worry, we've made a copy of each conflicting file."); }; this.repositories.Add (repo); @@ -364,123 +458,13 @@ namespace SparkleShare { if (repo.LocalPath.Equals (folder_path)) { this.repositories.Remove (repo); repo.Dispose (); - return; } } } - private void CheckRepositories () - { - lock (this.check_repos_lock) { - string path = this.config.FoldersPath; - - // Detect any renames - foreach (string folder_path in Directory.GetDirectories (path)) { - string folder_name = Path.GetFileName (folder_path); - - if (folder_name.Equals (".tmp")) - continue; - - if (this.config.GetIdentifierForFolder (folder_name) == null) { - string identifier_file_path = Path.Combine (folder_path, ".sparkleshare"); - - if (!File.Exists (identifier_file_path)) - continue; - - string identifier = File.ReadAllText (identifier_file_path).Trim (); - - if (this.config.IdentifierExists (identifier)) { - RemoveRepository (folder_path); - this.config.RenameFolder (identifier, folder_name); - - string new_folder_path = Path.Combine (path, folder_name); - AddRepository (new_folder_path); - - SparkleLogger.LogInfo ("Controller", - "Renamed folder with identifier " + identifier + " to '" + folder_name + "'"); - } - } - } - - // Remove any deleted folders - foreach (string folder_name in this.config.Folders) { - string folder_path = new SparkleFolder (folder_name).FullPath; - - if (!Directory.Exists (folder_path)) { - this.config.RemoveFolder (folder_name); - RemoveRepository (folder_path); - - SparkleLogger.LogInfo ("Controller", "Removed folder '" + folder_name + "' from config"); - - } else { - AddRepository (folder_path); - } - } - - // Remove any duplicate folders - string previous_name = ""; - foreach (string folder_name in this.config.Folders) { - if (!string.IsNullOrEmpty (previous_name) && folder_name.Equals (previous_name)) - this.config.RemoveFolder (folder_name); - else - previous_name = folder_name; - } - - FolderListChanged (); - } - } - - - // Fires events for the current syncing state - private void UpdateState () - { - bool has_unsynced_repos = false; - - foreach (SparkleRepoBase repo in Repositories) { - if (repo.Status == SyncStatus.SyncDown || repo.Status == SyncStatus.SyncUp || repo.IsBuffering) { - OnSyncing (); - return; - - } else if (repo.HasUnsyncedChanges) { - has_unsynced_repos = true; - } - } - - if (has_unsynced_repos) - OnError (); - else - OnIdle (); - } - - - private void ClearDirectoryAttributes (string path) - { - if (!Directory.Exists (path)) - return; - - string [] folders = Directory.GetDirectories (path); - - foreach (string folder in folders) - ClearDirectoryAttributes (folder); - - string [] files = Directory.GetFiles(path); - - foreach (string file in files) - if (!IsSymlink (file)) - File.SetAttributes (file, FileAttributes.Normal); - } - - - private bool IsSymlink (string file) - { - FileAttributes attributes = File.GetAttributes (file); - return ((attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint); - } - - - public void OnFolderActivity (object o, FileSystemEventArgs args) + private void OnFolderActivity (object o, FileSystemEventArgs args) { if (args != null && args.FullPath.EndsWith (".xml") && args.ChangeType == WatcherChangeTypes.Created) { @@ -499,7 +483,7 @@ namespace SparkleShare { } - public void HandleInvite (FileSystemEventArgs args) + private void HandleInvite (FileSystemEventArgs args) { if (this.fetcher != null && this.fetcher.IsActive) { @@ -531,6 +515,28 @@ namespace SparkleShare { } + // Fires events for the current syncing state + private void UpdateState () + { + bool has_unsynced_repos = false; + + foreach (SparkleRepoBase repo in Repositories) { + if (repo.Status == SyncStatus.SyncDown || repo.Status == SyncStatus.SyncUp || repo.IsBuffering) { + OnSyncing (); + return; + + } else if (repo.HasUnsyncedChanges) { + has_unsynced_repos = true; + } + } + + if (has_unsynced_repos) + OnError (); + else + OnIdle (); + } + + public void StartFetcher (string address, string required_fingerprint, string remote_path, string announcements_url, bool fetch_prior_history) { @@ -567,7 +573,6 @@ namespace SparkleShare { return; } - this.fetcher.Finished += delegate (bool repo_is_encrypted, bool repo_is_empty, string [] warnings) { if (repo_is_encrypted && repo_is_empty) { ShowSetupWindowEvent (PageType.CryptoSetup); @@ -615,6 +620,12 @@ namespace SparkleShare { } + public bool CheckPassword (string password) + { + return this.fetcher.IsFetchedRepoPasswordCorrect (password); + } + + public void FinishFetcher (string password) { this.fetcher.EnableFetchedRepoCrypto (password); @@ -685,61 +696,13 @@ namespace SparkleShare { } - public bool CheckPassword (string password) - { - return this.fetcher.IsFetchedRepoPasswordCorrect (password); - } - - - public void ShowSetupWindow (PageType page_type) - { - ShowSetupWindowEvent (page_type); - } - - - public void ShowAboutWindow () - { - ShowAboutWindowEvent (); - } - - - public void ShowEventLogWindow () - { - ShowEventLogWindowEvent (); - } - - - public void OpenSparkleShareFolder () - { - OpenFolder (this.config.FoldersPath); - } - - - public void OpenSparkleShareFolder (string name) - { - OpenFolder (new SparkleFolder (name).FullPath); - } - - - public void ToggleNotifications () { - bool notifications_enabled = this.config.GetConfigOption ("notifications").Equals (bool.TrueString); - this.config.SetConfigOption ("notifications", (!notifications_enabled).ToString ()); - } - - - private List skipped_avatars = new List (); - public string GetAvatar (string email, int size) { ServicePointManager.ServerCertificateValidationCallback = GetAvatarValidationCallBack; - string fetch_avatars_option = this.config.GetConfigOption ("fetch_avatars"); - if (fetch_avatars_option != null && - fetch_avatars_option.Equals (bool.FalseString)) { - + if (fetch_avatars_option != null && fetch_avatars_option.Equals (bool.FalseString)) return null; - } email = email.ToLower (); @@ -788,16 +751,24 @@ namespace SparkleShare { } - private bool GetAvatarValidationCallBack (Object sender, X509Certificate certificate, - X509Chain chain, SslPolicyErrors errors) + public virtual void Quit () + { + foreach (SparkleRepoBase repo in Repositories) + repo.Dispose (); + + Environment.Exit (0); + } + + + private bool GetAvatarValidationCallBack (Object sender, + X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { X509Certificate2 certificate2 = new X509Certificate2 (certificate.GetRawCertData ()); // On some systems (mostly Linux) we can't assume the needed certificates are // available, so we have to check the certificate's SHA-1 fingerprint manually. // - // Obtained from https://www.gravatar.com/ on Aug 18 2012 and - // expires on Oct 24 2015. + // Obtained from https://www.gravatar.com/ on Aug 18 2012 and expires on Oct 24 2015. string gravatar_cert_fingerprint = "217ACB08C0A1ACC23A21B6ECDE82CD45E14DEC19"; if (certificate2.Thumbprint.Equals (gravatar_cert_fingerprint)) { @@ -810,12 +781,28 @@ namespace SparkleShare { } - public virtual void Quit () + private void ClearDirectoryAttributes (string path) { - foreach (SparkleRepoBase repo in Repositories) - repo.Dispose (); - - Environment.Exit (0); + if (!Directory.Exists (path)) + return; + + string [] folders = Directory.GetDirectories (path); + + foreach (string folder in folders) + ClearDirectoryAttributes (folder); + + string [] files = Directory.GetFiles(path); + + foreach (string file in files) + if (!IsSymlink (file)) + File.SetAttributes (file, FileAttributes.Normal); + } + + + private bool IsSymlink (string file) + { + FileAttributes attributes = File.GetAttributes (file); + return ((attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint); } } } diff --git a/SparkleShare/SparkleKeys.cs b/SparkleShare/SparkleKeys.cs index 292fd636..cbb5232b 100644 --- a/SparkleShare/SparkleKeys.cs +++ b/SparkleShare/SparkleKeys.cs @@ -33,29 +33,20 @@ namespace SparkleShare { if (File.Exists (key_file_path)) { SparkleLogger.LogInfo ("Auth", "A key pair exists ('" + key_name + "'), leaving it untouched"); return new string [] { key_file_path, key_file_path + ".pub" }; - - } else { - if (!Directory.Exists (output_path)) - Directory.CreateDirectory (output_path); } - Process process = new Process (); - - process.StartInfo.FileName = "ssh-keygen"; - process.StartInfo.WorkingDirectory = output_path; - process.StartInfo.UseShellExecute = false; - process.StartInfo.CreateNoWindow = true; - string computer_name = System.Net.Dns.GetHostName (); if (computer_name.EndsWith (".local")) computer_name = computer_name.Substring (0, computer_name.Length - 6); - process.StartInfo.Arguments = "-t rsa " + // crypto type + string arguments = "-t rsa " + // crypto type "-P \"\" " + // empty password "-C \"" + computer_name + "\" " + // key comment "-f \"" + key_name + "\""; // file name + SparkleKeyProcess process = new SparkleKeyProcess ("ssh-keygen", arguments); + process.StartInfo.WorkingDirectory = output_path; process.Start (); process.WaitForExit (); @@ -70,14 +61,7 @@ namespace SparkleShare { public static void ImportPrivateKey (string key_file_path) { - Process process = new Process (); - - process.StartInfo.FileName = "ssh-add"; - process.StartInfo.Arguments = "\"" + key_file_path + "\""; - process.StartInfo.UseShellExecute = false; - process.StartInfo.CreateNoWindow = true; - process.StartInfo.RedirectStandardError = true; - + SparkleKeyProcess process = new SparkleKeyProcess ("ssh-add", "\"" + key_file_path + "\""); process.Start (); process.WaitForExit (); @@ -90,23 +74,26 @@ namespace SparkleShare { public static void ListPrivateKeys () { - Process process = new Process (); - - process.StartInfo.FileName = "ssh-add"; - process.StartInfo.Arguments = "-l"; - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.CreateNoWindow = true; - + SparkleKeyProcess process = new SparkleKeyProcess ("ssh-add", "-l"); process.Start (); - - // Reading the standard output HAS to go before - // WaitForExit, or it will hang forever on output > 4096 bytes string keys_in_use = process.StandardOutput.ReadToEnd (); process.WaitForExit (); - SparkleLogger.LogInfo ("Auth", "The following keys may be used: " + - Environment.NewLine + keys_in_use.Trim ()); + SparkleLogger.LogInfo ("Auth", "The following keys may be used:\n" + keys_in_use.Trim ()); + } + + + private class SparkleKeyProcess : Process { + + public SparkleKeyProcess (string command, string arguments) : base () + { + StartInfo.FileName = command; + StartInfo.Arguments = arguments; + StartInfo.UseShellExecute = false; + StartInfo.RedirectStandardOutput = true; + StartInfo.RedirectStandardError = true; + StartInfo.CreateNoWindow = true; + } } } } From d403e80e047bad0936fa4e52d03e7a19aa0dec64 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 19 Nov 2012 15:47:28 +0000 Subject: [PATCH 05/14] more cleanup --- SparkleShare/Common/Plugins/bitbucket.xml | 1 - SparkleShare/Common/Plugins/github.xml | 1 - SparkleShare/Common/Plugins/gitorious.xml | 1 - SparkleShare/Common/Plugins/own-server.xml | 1 - SparkleShare/Common/Plugins/ssnet.xml | 1 - SparkleShare/Mac/SparkleBadger.cs | 90 ---------------------- SparkleShare/Mac/SparkleShare.csproj | 1 - 7 files changed, 96 deletions(-) delete mode 100755 SparkleShare/Mac/SparkleBadger.cs diff --git a/SparkleShare/Common/Plugins/bitbucket.xml b/SparkleShare/Common/Plugins/bitbucket.xml index b3eba9ef..17374488 100644 --- a/SparkleShare/Common/Plugins/bitbucket.xml +++ b/SparkleShare/Common/Plugins/bitbucket.xml @@ -19,4 +19,3 @@ - diff --git a/SparkleShare/Common/Plugins/github.xml b/SparkleShare/Common/Plugins/github.xml index d5756b31..44751268 100644 --- a/SparkleShare/Common/Plugins/github.xml +++ b/SparkleShare/Common/Plugins/github.xml @@ -18,4 +18,3 @@ - diff --git a/SparkleShare/Common/Plugins/gitorious.xml b/SparkleShare/Common/Plugins/gitorious.xml index 43c1388f..d0cee9ed 100644 --- a/SparkleShare/Common/Plugins/gitorious.xml +++ b/SparkleShare/Common/Plugins/gitorious.xml @@ -18,4 +18,3 @@ - diff --git a/SparkleShare/Common/Plugins/own-server.xml b/SparkleShare/Common/Plugins/own-server.xml index c8f3d04e..eb9b401a 100644 --- a/SparkleShare/Common/Plugins/own-server.xml +++ b/SparkleShare/Common/Plugins/own-server.xml @@ -17,4 +17,3 @@ - diff --git a/SparkleShare/Common/Plugins/ssnet.xml b/SparkleShare/Common/Plugins/ssnet.xml index 9b1dcac4..718e6f3c 100644 --- a/SparkleShare/Common/Plugins/ssnet.xml +++ b/SparkleShare/Common/Plugins/ssnet.xml @@ -17,4 +17,3 @@ - diff --git a/SparkleShare/Mac/SparkleBadger.cs b/SparkleShare/Mac/SparkleBadger.cs deleted file mode 100755 index a306a144..00000000 --- a/SparkleShare/Mac/SparkleBadger.cs +++ /dev/null @@ -1,90 +0,0 @@ -// SparkleShare, a collaboration and sharing tool. -// Copyright (C) 2010 Hylke Bons -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - - -using System; -using System.Drawing; -using System.IO; -using System.Collections.Generic; - -using MonoMac.AppKit; -using MonoMac.Foundation; - -namespace SparkleShare { - - public class SparkleBadger { - - private Dictionary icons = new Dictionary (); - private int [] sizes = new int [] {16, 32, 48, 128, 256, 512}; - private string [] paths; - - - public SparkleBadger (string [] paths) - { - this.paths = paths; - } - - - public void Badge () - { - using (NSAutoreleasePool a = new NSAutoreleasePool ()) { - foreach (string path in this.paths) { - string extension = Path.GetExtension (path.ToLower ()); - NSImage new_icon = new NSImage (); - - if (!this.icons.ContainsKey (extension)) { - foreach (int size in this.sizes) { - NSImage file_icon = NSWorkspace.SharedWorkspace.IconForFileType (extension); - file_icon.Size = new SizeF (size, size); - - // TODO: replace this with the sync icon - NSImage overlay_icon = NSWorkspace.SharedWorkspace.IconForFileType ("sln"); - overlay_icon.Size = new SizeF (size / 2, size / 2); - - file_icon.LockFocus (); - NSGraphicsContext.CurrentContext.ImageInterpolation = NSImageInterpolation.High; - overlay_icon.Draw ( - new RectangleF (0, 0, file_icon.Size.Width / 3, file_icon.Size.Width / 3), - new RectangleF (), NSCompositingOperation.SourceOver, 1.0f); - file_icon.UnlockFocus (); - - new_icon.AddRepresentation (file_icon.Representations () [0]); - } - - - this.icons.Add (extension, new_icon); - - } else { - new_icon = this.icons [extension]; - } - - NSWorkspace.SharedWorkspace.SetIconforFile (new_icon, path, 0); - } - } - } - - - public void Clear () - { - foreach (string path in this.paths) { - string extension = Path.GetExtension (path.ToLower ()); - - NSImage original_icon = NSWorkspace.SharedWorkspace.IconForFileType (extension); - NSWorkspace.SharedWorkspace.SetIconforFile (original_icon, path, 0); - } - } - } -} diff --git a/SparkleShare/Mac/SparkleShare.csproj b/SparkleShare/Mac/SparkleShare.csproj index b13d76aa..33a6eef5 100644 --- a/SparkleShare/Mac/SparkleShare.csproj +++ b/SparkleShare/Mac/SparkleShare.csproj @@ -71,7 +71,6 @@ - From 8948837a597dca726ea1e82a31b00defe59359b6 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 20 Nov 2012 20:33:02 +0000 Subject: [PATCH 06/14] repo git: fix getting stuck in conflict resolution loop when there are no conflicts --- SparkleLib/Git/SparkleRepoGit.cs | 19 +++++++++---------- SparkleShare/Windows/SparkleController.cs | 10 ++++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index d50afc6b..00fc6f76 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -49,14 +49,12 @@ namespace SparkleLib.Git { if (string.IsNullOrEmpty (this.cached_branch)) { string rebase_apply_path = new string [] { LocalPath, ".git", "rebase-apply" }.Combine (); - if (Directory.Exists (rebase_apply_path)) { - while (HasLocalChanges) { - try { - ResolveConflict (); - - } catch (IOException e) { - SparkleLogger.LogInfo ("Git", Name + " | Failed to resolve conflict, trying again... (" + e.Message + ")"); - } + while (Directory.Exists (rebase_apply_path) && HasLocalChanges) { + try { + ResolveConflict (); + + } catch (IOException e) { + SparkleLogger.LogInfo ("Git", Name + " | Failed to resolve conflict, trying again... (" + e.Message + ")"); } } @@ -477,8 +475,9 @@ namespace SparkleLib.Git { } SparkleLogger.LogInfo ("Git", Name + " | Conflict detected, trying to get out..."); - - while (HasLocalChanges) { + string rebase_apply_path = new string [] { LocalPath, ".git", "rebase-apply" }.Combine (); + + while (Directory.Exists (rebase_apply_path) && HasLocalChanges) { try { ResolveConflict (); diff --git a/SparkleShare/Windows/SparkleController.cs b/SparkleShare/Windows/SparkleController.cs index 1483ce43..b3ec49bb 100644 --- a/SparkleShare/Windows/SparkleController.cs +++ b/SparkleShare/Windows/SparkleController.cs @@ -199,7 +199,7 @@ namespace SparkleShare { if (!string.IsNullOrEmpty (auth_agent_pid)) { SparkleLogger.LogInfo ("Controller", "Trying to use existing ssh-agent with PID=" + auth_agent_pid + "..."); - this.ssh_agent_pid = Convert.ToInt32(auth_agent_pid); + this.ssh_agent_pid = Convert.ToInt32 (auth_agent_pid); try { Process ssh_agent = Process.GetProcessById (this.ssh_agent_pid); @@ -230,12 +230,10 @@ namespace SparkleShare { Environment.SetEnvironmentVariable ("SSH_AUTH_SOCK", auth_sock_match.Groups [1].Value); if (ssh_pid_match.Success) { - string ssh_pid = ssh_pid_match.Groups [1].Value; + Int32.TryParse (ssh_pid_match.Groups [1].Value, out this.ssh_agent_pid); + Environment.SetEnvironmentVariable ("SSH_AGENT_PID", this.ssh_agent_pid); - Int32.TryParse (ssh_pid, out this.ssh_agent_pid); - Environment.SetEnvironmentVariable ("SSH_AGENT_PID", ssh_pid); - - SparkleLogger.LogInfo ("Controller", "ssh-agent started, PID=" + ssh_pid); + SparkleLogger.LogInfo ("Controller", "ssh-agent started, PID=" + this.ssh_agent_pid); } else { SparkleLogger.LogInfo ("Controller", "ssh-agent started, PID=Unknown"); From 29d92c2e8eb64e580ede5744214a8d6d252f9aa6 Mon Sep 17 00:00:00 2001 From: Nicolas Raoul Date: Wed, 21 Nov 2012 12:55:08 +0900 Subject: [PATCH 07/14] Won't build if pkgconfig is not installed --- SparkleShare/Mac/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SparkleShare/Mac/README.md b/SparkleShare/Mac/README.md index 5e77e778..bcc411a3 100644 --- a/SparkleShare/Mac/README.md +++ b/SparkleShare/Mac/README.md @@ -19,10 +19,10 @@ $ export PKG_CONFIG=/Library/Frameworks/Mono.framework/Versions/Current/bin/pkg- $ export PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig ``` -Install git, automake, libtool and intltool using MacPorts: +Install git, automake, libtool, pkgconfig and intltool using MacPorts: ```bash -$ sudo port install git-core automake intltool libtool +$ sudo port install git-core automake intltool pkgconfig libtool ``` Get a Git install, and place both the `bin` and `libexec` directories in `SparkleShare/Mac/git`. From cd6f69ef43f47dd677993cc5f549a65a9ebc5585 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 21 Nov 2012 09:22:29 +0000 Subject: [PATCH 08/14] repo git: don't try to resolve conflicts when a rebase failed due to locked files --- SparkleLib/Git/SparkleRepoGit.cs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 00fc6f76..3facc7c2 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -472,22 +472,23 @@ namespace SparkleLib.Git { git.StartAndWaitForExit (); return false; - } - - SparkleLogger.LogInfo ("Git", Name + " | Conflict detected, trying to get out..."); - string rebase_apply_path = new string [] { LocalPath, ".git", "rebase-apply" }.Combine (); - while (Directory.Exists (rebase_apply_path) && HasLocalChanges) { - try { - ResolveConflict (); + } else { + SparkleLogger.LogInfo ("Git", Name + " | Conflict detected, trying to get out..."); + string rebase_apply_path = new string [] { LocalPath, ".git", "rebase-apply" }.Combine (); + + while (Directory.Exists (rebase_apply_path) && HasLocalChanges) { + try { + ResolveConflict (); - } catch (IOException e) { - SparkleLogger.LogInfo ("Git", Name + " | Failed to resolve conflict, trying again... (" + e.Message + ")"); + } catch (IOException e) { + SparkleLogger.LogInfo ("Git", Name + " | Failed to resolve conflict, trying again... (" + e.Message + ")"); + } } - } - SparkleLogger.LogInfo ("Git", Name + " | Conflict resolved"); - OnConflictResolved (); + SparkleLogger.LogInfo ("Git", Name + " | Conflict resolved"); + OnConflictResolved (); + } } git = new SparkleGit (LocalPath, "config core.ignorecase false"); From f3e17e66f725cfa03a9ba29a9c53e8fc7b3ba871 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 21 Nov 2012 09:33:47 +0000 Subject: [PATCH 09/14] windows: add debug rule for #1037 --- SparkleShare/Windows/SparkleController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SparkleShare/Windows/SparkleController.cs b/SparkleShare/Windows/SparkleController.cs index b3ec49bb..c9b59f95 100644 --- a/SparkleShare/Windows/SparkleController.cs +++ b/SparkleShare/Windows/SparkleController.cs @@ -236,7 +236,7 @@ namespace SparkleShare { SparkleLogger.LogInfo ("Controller", "ssh-agent started, PID=" + this.ssh_agent_pid); } else { - SparkleLogger.LogInfo ("Controller", "ssh-agent started, PID=Unknown"); + SparkleLogger.LogInfo ("Controller", "Could not start ssh-agent:" + output); } } From 804b390eba37f856a2c1bc15d081d4f269884b54 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 21 Nov 2012 23:08:32 +0000 Subject: [PATCH 10/14] repo git: fix parsing of changed host key error. #1078 --- SparkleLib/Git/SparkleRepoGit.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 3facc7c2..bcb17fa2 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -667,8 +667,8 @@ namespace SparkleLib.Git { { Error = ErrorStatus.None; - if (line.StartsWith ("WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!") || - line.StartsWith ("WARNING: POSSIBLE DNS SPOOFING DETECTED!")) { + if (line.Contains ("WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!") || + line.Contains ("WARNING: POSSIBLE DNS SPOOFING DETECTED!")) { Error = ErrorStatus.HostIdentityChanged; From 6dbad640d61dd8cbb35b75755170c43b3d86ebe5 Mon Sep 17 00:00:00 2001 From: Nicolas Raoul Date: Thu, 22 Nov 2012 15:03:53 +0900 Subject: [PATCH 11/14] build MonoMac.dll if needed --- SparkleShare/Mac/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SparkleShare/Mac/README.md b/SparkleShare/Mac/README.md index bcc411a3..854803a1 100644 --- a/SparkleShare/Mac/README.md +++ b/SparkleShare/Mac/README.md @@ -43,6 +43,16 @@ $ ./autogen.sh Now that you have compiled the libraries, open `SparkleShare/Mac/SparkleShare.sln` in MonoDevelop and start the build (Build > Build All). +If you get `Are you missing a using directive or an assembly reference?` errors related to MacOS objects, then run: + +``` +git clone https://github.com/mono/monomac +git clone https://github.com/mono/maccore +cd monomac +make +``` + +It should generate `MonoMac.dll`. Copy it over any `MonoMac.dll` you might have on your system, then restart Monodevelop, and the project should now build fine. ### Creating a Mac bundle From a5ea281c04c97df10cd934425aff2cc06884924d Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 22 Nov 2012 09:45:52 +0000 Subject: [PATCH 12/14] fetcher git: simplify --- SparkleLib/Git/SparkleFetcherGit.cs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/SparkleLib/Git/SparkleFetcherGit.cs b/SparkleLib/Git/SparkleFetcherGit.cs index c9d242f7..4cf2ddeb 100755 --- a/SparkleLib/Git/SparkleFetcherGit.cs +++ b/SparkleLib/Git/SparkleFetcherGit.cs @@ -211,14 +211,7 @@ namespace SparkleLib.Git { public override bool IsFetchedRepoEmpty { get { SparkleGit git = new SparkleGit (TargetFolder, "rev-parse HEAD"); - git.StartInfo.RedirectStandardError = true; - git.Start (); - - // Reading the standard output HAS to go before - // WaitForExit, or it will hang forever on output > 4096 bytes - git.StandardOutput.ReadToEnd (); - git.StandardError.ReadToEnd (); - git.WaitForExit (); + git.StartAndWaitForExit (); return (git.ExitCode != 0); } @@ -257,17 +250,12 @@ namespace SparkleLib.Git { if (!File.Exists (password_check_file_path)) { SparkleGit git = new SparkleGit (TargetFolder, "show HEAD:.sparkleshare"); - git.Start (); + string output = git.StartAndReadStandardOutput (); - // Reading the standard output HAS to go before - // WaitForExit, or it will hang forever on output > 4096 bytes - string output = git.StandardOutput.ReadToEnd (); - git.WaitForExit (); - - if (git.ExitCode != 0) - return false; - else + if (git.ExitCode == 0) File.WriteAllText (password_check_file_path, output); + else + return false; } Process process = new Process () { From 3b51e0b3153224c7f9b3822c5ab564385151eade Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 22 Nov 2012 12:19:37 +0000 Subject: [PATCH 13/14] mac statusicon: put noise in submenu --- SparkleShare/Mac/SparkleStatusIcon.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index a003ef55..d09ca146 100755 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -30,6 +30,7 @@ namespace SparkleShare { public SparkleStatusIconController Controller = new SparkleStatusIconController (); private NSMenu menu; + private NSMenu submenu; private NSStatusItem status_item = NSStatusBar.SystemStatusBar.CreateStatusItem (28); private NSMenuItem state_item; @@ -207,6 +208,15 @@ namespace SparkleShare { this.menu.AddItem (NSMenuItem.SeparatorItem); this.menu.AddItem (this.folder_item); + this.submenu = new NSMenu (); + + this.submenu.AddItem (this.recent_events_item); + this.submenu.AddItem (this.add_item); + this.submenu.AddItem (NSMenuItem.SeparatorItem); + this.submenu.AddItem (this.about_item); + + this.folder_item.Submenu = this.submenu; + this.folder_menu_items = new NSMenuItem [Controller.Folders.Length]; this.error_menu_items = new NSMenuItem [Controller.Folders.Length]; this.try_again_menu_items = new NSMenuItem [Controller.Folders.Length]; @@ -252,13 +262,7 @@ namespace SparkleShare { foreach (NSMenuItem item in this.folder_menu_items) this.menu.AddItem (item); - this.menu.AddItem (NSMenuItem.SeparatorItem); - this.menu.AddItem (this.recent_events_item); - this.menu.AddItem (this.add_item); - this.menu.AddItem (NSMenuItem.SeparatorItem); - this.menu.AddItem (this.about_item); - this.menu.AddItem (NSMenuItem.SeparatorItem); this.menu.AddItem (this.quit_item); this.menu.Delegate = new SparkleStatusIconMenuDelegate (); From 0c3905e58a3d41c74af026a0785f8353daa67e42 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 22 Nov 2012 12:31:48 +0000 Subject: [PATCH 14/14] fetcher: log exceptions more cleanly --- SparkleLib/Git/SparkleFetcherGit.cs | 2 +- SparkleLib/Git/SparkleRepoGit.cs | 14 +++----------- SparkleLib/SparkleExtensions.cs | 2 +- SparkleLib/SparkleFetcherBase.cs | 29 +++++++++++------------------ SparkleLib/SparkleLogger.cs | 9 +++++++++ SparkleShare/Mac/SparkleUI.cs | 2 +- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/SparkleLib/Git/SparkleFetcherGit.cs b/SparkleLib/Git/SparkleFetcherGit.cs index 4cf2ddeb..4ab3b6ea 100755 --- a/SparkleLib/Git/SparkleFetcherGit.cs +++ b/SparkleLib/Git/SparkleFetcherGit.cs @@ -294,7 +294,7 @@ namespace SparkleLib.Git { } } catch (Exception e) { - SparkleLogger.LogInfo ("Fetcher", "Failed to dispose properly: " + e.Message); + SparkleLogger.LogInfo ("Fetcher", "Failed to dispose properly", e); } } diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index bcb17fa2..75c84366 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -411,8 +411,6 @@ namespace SparkleLib.Git { { SparkleGit git = new SparkleGit (LocalPath, "add --all"); git.StartAndWaitForExit (); - - SparkleLogger.LogInfo ("Git", Name + " | Changes staged"); } @@ -533,9 +531,7 @@ namespace SparkleLib.Git { SparkleLogger.LogInfo ("Git", Name + " | Conflict type: " + line); // Ignore conflicts in the .sparkleshare file and use the local version - if (conflicting_path.EndsWith (".sparkleshare") || - conflicting_path.EndsWith (".empty")) { - + if (conflicting_path.EndsWith (".sparkleshare") || conflicting_path.EndsWith (".empty")) { // Recover local version SparkleGit git_theirs = new SparkleGit (LocalPath, "checkout --theirs \"" + conflicting_path + "\""); git_theirs.StartAndWaitForExit (); @@ -574,12 +570,8 @@ namespace SparkleLib.Git { // The local version has been modified, but the server version was removed } else if (line.StartsWith ("DU")) { - - // The modified local version is already in the - // checkout, so it just needs to be added. - // - // We need to specifically mention the file, so - // we can't reuse the Add () method + // The modified local version is already in the checkout, so it just needs to be added. + // We need to specifically mention the file, so we can't reuse the Add () method SparkleGit git_add = new SparkleGit (LocalPath, "add \"" + conflicting_path + "\""); git_add.StartAndWaitForExit (); diff --git a/SparkleLib/SparkleExtensions.cs b/SparkleLib/SparkleExtensions.cs index a5164288..fb39aa75 100755 --- a/SparkleLib/SparkleExtensions.cs +++ b/SparkleLib/SparkleExtensions.cs @@ -68,7 +68,7 @@ namespace SparkleLib { else if (byte_count >= 1024) return String.Format ("{0:##.##} ᴋʙ", Math.Round (byte_count / 1024, 0)); else - return byte_count.ToString () + " bytes"; + return byte_count.ToString () + " ʙ"; } } } diff --git a/SparkleLib/SparkleFetcherBase.cs b/SparkleLib/SparkleFetcherBase.cs index 5df9b736..173b8b85 100755 --- a/SparkleLib/SparkleFetcherBase.cs +++ b/SparkleLib/SparkleFetcherBase.cs @@ -162,8 +162,8 @@ namespace SparkleLib { IsActive = false; - bool repo_is_encrypted = - (RemoteUrl.AbsolutePath.Contains ("-crypto") || RemoteUrl.Host.Equals ("sparkleshare.net")); + bool repo_is_encrypted = (RemoteUrl.AbsolutePath.Contains ("-crypto") || + RemoteUrl.Host.Equals ("sparkleshare.net")); Finished (repo_is_encrypted, IsFetchedRepoEmpty, Warnings); @@ -257,29 +257,22 @@ namespace SparkleLib { private string FetchHostKey () { - string host = RemoteUrl.Host; - int port = RemoteUrl.Port; - - if (port < 1) - port = 22; - - SparkleLogger.LogInfo ("Auth", "Fetching host key for " + host); - - Process process = new Process () { - EnableRaisingEvents = true - }; + SparkleLogger.LogInfo ("Auth", "Fetching host key for " + RemoteUrl.Host); + Process process = new Process (); process.StartInfo.FileName = "ssh-keyscan"; - process.StartInfo.Arguments = "-t rsa -p " + port + " " + host; process.StartInfo.WorkingDirectory = SparkleConfig.DefaultConfig.TmpPath; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.CreateNoWindow = true; + process.EnableRaisingEvents = true; + + if (RemoteUrl.Port < 1) + process.StartInfo.Arguments = "-t rsa -p 22 " + RemoteUrl.Host; + else + process.StartInfo.Arguments = "-t rsa -p " + RemoteUrl.Port + " " + RemoteUrl.Host; process.Start (); - - // Reading the standard output HAS to go before - // WaitForExit, or it will hang forever on output > 4096 bytes string host_key = process.StandardOutput.ReadToEnd ().Trim (); process.WaitForExit (); @@ -302,7 +295,7 @@ namespace SparkleLib { return fingerprint.ToLower ().Replace ("-", ":"); } catch (Exception e) { - SparkleLogger.LogInfo ("Fetcher", "Failed creating fingerprint: " + e.Message + e.StackTrace); + SparkleLogger.LogInfo ("Fetcher", "Failed creating fingerprint: " + e.Message + " " + e.StackTrace); return null; } } diff --git a/SparkleLib/SparkleLogger.cs b/SparkleLib/SparkleLogger.cs index 6e3bff18..68889ede 100755 --- a/SparkleLib/SparkleLogger.cs +++ b/SparkleLib/SparkleLogger.cs @@ -26,10 +26,19 @@ namespace SparkleLib { private static int log_size = 0; public static void LogInfo (string type, string message) + { + LogInfo (type, message, null); + } + + + public static void LogInfo (string type, string message, Exception exception) { string timestamp = DateTime.Now.ToString ("HH:mm:ss"); string line = timestamp + " | " + type + " | " + message; + if (exception != null) + line += ": " + exception.Message + " " + exception.StackTrace; + if (SparkleConfig.DebugMode) Console.WriteLine (line); diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index d8739f30..97d75be6 100755 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -77,7 +77,7 @@ namespace SparkleShare { private void HideDockIcon () { - // Currently not supported, here for completeness sake (see Apple's docs) + // Currently not supported by Apple's API // NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.None; }