This commit is contained in:
Hylke Bons 2012-11-22 12:33:54 +00:00
commit 6296a78b26
24 changed files with 306 additions and 471 deletions

View file

@ -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 () {
@ -306,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);
}
}

View file

@ -34,19 +34,27 @@ 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)) {
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 + ")");
}
}
@ -224,11 +232,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 +252,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 +314,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 +334,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;
@ -409,8 +411,6 @@ namespace SparkleLib.Git {
{
SparkleGit git = new SparkleGit (LocalPath, "add --all");
git.StartAndWaitForExit ();
SparkleLogger.LogInfo ("Git", Name + " | Changes staged");
}
@ -470,21 +470,23 @@ namespace SparkleLib.Git {
git.StartAndWaitForExit ();
return false;
}
} 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 ();
SparkleLogger.LogInfo ("Git", Name + " | Conflict detected, trying to get out...");
while (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");
@ -529,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 ();
@ -570,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 ();
@ -663,8 +659,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;
@ -732,15 +728,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 ();

View file

@ -6,7 +6,6 @@ ASSEMBLY_INFO_SOURCE = Defines.cs
SOURCES = \
SparkleBackend.cs \
SparkleConfig.cs \
SparkleExceptions.cs \
SparkleExtensions.cs \
SparkleFetcherBase.cs \
SparkleListenerBase.cs \

View file

@ -1,37 +0,0 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
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;
}
}
}

View file

@ -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 () + " ʙ";
}
}
}

View file

@ -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;
}
}

View file

@ -13,15 +13,15 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<Optimize>False</Optimize>
<OutputPath>..\bin</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<ConsolePause>False</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -40,17 +40,15 @@
<Compile Include="SparkleConfig.cs" />
<Compile Include="SparkleWatcher.cs" />
<Compile Include="SparkleExtensions.cs" />
<Compile Include="SparkleExceptions.cs" />
<Compile Include="SparkleUser.cs" />
<Compile Include="SparkleLogger.cs" />
<Compile Include="Defines.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="true" RelativeMakefileName="Makefile.am">
<BuildFilesVar Sync="true" Name="SOURCES" />
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am">
<BuildFilesVar Sync="True" Name="SOURCES" />
<DeployFilesVar />
<ResourcesVar />
<OthersVar />

View file

@ -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);

View file

@ -19,4 +19,3 @@
</path>
</plugin>
</sparkleshare>

View file

@ -18,4 +18,3 @@
</path>
</plugin>
</sparkleshare>

View file

@ -18,4 +18,3 @@
</path>
</plugin>
</sparkleshare>

View file

@ -17,4 +17,3 @@
</path>
</plugin>
</sparkleshare>

View file

@ -17,4 +17,3 @@
</path>
</plugin>
</sparkleshare>

View file

@ -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 <tt>git</tt>, <tt>automake</tt>, <tt>libtool</tt> and <tt>intltool</tt> using <tt>MacPorts</tt>:
Install <tt>git</tt>, <tt>automake</tt>, <tt>libtool</tt>, <tt>pkgconfig</tt> and <tt>intltool</tt> using <tt>MacPorts</tt>:
```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`.
@ -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

View file

@ -22,7 +22,6 @@ using System.IO;
using MonoMac.AppKit;
using MonoMac.Foundation;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit;
namespace SparkleShare {

View file

@ -1,90 +0,0 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
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<string, NSImage> icons = new Dictionary<string, NSImage> ();
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);
}
}
}
}

View file

@ -23,7 +23,6 @@ using System.IO;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit;
namespace SparkleShare {

View file

@ -71,7 +71,6 @@
</Compile>
<Compile Include="SparkleMacWatcher.cs" />
<Compile Include="SparkleEventLog.cs" />
<Compile Include="SparkleBadger.cs" />
<Compile Include="SparkleBubbles.cs" />
<Compile Include="SparkleSetup.cs" />
<Compile Include="SparkleSetupWindow.cs" />

View file

@ -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 ();

View file

@ -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;
}

View file

@ -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<SparkleRepoBase> repositories = new List<SparkleRepoBase> ();
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<string> skipped_avatars = new List<string> ();
private List<SparkleRepoBase> repositories = new List<SparkleRepoBase> ();
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 ClearFolderAttributes (string path)
{
if (!Directory.Exists (path))
return;
string [] folders = Directory.GetDirectories (path);
foreach (string folder in folders)
ClearFolderAttributes (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);
@ -652,13 +663,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);
@ -678,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<string> skipped_avatars = new List<string> ();
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 ();
@ -781,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)) {
@ -803,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);
}
}
}

View file

@ -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) {

View file

@ -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;
}
}
}
}

View file

@ -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,15 +230,13 @@ 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");
SparkleLogger.LogInfo ("Controller", "Could not start ssh-agent:" + output);
}
}