Remove Helpers class, add Logger class
This commit is contained in:
parent
138db2c41b
commit
c9e4218358
|
@ -120,7 +120,7 @@ namespace SparkleLib.Git {
|
|||
number = (number / 100 * 20); // "Compressing objects" stage
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("Fetcher", line);
|
||||
SparkleLogger.LogInfo ("Fetcher", line);
|
||||
line = line.Trim (new char [] {' ', '@'});
|
||||
|
||||
if (line.StartsWith ("fatal:", StringComparison.InvariantCultureIgnoreCase) ||
|
||||
|
@ -195,7 +195,7 @@ namespace SparkleLib.Git {
|
|||
public override void EnableFetchedRepoCrypto (string password)
|
||||
{
|
||||
// Define the crypto filter in the config
|
||||
string repo_config_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "config");
|
||||
string repo_config_file_path = new string [] { TargetFolder, ".git", "config" }.Combine ();
|
||||
string config = File.ReadAllText (repo_config_file_path);
|
||||
|
||||
string n = Environment.NewLine;
|
||||
|
@ -207,11 +207,11 @@ namespace SparkleLib.Git {
|
|||
File.WriteAllText (repo_config_file_path, config);
|
||||
|
||||
// Pass all files through the crypto filter
|
||||
string git_attributes_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "info", "attributes");
|
||||
string git_attributes_file_path = new string [] { TargetFolder, ".git", "info", "attributes" }.Combine ();
|
||||
File.AppendAllText (git_attributes_file_path, "\n* filter=crypto");
|
||||
|
||||
// Store the password
|
||||
string password_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "password");
|
||||
string password_file_path = new string [] { TargetFolder, ".git", "password" }.Combine ();
|
||||
File.WriteAllText (password_file_path, password.Trim ());
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ namespace SparkleLib.Git {
|
|||
this.git.Dispose ();
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Fetcher", "Failed to dispose properly: " + e.Message);
|
||||
SparkleLogger.LogInfo ("Fetcher", "Failed to dispose properly: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ namespace SparkleLib.Git {
|
|||
private void InstallExcludeRules ()
|
||||
{
|
||||
string exclude_rules = string.Join (Environment.NewLine, ExcludeRules);
|
||||
string exclude_rules_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "info", "exclude");
|
||||
string exclude_rules_file_path = new string [] { TargetFolder, ".git", "info", "exclude" }.Combine ();
|
||||
|
||||
File.WriteAllText (exclude_rules_file_path, exclude_rules);
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ namespace SparkleLib.Git {
|
|||
|
||||
private void InstallAttributeRules ()
|
||||
{
|
||||
string attribute_rules_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "info", "attributes");
|
||||
string attribute_rules_file_path = new string [] { TargetFolder, ".git", "info", "attributes" }.Combine ();
|
||||
TextWriter writer = new StreamWriter (attribute_rules_file_path);
|
||||
|
||||
if (this.use_git_bin) {
|
||||
|
|
|
@ -33,14 +33,14 @@ namespace SparkleLib.Git {
|
|||
|
||||
new public void Start ()
|
||||
{
|
||||
SparkleHelpers.DebugInfo ("Cmd | " + System.IO.Path.GetFileName (StartInfo.WorkingDirectory),
|
||||
SparkleLogger.LogInfo ("Cmd | " + System.IO.Path.GetFileName (StartInfo.WorkingDirectory),
|
||||
System.IO.Path.GetFileName (StartInfo.FileName) + " " + StartInfo.Arguments);
|
||||
|
||||
try {
|
||||
base.Start ();
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Cmd", "Couldn't execute command: " + e.Message);
|
||||
SparkleLogger.LogInfo ("Cmd", "Couldn't execute command: " + e.Message);
|
||||
Environment.Exit (-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace SparkleLib.Git {
|
|||
|
||||
this.use_git_bin = (git.ExitCode == 0);
|
||||
|
||||
string rebase_apply_path = SparkleHelpers.CombineMore (LocalPath, ".git", "rebase-apply");
|
||||
string rebase_apply_path = new string [] { LocalPath, ".git", "rebase-apply" }.Combine ();
|
||||
|
||||
if (Directory.Exists (rebase_apply_path)) {
|
||||
git = new SparkleGit (LocalPath, "rebase --abort");
|
||||
|
@ -141,7 +141,7 @@ namespace SparkleLib.Git {
|
|||
|
||||
public override bool HasRemoteChanges {
|
||||
get {
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | Checking for remote changes...");
|
||||
SparkleLogger.LogInfo ("Git", Name + " | Checking for remote changes...");
|
||||
string current_revision = CurrentRevision;
|
||||
|
||||
SparkleGit git = new SparkleGit (LocalPath, "ls-remote --heads --exit-code \"" + RemoteUrl + "\" master");
|
||||
|
@ -153,13 +153,13 @@ namespace SparkleLib.Git {
|
|||
string remote_revision = output.Substring (0, 40);
|
||||
|
||||
if (!remote_revision.StartsWith (current_revision)) {
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | Remote changes found, local: " +
|
||||
SparkleLogger.LogInfo ("Git", Name + " | Remote changes found, local: " +
|
||||
current_revision + ", remote: " + remote_revision);
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | No remote changes, local+remote: " + current_revision);
|
||||
SparkleLogger.LogInfo ("Git", Name + " | No remote changes, local+remote: " + current_revision);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ namespace SparkleLib.Git {
|
|||
}
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | " + line);
|
||||
SparkleLogger.LogInfo ("Git", Name + " | " + line);
|
||||
}
|
||||
|
||||
if (number >= percentage) {
|
||||
|
@ -298,7 +298,7 @@ namespace SparkleLib.Git {
|
|||
}
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | " + line);
|
||||
SparkleLogger.LogInfo ("Git", Name + " | " + line);
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,12 +341,12 @@ namespace SparkleLib.Git {
|
|||
|
||||
public override bool HasUnsyncedChanges {
|
||||
get {
|
||||
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath, ".git", "has_unsynced_changes");
|
||||
string unsynced_file_path = new string [] { LocalPath, ".git", "has_unsynced_changes" }.Combine ();
|
||||
return File.Exists (unsynced_file_path);
|
||||
}
|
||||
|
||||
set {
|
||||
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath, ".git", "has_unsynced_changes");
|
||||
string unsynced_file_path = new string [] { LocalPath, ".git", "has_unsynced_changes" }.Combine ();
|
||||
|
||||
if (value)
|
||||
File.WriteAllText (unsynced_file_path, "");
|
||||
|
@ -362,7 +362,7 @@ namespace SparkleLib.Git {
|
|||
SparkleGit git = new SparkleGit (LocalPath, "add --all");
|
||||
git.StartAndWaitForExit ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | Changes staged");
|
||||
SparkleLogger.LogInfo ("Git", Name + " | Changes staged");
|
||||
}
|
||||
|
||||
|
||||
|
@ -403,19 +403,19 @@ namespace SparkleLib.Git {
|
|||
git.StartAndWaitForExit ();
|
||||
|
||||
if (git.ExitCode != 0) {
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | Conflict detected, trying to get out...");
|
||||
SparkleLogger.LogInfo ("Git", Name + " | Conflict detected, trying to get out...");
|
||||
|
||||
while (HasLocalChanges) {
|
||||
try {
|
||||
ResolveConflict ();
|
||||
|
||||
} catch (IOException e) {
|
||||
SparkleHelpers.DebugInfo ("Git",
|
||||
SparkleLogger.LogInfo ("Git",
|
||||
Name + " | Failed to resolve conflict, trying again... (" + e.Message + ")");
|
||||
}
|
||||
}
|
||||
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | Conflict resolved");
|
||||
SparkleLogger.LogInfo ("Git", Name + " | Conflict resolved");
|
||||
OnConflictResolved ();
|
||||
}
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ namespace SparkleLib.Git {
|
|||
string conflicting_path = line.Substring (3);
|
||||
conflicting_path = EnsureSpecialCharacters (conflicting_path);
|
||||
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | Conflict type: " + line);
|
||||
SparkleLogger.LogInfo ("Git", Name + " | Conflict type: " + line);
|
||||
|
||||
// Ignore conflicts in the .sparkleshare file and use the local version
|
||||
if (conflicting_path.EndsWith (".sparkleshare") ||
|
||||
|
@ -747,7 +747,7 @@ namespace SparkleLib.Git {
|
|||
{
|
||||
try {
|
||||
foreach (string child_path in Directory.GetDirectories (path)) {
|
||||
if (SparkleHelpers.IsSymlink (child_path))
|
||||
if (IsSymlink (child_path))
|
||||
continue;
|
||||
|
||||
if (child_path.EndsWith (".git")) {
|
||||
|
@ -758,7 +758,7 @@ namespace SparkleLib.Git {
|
|||
|
||||
if (File.Exists (HEAD_file_path)) {
|
||||
File.Move (HEAD_file_path, HEAD_file_path + ".backup");
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | Renamed " + HEAD_file_path);
|
||||
SparkleLogger.LogInfo ("Git", Name + " | Renamed " + HEAD_file_path);
|
||||
}
|
||||
|
||||
continue;
|
||||
|
@ -777,13 +777,13 @@ namespace SparkleLib.Git {
|
|||
File.SetAttributes (Path.Combine (path, ".empty"), FileAttributes.Hidden);
|
||||
|
||||
} catch {
|
||||
SparkleHelpers.DebugInfo ("Git", Name + " | Failed adding empty folder " + path);
|
||||
SparkleLogger.LogInfo ("Git", Name + " | Failed adding empty folder " + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
SparkleHelpers.DebugInfo ("Git", "Failed preparing directory: " + e.Message);
|
||||
SparkleLogger.LogInfo ("Git", "Failed preparing directory: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -857,7 +857,7 @@ namespace SparkleLib.Git {
|
|||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Local", "Error calculating size: " + e.Message);
|
||||
SparkleLogger.LogInfo ("Local", "Error calculating size: " + e.Message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -867,11 +867,18 @@ namespace SparkleLib.Git {
|
|||
size += CalculateSizes (directory);
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Local", "Error calculating size: " + e.Message);
|
||||
SparkleLogger.LogInfo ("Local", "Error calculating size: " + e.Message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
private bool IsSymlink (string file)
|
||||
{
|
||||
FileAttributes attributes = File.GetAttributes (file);
|
||||
return ((attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,16 @@ TARGET = library
|
|||
ASSEMBLY_INFO_SOURCE = Defines.cs
|
||||
|
||||
SOURCES = \
|
||||
Defines.cs \
|
||||
SparkleAnnouncement.cs \
|
||||
SparkleBackend.cs \
|
||||
SparkleConfig.cs \
|
||||
SparkleExceptions.cs \
|
||||
SparkleExtensions.cs \
|
||||
SparkleFetcherBase.cs \
|
||||
SparkleHelpers.cs \
|
||||
SparkleListenerBase.cs \
|
||||
SparkleListenerFactory.cs \
|
||||
SparkleListenerTcp.cs \
|
||||
SparkleLogger.cs \
|
||||
SparkleRepoBase.cs \
|
||||
SparkleUser.cs \
|
||||
SparkleWatcher.cs \
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace SparkleLib {
|
|||
if (GetConfigOption ("home_path") != null)
|
||||
return GetConfigOption ("home_path");
|
||||
|
||||
if (SparkleHelpers.IsWindows)
|
||||
if (SparkleBackend.Platform == PlatformID.Win32NT)
|
||||
return Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
|
||||
else
|
||||
return Environment.GetFolderPath (Environment.SpecialFolder.Personal);
|
||||
|
@ -139,9 +139,7 @@ namespace SparkleLib {
|
|||
string email = email_node.Value;
|
||||
|
||||
string pubkey_file_path = Path.Combine (
|
||||
Path.GetDirectoryName (FullPath),
|
||||
"sparkleshare." + email + ".key.pub"
|
||||
);
|
||||
Path.GetDirectoryName (FullPath), "sparkleshare." + email + ".key.pub");
|
||||
|
||||
SparkleUser user = new SparkleUser (name, email);
|
||||
|
||||
|
@ -179,19 +177,18 @@ namespace SparkleLib {
|
|||
|
||||
public void AddFolder (string name, string identifier, string url, string backend)
|
||||
{
|
||||
XmlNode node_name = CreateElement ("name");
|
||||
node_name.InnerText = name;
|
||||
XmlNode node_name = CreateElement ("name");
|
||||
XmlNode node_identifier = CreateElement ("identifier");
|
||||
XmlNode node_url = CreateElement ("url");
|
||||
XmlNode node_backend = CreateElement ("backend");
|
||||
|
||||
XmlNode node_identifier = CreateElement ("identifier");
|
||||
node_name.InnerText = name;
|
||||
node_identifier.InnerText = identifier;
|
||||
|
||||
XmlNode node_url = CreateElement ("url");
|
||||
node_url.InnerText = url;
|
||||
|
||||
XmlNode node_backend = CreateElement ("backend");
|
||||
node_backend.InnerText = backend;
|
||||
node_url.InnerText = url;
|
||||
node_backend.InnerText = backend;
|
||||
|
||||
XmlNode node_folder = CreateNode (XmlNodeType.Element, "folder", null);
|
||||
|
||||
node_folder.AppendChild (node_name);
|
||||
node_folder.AppendChild (node_identifier);
|
||||
node_folder.AppendChild (node_url);
|
||||
|
@ -217,9 +214,10 @@ namespace SparkleLib {
|
|||
|
||||
public void RenameFolder (string identifier, string name)
|
||||
{
|
||||
XmlNode node_folder = SelectSingleNode (string.Format ("/sparkleshare/folder[identifier=\"{0}\"]", identifier));
|
||||
node_folder ["name"].InnerText = name;
|
||||
XmlNode node_folder = SelectSingleNode (
|
||||
string.Format ("/sparkleshare/folder[identifier=\"{0}\"]", identifier));
|
||||
|
||||
node_folder ["name"].InnerText = name;
|
||||
Save ();
|
||||
}
|
||||
|
||||
|
@ -339,8 +337,8 @@ namespace SparkleLib {
|
|||
node_root.AppendChild (node);
|
||||
}
|
||||
|
||||
SparkleHelpers.DebugInfo ("Config", "Updated option " + name + ":" + content);
|
||||
Save ();
|
||||
SparkleLogger.LogInfo ("Config", "Updated option " + name + ":" + content);
|
||||
}
|
||||
|
||||
|
||||
|
@ -350,7 +348,7 @@ namespace SparkleLib {
|
|||
throw new FileNotFoundException (FullPath + " does not exist");
|
||||
|
||||
Save (FullPath);
|
||||
SparkleHelpers.DebugInfo ("Config", "Wrote to '" + FullPath + "'");
|
||||
SparkleLogger.LogInfo ("Config", "Wrote to '" + FullPath + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,14 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace SparkleLib {
|
||||
|
||||
public static class Extensions {
|
||||
|
||||
public static string Combine (this String [] parts)
|
||||
public static string Combine (this string [] parts)
|
||||
{
|
||||
string new_path = "";
|
||||
|
||||
|
@ -31,5 +33,25 @@ namespace SparkleLib {
|
|||
|
||||
return new_path;
|
||||
}
|
||||
|
||||
|
||||
public static string SHA1 (this string s)
|
||||
{
|
||||
SHA1 sha1 = new SHA1CryptoServiceProvider ();
|
||||
byte [] bytes = ASCIIEncoding.Default.GetBytes (s);
|
||||
byte [] enc_bytes = sha1.ComputeHash (bytes);
|
||||
|
||||
return BitConverter.ToString (enc_bytes).ToLower ().Replace ("-", "");
|
||||
}
|
||||
|
||||
|
||||
public static string MD5 (this string s)
|
||||
{
|
||||
MD5 md5 = new MD5CryptoServiceProvider ();
|
||||
byte [] bytes = ASCIIEncoding.Default.GetBytes (s);
|
||||
byte [] enc_bytes = md5.ComputeHash (bytes);
|
||||
|
||||
return BitConverter.ToString (enc_bytes).ToLower ().Replace ("-", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace SparkleLib {
|
|||
IsActive = true;
|
||||
Started ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("Fetcher", TargetFolder + " | Fetching folder: " + RemoteUrl);
|
||||
SparkleLogger.LogInfo ("Fetcher", TargetFolder + " | Fetching folder: " + RemoteUrl);
|
||||
|
||||
if (Directory.Exists (TargetFolder))
|
||||
Directory.Delete (TargetFolder, true);
|
||||
|
@ -134,7 +134,7 @@ namespace SparkleLib {
|
|||
string host_fingerprint = GetFingerprint (host_key);
|
||||
|
||||
if (host_fingerprint == null || !RequiredFingerprint.Equals (host_fingerprint)) {
|
||||
SparkleHelpers.DebugInfo ("Auth", "Fingerprint doesn't match");
|
||||
SparkleLogger.LogInfo ("Auth", "Fingerprint doesn't match");
|
||||
|
||||
this.errors.Add ("error: Host fingerprint doesn't match");
|
||||
Failed ();
|
||||
|
@ -143,10 +143,10 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
warn = false;
|
||||
SparkleHelpers.DebugInfo ("Auth", "Fingerprint matches");
|
||||
SparkleLogger.LogInfo ("Auth", "Fingerprint matches");
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("Auth", "Skipping fingerprint check");
|
||||
SparkleLogger.LogInfo ("Auth", "Skipping fingerprint check");
|
||||
}
|
||||
|
||||
AcceptHostKey (host_key, warn);
|
||||
|
@ -154,7 +154,7 @@ namespace SparkleLib {
|
|||
this.thread = new Thread (() => {
|
||||
if (Fetch ()) {
|
||||
Thread.Sleep (500);
|
||||
SparkleHelpers.DebugInfo ("Fetcher", "Finished");
|
||||
SparkleLogger.LogInfo ("Fetcher", "Finished");
|
||||
|
||||
IsActive = false;
|
||||
|
||||
|
@ -164,7 +164,7 @@ namespace SparkleLib {
|
|||
|
||||
} else {
|
||||
Thread.Sleep (500);
|
||||
SparkleHelpers.DebugInfo ("Fetcher", "Failed");
|
||||
SparkleLogger.LogInfo ("Fetcher", "Failed");
|
||||
|
||||
IsActive = false;
|
||||
Failed ();
|
||||
|
@ -217,7 +217,7 @@ namespace SparkleLib {
|
|||
public static string CreateIdentifier ()
|
||||
{
|
||||
string random = Path.GetRandomFileName ();
|
||||
return SparkleHelpers.SHA1 (random);
|
||||
return random.SHA1 ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -255,7 +255,7 @@ namespace SparkleLib {
|
|||
private string GetHostKey ()
|
||||
{
|
||||
string host = RemoteUrl.Host;
|
||||
SparkleHelpers.DebugInfo ("Auth", "Fetching host key for " + host);
|
||||
SparkleLogger.LogInfo ("Auth", "Fetching host key for " + host);
|
||||
|
||||
Process process = new Process () {
|
||||
EnableRaisingEvents = true
|
||||
|
@ -312,7 +312,7 @@ namespace SparkleLib {
|
|||
fingerprint = fingerprint.Substring (fingerprint.IndexOf (" ") + 1, 47);
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Fetcher", "Not a valid fingerprint: " + e.Message);
|
||||
SparkleLogger.LogInfo ("Fetcher", "Not a valid fingerprint: " + e.Message);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -346,7 +346,7 @@ namespace SparkleLib {
|
|||
else
|
||||
File.AppendAllText (known_hosts_file_path, "\n" + host_key + "\n");
|
||||
|
||||
SparkleHelpers.DebugInfo ("Auth", "Accepted host key for " + host);
|
||||
SparkleLogger.LogInfo ("Auth", "Accepted host key for " + host);
|
||||
|
||||
if (warn)
|
||||
this.warnings.Add ("The following host key has been accepted:\n" + GetFingerprint (host_key));
|
||||
|
|
|
@ -1,119 +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.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace SparkleLib {
|
||||
|
||||
public static class SparkleHelpers {
|
||||
|
||||
private static Object debug_lock = new Object ();
|
||||
|
||||
// Show debug info if needed
|
||||
public static void DebugInfo (string type, string message)
|
||||
{
|
||||
string timestamp = DateTime.Now.ToString ("HH:mm:ss");
|
||||
string line = timestamp + " | " + type + " | " + message;
|
||||
|
||||
if (SparkleConfig.DebugMode)
|
||||
Console.WriteLine (line);
|
||||
|
||||
lock (debug_lock)
|
||||
File.AppendAllText (SparkleConfig.DefaultConfig.LogFilePath, line + Environment.NewLine);
|
||||
}
|
||||
|
||||
|
||||
// Makes it possible to combine more than
|
||||
// two paths at once
|
||||
public static string CombineMore (params string [] parts)
|
||||
{
|
||||
string new_path = "";
|
||||
|
||||
foreach (string part in parts)
|
||||
new_path = Path.Combine (new_path, part);
|
||||
|
||||
return new_path;
|
||||
}
|
||||
|
||||
|
||||
// Recursively sets access rights of a folder to 'Normal'
|
||||
public static void ClearAttributes (string path)
|
||||
{
|
||||
if (!Directory.Exists (path))
|
||||
return;
|
||||
|
||||
string [] folders = Directory.GetDirectories (path);
|
||||
|
||||
foreach (string folder in folders)
|
||||
ClearAttributes (folder);
|
||||
|
||||
string [] files = Directory.GetFiles(path);
|
||||
|
||||
foreach (string file in files)
|
||||
if (!IsSymlink (file))
|
||||
File.SetAttributes (file, FileAttributes.Normal);
|
||||
}
|
||||
|
||||
|
||||
// Check if a file is a symbolic link
|
||||
public static bool IsSymlink (string file)
|
||||
{
|
||||
FileAttributes attributes = File.GetAttributes (file);
|
||||
return ((attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint);
|
||||
}
|
||||
|
||||
|
||||
// Converts a UNIX timestamp to a more usable time object
|
||||
public static DateTime UnixTimestampToDateTime (int timestamp)
|
||||
{
|
||||
DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0);
|
||||
return unix_epoch.AddSeconds (timestamp);
|
||||
}
|
||||
|
||||
|
||||
public static bool IsWindows {
|
||||
get {
|
||||
return (Environment.OSVersion.Platform == PlatformID.Win32NT ||
|
||||
Environment.OSVersion.Platform == PlatformID.Win32S ||
|
||||
Environment.OSVersion.Platform == PlatformID.Win32Windows);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string SHA1 (string s)
|
||||
{
|
||||
SHA1 sha1 = new SHA1CryptoServiceProvider ();
|
||||
byte [] bytes = ASCIIEncoding.Default.GetBytes (s);
|
||||
byte [] enc_bytes = sha1.ComputeHash (bytes);
|
||||
|
||||
return BitConverter.ToString (enc_bytes).ToLower ().Replace ("-", "");
|
||||
}
|
||||
|
||||
|
||||
public static string MD5 (string s)
|
||||
{
|
||||
MD5 md5 = new MD5CryptoServiceProvider ();
|
||||
byte [] bytes = ASCIIEncoding.Default.GetBytes (s);
|
||||
byte [] enc_bytes = md5.ComputeHash (bytes);
|
||||
|
||||
return BitConverter.ToString (enc_bytes).ToLower ().Replace ("-", "");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
|
@ -37,9 +37,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="SparkleRepoBase.cs" />
|
||||
<Compile Include="SparkleFetcherBase.cs" />
|
||||
<Compile Include="Defines.cs" />
|
||||
<Compile Include="SparkleAnnouncement.cs" />
|
||||
<Compile Include="SparkleHelpers.cs" />
|
||||
<Compile Include="SparkleWrappers.cs" />
|
||||
<Compile Include="SparkleListenerBase.cs" />
|
||||
<Compile Include="SparkleListenerFactory.cs" />
|
||||
|
@ -50,6 +48,7 @@
|
|||
<Compile Include="SparkleExtensions.cs" />
|
||||
<Compile Include="SparkleExceptions.cs" />
|
||||
<Compile Include="SparkleUser.cs" />
|
||||
<Compile Include="SparkleLogger.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
|
|
|
@ -76,19 +76,19 @@ namespace SparkleLib {
|
|||
{
|
||||
if (!IsRecentAnnouncement (announcement)) {
|
||||
if (IsConnected) {
|
||||
SparkleHelpers.DebugInfo ("Listener", "Announcing message " + announcement.Message +
|
||||
SparkleLogger.LogInfo ("Listener", "Announcing message " + announcement.Message +
|
||||
" to " + announcement.FolderIdentifier + " on " + Server);
|
||||
|
||||
AnnounceInternal (announcement);
|
||||
AddRecentAnnouncement (announcement);
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("Listener", "Can't send message to " + Server + ". Queuing message");
|
||||
SparkleLogger.LogInfo ("Listener", "Can't send message to " + Server + ". Queuing message");
|
||||
this.queue_up [announcement.FolderIdentifier] = announcement;
|
||||
}
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("Listener", "Already processed message " + announcement.Message +
|
||||
SparkleLogger.LogInfo ("Listener", "Already processed message " + announcement.Message +
|
||||
" to " + announcement.FolderIdentifier + " from " + Server);
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ namespace SparkleLib {
|
|||
public void AlsoListenTo (string channel)
|
||||
{
|
||||
if (!this.channels.Contains (channel) && IsConnected) {
|
||||
SparkleHelpers.DebugInfo ("Listener", "Subscribing to channel " + channel + " on " + Server);
|
||||
SparkleLogger.LogInfo ("Listener", "Subscribing to channel " + channel + " on " + Server);
|
||||
|
||||
this.channels.Add (channel);
|
||||
AlsoListenToInternal (channel);
|
||||
|
@ -107,18 +107,18 @@ namespace SparkleLib {
|
|||
|
||||
public void Reconnect ()
|
||||
{
|
||||
SparkleHelpers.DebugInfo ("Listener", "Trying to reconnect to " + Server);
|
||||
SparkleLogger.LogInfo ("Listener", "Trying to reconnect to " + Server);
|
||||
Connect ();
|
||||
}
|
||||
|
||||
|
||||
public void OnConnected ()
|
||||
{
|
||||
SparkleHelpers.DebugInfo ("Listener", "Listening for announcements on " + Server);
|
||||
SparkleLogger.LogInfo ("Listener", "Listening for announcements on " + Server);
|
||||
Connected ();
|
||||
|
||||
if (this.queue_up.Count > 0) {
|
||||
SparkleHelpers.DebugInfo ("Listener", "Delivering " + this.queue_up.Count + " queued messages...");
|
||||
SparkleLogger.LogInfo ("Listener", "Delivering " + this.queue_up.Count + " queued messages...");
|
||||
|
||||
foreach (KeyValuePair<string, SparkleAnnouncement> item in this.queue_up) {
|
||||
SparkleAnnouncement announcement = item.Value;
|
||||
|
@ -132,25 +132,25 @@ namespace SparkleLib {
|
|||
|
||||
public void OnDisconnected (string message)
|
||||
{
|
||||
SparkleHelpers.DebugInfo ("Listener", "Disconnected from " + Server + ": " + message);
|
||||
SparkleLogger.LogInfo ("Listener", "Disconnected from " + Server + ": " + message);
|
||||
Disconnected ();
|
||||
}
|
||||
|
||||
|
||||
public void OnAnnouncement (SparkleAnnouncement announcement)
|
||||
{
|
||||
SparkleHelpers.DebugInfo ("Listener",
|
||||
SparkleLogger.LogInfo ("Listener",
|
||||
"Got message " + announcement.Message + " from " +
|
||||
announcement.FolderIdentifier + " on " + Server);
|
||||
|
||||
if (IsRecentAnnouncement (announcement)) {
|
||||
SparkleHelpers.DebugInfo ("Listener", "Ignoring previously processed message " + announcement.Message +
|
||||
SparkleLogger.LogInfo ("Listener", "Ignoring previously processed message " + announcement.Message +
|
||||
" from " + announcement.FolderIdentifier + " on " + Server);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SparkleHelpers.DebugInfo ("Listener", "Processing message " + announcement.Message + " from " +
|
||||
SparkleLogger.LogInfo ("Listener", "Processing message " + announcement.Message + " from " +
|
||||
announcement.FolderIdentifier + " on " + Server);
|
||||
|
||||
AddRecentAnnouncement (announcement);
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace SparkleLib {
|
|||
// the number of connections as low as possible
|
||||
foreach (SparkleListenerBase listener in listeners) {
|
||||
if (listener.Server.Equals (announce_uri)) {
|
||||
SparkleHelpers.DebugInfo ("ListenerFactory", "Refered to existing listener for " + announce_uri);
|
||||
SparkleLogger.LogInfo ("ListenerFactory", "Refered to existing listener for " + announce_uri);
|
||||
|
||||
// We already seem to have a listener for this server,
|
||||
// refer to the existing one instead
|
||||
|
@ -64,7 +64,7 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
listeners.Add (new SparkleListenerTcp (announce_uri, folder_identifier));
|
||||
SparkleHelpers.DebugInfo ("ListenerFactory", "Issued new listener for " + announce_uri);
|
||||
SparkleLogger.LogInfo ("ListenerFactory", "Issued new listener for " + announce_uri);
|
||||
|
||||
return (SparkleListenerBase) listeners [listeners.Count - 1];
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace SparkleLib {
|
|||
// We've timed out, let's ping the server to
|
||||
// see if the connection is still up
|
||||
if (i == timeout) {
|
||||
SparkleHelpers.DebugInfo ("ListenerTcp",
|
||||
SparkleLogger.LogInfo ("ListenerTcp",
|
||||
"Pinging " + Server);
|
||||
|
||||
byte [] ping_bytes = Encoding.UTF8.GetBytes ("ping\n");
|
||||
|
@ -118,7 +118,7 @@ namespace SparkleLib {
|
|||
// 10057 means "Socket is not connected"
|
||||
throw new SocketException (10057);
|
||||
|
||||
SparkleHelpers.DebugInfo ("ListenerTcp", "Received pong from " + Server);
|
||||
SparkleLogger.LogInfo ("ListenerTcp", "Received pong from " + Server);
|
||||
|
||||
i = 0;
|
||||
this.last_ping = DateTime.Now;
|
||||
|
@ -135,7 +135,7 @@ namespace SparkleLib {
|
|||
);
|
||||
|
||||
if (sleepiness <= 0) {
|
||||
SparkleHelpers.DebugInfo ("ListenerTcp", "System woke up from sleep");
|
||||
SparkleLogger.LogInfo ("ListenerTcp", "System woke up from sleep");
|
||||
|
||||
// 10057 means "Socket is not connected"
|
||||
throw new SocketException (10057);
|
||||
|
|
40
SparkleLib/SparkleLogger.cs
Executable file
40
SparkleLib/SparkleLogger.cs
Executable file
|
@ -0,0 +1,40 @@
|
|||
// 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.IO;
|
||||
|
||||
namespace SparkleLib {
|
||||
|
||||
public static class SparkleLogger {
|
||||
|
||||
private static Object debug_lock = new Object ();
|
||||
|
||||
|
||||
public static void LogInfo (string type, string message)
|
||||
{
|
||||
string timestamp = DateTime.Now.ToString ("HH:mm:ss");
|
||||
string line = timestamp + " | " + type + " | " + message;
|
||||
|
||||
if (SparkleConfig.DebugMode)
|
||||
Console.WriteLine (line);
|
||||
|
||||
lock (debug_lock)
|
||||
File.AppendAllText (SparkleConfig.DefaultConfig.LogFilePath, line + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -95,7 +95,7 @@ namespace SparkleLib {
|
|||
File.WriteAllText (id_path, this.identifier);
|
||||
File.SetAttributes (id_path, FileAttributes.Hidden);
|
||||
|
||||
SparkleHelpers.DebugInfo ("Local", Name + " | Assigned identifier: " + this.identifier);
|
||||
SparkleLogger.LogInfo ("Local", Name + " | Assigned identifier: " + this.identifier);
|
||||
|
||||
return this.identifier;
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ namespace SparkleLib {
|
|||
IsBuffering = true;
|
||||
this.watcher.Disable ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("Local", Name + " | Activity detected, waiting for it to settle...");
|
||||
SparkleLogger.LogInfo ("Local", Name + " | Activity detected, waiting for it to settle...");
|
||||
|
||||
List<double> size_buffer = new List<double> ();
|
||||
|
||||
|
@ -230,7 +230,7 @@ namespace SparkleLib {
|
|||
size_buffer [1].Equals (size_buffer [2]) &&
|
||||
size_buffer [2].Equals (size_buffer [3])) {
|
||||
|
||||
SparkleHelpers.DebugInfo ("Local", Name + " | Activity has settled");
|
||||
SparkleLogger.LogInfo ("Local", Name + " | Activity has settled");
|
||||
IsBuffering = false;
|
||||
|
||||
if (HasLocalChanges) {
|
||||
|
@ -280,13 +280,13 @@ namespace SparkleLib {
|
|||
{
|
||||
this.watcher.Disable ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("SyncUp", Name + " | Initiated");
|
||||
SparkleLogger.LogInfo ("SyncUp", Name + " | Initiated");
|
||||
HasUnsyncedChanges = true;
|
||||
|
||||
SyncStatusChanged (SyncStatus.SyncUp);
|
||||
|
||||
if (SyncUp ()) {
|
||||
SparkleHelpers.DebugInfo ("SyncUp", Name + " | Done");
|
||||
SparkleLogger.LogInfo ("SyncUp", Name + " | Done");
|
||||
ChangeSets = GetChangeSets ();
|
||||
|
||||
HasUnsyncedChanges = false;
|
||||
|
@ -295,7 +295,7 @@ namespace SparkleLib {
|
|||
this.listener.Announce (new SparkleAnnouncement (Identifier, CurrentRevision));
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("SyncUp", Name + " | Error");
|
||||
SparkleLogger.LogInfo ("SyncUp", Name + " | Error");
|
||||
SyncDownBase ();
|
||||
|
||||
this.watcher.Disable ();
|
||||
|
@ -323,13 +323,13 @@ namespace SparkleLib {
|
|||
{
|
||||
this.watcher.Disable ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("SyncDown", Name + " | Initiated");
|
||||
SparkleLogger.LogInfo ("SyncDown", Name + " | Initiated");
|
||||
|
||||
SyncStatusChanged (SyncStatus.SyncDown);
|
||||
string pre_sync_revision = CurrentRevision;
|
||||
|
||||
if (SyncDown ()) {
|
||||
SparkleHelpers.DebugInfo ("SyncDown", Name + " | Done");
|
||||
SparkleLogger.LogInfo ("SyncDown", Name + " | Done");
|
||||
ServerOnline = true;
|
||||
|
||||
ChangeSets = GetChangeSets ();
|
||||
|
@ -361,7 +361,7 @@ namespace SparkleLib {
|
|||
SyncStatusChanged (SyncStatus.Idle);
|
||||
|
||||
} else {
|
||||
SparkleHelpers.DebugInfo ("SyncDown", Name + " | Error");
|
||||
SparkleLogger.LogInfo ("SyncDown", Name + " | Error");
|
||||
ServerOnline = false;
|
||||
|
||||
ChangeSets = GetChangeSets ();
|
||||
|
@ -424,7 +424,7 @@ namespace SparkleLib {
|
|||
private void ListenerDisconnectedDelegate ()
|
||||
{
|
||||
this.poll_interval = PollInterval.Short;
|
||||
SparkleHelpers.DebugInfo (Name, "Falling back to polling");
|
||||
SparkleLogger.LogInfo (Name, "Falling back to polling");
|
||||
}
|
||||
|
||||
|
||||
|
@ -439,12 +439,12 @@ namespace SparkleLib {
|
|||
while (this.is_syncing)
|
||||
Thread.Sleep (100);
|
||||
|
||||
SparkleHelpers.DebugInfo ("Listener", "Syncing due to announcement");
|
||||
SparkleLogger.LogInfo ("Listener", "Syncing due to announcement");
|
||||
SyncDownBase ();
|
||||
|
||||
} else {
|
||||
if (announcement.FolderIdentifier.Equals (identifier))
|
||||
SparkleHelpers.DebugInfo ("Listener", "Not syncing, message is for current revision");
|
||||
SparkleLogger.LogInfo ("Listener", "Not syncing, message is for current revision");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
<string>SparkleShare</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.productivity</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>LSUIElement</key>
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace SparkleShare {
|
|||
process.Start ();
|
||||
process.WaitForExit ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("Controller", "Added " + NSBundle.MainBundle.BundlePath + " to login items");
|
||||
SparkleLogger.LogInfo ("Controller", "Added " + NSBundle.MainBundle.BundlePath + " to login items");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
</ReleaseVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG</DefineConstants>
|
||||
|
@ -26,7 +25,13 @@
|
|||
<Command type="AfterBuild" command="mkdir -p ${TargetDir}/${SolutionName}.app/Contents/Frameworks; cp -r Growl.framework ${TargetDir}/${SolutionName}.app/Contents/Frameworks; cp -r git ${TargetDir}/${SolutionName}.app/Contents/Resources; cp -r SparkleShareInviteOpener.app ${TargetDir}/${SolutionName}.app/Contents/Resources" externalConsole="true" />
|
||||
</CustomCommands>
|
||||
</CustomCommands>
|
||||
<EnableCodeSigning>false</EnableCodeSigning>
|
||||
<CreatePackage>false</CreatePackage>
|
||||
<EnablePackageSigning>false</EnablePackageSigning>
|
||||
<IncludeMonoRuntime>false</IncludeMonoRuntime>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<CodeSigningKey>Mac Developer</CodeSigningKey>
|
||||
<PackageSigningKey>3rd Party Mac Developer Installer</PackageSigningKey>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using SparkleLib;
|
||||
|
||||
namespace SparkleShare {
|
||||
|
||||
// This is SparkleShare!
|
||||
|
@ -34,7 +36,9 @@ namespace SparkleShare {
|
|||
#endif
|
||||
public static void Main (string [] args)
|
||||
{
|
||||
if (args.Length != 0 && !args [0].Equals ("start")) {
|
||||
if (args.Length != 0 && !args [0].Equals ("start") &&
|
||||
SparkleBackend.Platform != PlatformID.MacOSX) {
|
||||
|
||||
string n = Environment.NewLine;
|
||||
|
||||
Console.WriteLine (n +
|
||||
|
|
|
@ -259,7 +259,7 @@ namespace SparkleShare {
|
|||
);
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Controller",
|
||||
SparkleLogger.LogInfo ("Controller",
|
||||
"Failed to load '" + backend + "' backend for '" + folder_name + "': " + e.Message);
|
||||
|
||||
return;
|
||||
|
@ -342,7 +342,7 @@ namespace SparkleShare {
|
|||
string new_folder_path = Path.Combine (path, folder_name);
|
||||
AddRepository (new_folder_path);
|
||||
|
||||
SparkleHelpers.DebugInfo ("Controller",
|
||||
SparkleLogger.LogInfo ("Controller",
|
||||
"Renamed folder with identifier " + identifier + " to '" + folder_name + "'");
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ namespace SparkleShare {
|
|||
this.config.RemoveFolder (folder_name);
|
||||
RemoveRepository (folder_path);
|
||||
|
||||
SparkleHelpers.DebugInfo ("Controller",
|
||||
SparkleLogger.LogInfo ("Controller",
|
||||
"Removed folder '" + folder_name + "' from config");
|
||||
|
||||
} else {
|
||||
|
@ -390,6 +390,31 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (args != null && args.FullPath.EndsWith (".xml") &&
|
||||
|
@ -463,7 +488,7 @@ namespace SparkleShare {
|
|||
);
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Controller",
|
||||
SparkleLogger.LogInfo ("Controller",
|
||||
"Failed to load '" + backend + "' backend for '" + canonical_name + "' " + e.Message);
|
||||
|
||||
FolderFetchError (Path.Combine (address, remote_path).Replace (@"\", "/"),
|
||||
|
@ -505,10 +530,10 @@ namespace SparkleShare {
|
|||
if (Directory.Exists (this.fetcher.TargetFolder)) {
|
||||
try {
|
||||
Directory.Delete (this.fetcher.TargetFolder, true);
|
||||
SparkleHelpers.DebugInfo ("Controller", "Deleted " + this.fetcher.TargetFolder);
|
||||
SparkleLogger.LogInfo ("Controller", "Deleted " + this.fetcher.TargetFolder);
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Controller",
|
||||
SparkleLogger.LogInfo ("Controller",
|
||||
"Failed to delete " + this.fetcher.TargetFolder + ": " + e.Message);
|
||||
}
|
||||
}
|
||||
|
@ -554,11 +579,11 @@ namespace SparkleShare {
|
|||
string target_folder_path = Path.Combine (this.config.FoldersPath, target_folder_name);
|
||||
|
||||
try {
|
||||
SparkleHelpers.ClearAttributes (this.fetcher.TargetFolder);
|
||||
ClearFolderAttributes (this.fetcher.TargetFolder);
|
||||
Directory.Move (this.fetcher.TargetFolder, target_folder_path);
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Controller", "Error moving directory: " + e.Message);
|
||||
SparkleLogger.LogInfo ("Controller", "Error moving directory: " + e.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -640,7 +665,7 @@ namespace SparkleShare {
|
|||
string avatars_path = new string [] { Path.GetDirectoryName (this.config.FullPath),
|
||||
"avatars", size + "x" + size }.Combine ();
|
||||
|
||||
string avatar_file_path = Path.Combine (avatars_path, SparkleHelpers.MD5 (email) + ".jpg");
|
||||
string avatar_file_path = Path.Combine (avatars_path, email.MD5 () + ".jpg");
|
||||
|
||||
if (File.Exists (avatar_file_path)) {
|
||||
if (new FileInfo (avatar_file_path).CreationTime < DateTime.Now.AddDays (-1))
|
||||
|
@ -650,7 +675,7 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
WebClient client = new WebClient ();
|
||||
string url = "https://gravatar.com/avatar/" + SparkleHelpers.MD5 (email) + ".jpg?s=" + size + "&d=404";
|
||||
string url = "https://gravatar.com/avatar/" + email.MD5 () + ".jpg?s=" + size + "&d=404";
|
||||
|
||||
try {
|
||||
byte [] buffer = client.DownloadData (url);
|
||||
|
@ -658,11 +683,11 @@ namespace SparkleShare {
|
|||
if (buffer.Length > 255) {
|
||||
if (!Directory.Exists (avatars_path)) {
|
||||
Directory.CreateDirectory (avatars_path);
|
||||
SparkleHelpers.DebugInfo ("Controller", "Created '" + avatars_path + "'");
|
||||
SparkleLogger.LogInfo ("Controller", "Created '" + avatars_path + "'");
|
||||
}
|
||||
|
||||
File.WriteAllBytes (avatar_file_path, buffer);
|
||||
SparkleHelpers.DebugInfo ("Controller", "Fetched " + size + "x" + size + " avatar for " + email);
|
||||
SparkleLogger.LogInfo ("Controller", "Fetched " + size + "x" + size + " avatar for " + email);
|
||||
|
||||
return avatar_file_path;
|
||||
|
||||
|
@ -678,7 +703,7 @@ namespace SparkleShare {
|
|||
|
||||
public string AssignAvatar (string s)
|
||||
{
|
||||
string hash = "0" + SparkleHelpers.MD5 (s).Substring (0, 8);
|
||||
string hash = "0" + s.MD5 ().Substring (0, 8);
|
||||
string numbers = Regex.Replace (hash, "[a-z]", "");
|
||||
int number = int.Parse (numbers);
|
||||
string letters = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace SparkleShare {
|
|||
if (change_sets != null)
|
||||
list.AddRange (change_sets);
|
||||
else
|
||||
SparkleHelpers.DebugInfo ("Log", "Could not create log for " + repo.Name);
|
||||
SparkleLogger.LogInfo ("Log", "Could not create log for " + repo.Name);
|
||||
}
|
||||
|
||||
list.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp)));
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace SparkleShare {
|
|||
Initialize (address, remote_path, accept_url, announcements_url, fingerprint);
|
||||
|
||||
} catch (XmlException e) {
|
||||
SparkleHelpers.DebugInfo ("Invite", "Invalid XML: " + e.Message);
|
||||
SparkleLogger.LogInfo ("Invite", "Invalid XML: " + e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -104,12 +104,12 @@ namespace SparkleShare {
|
|||
response.Close ();
|
||||
|
||||
} catch (WebException e) {
|
||||
SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message);
|
||||
SparkleLogger.LogInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response != null && response.StatusCode == HttpStatusCode.OK) {
|
||||
SparkleHelpers.DebugInfo ("Invite", "Uploaded public key to " + AcceptUrl);
|
||||
SparkleLogger.LogInfo ("Invite", "Uploaded public key to " + AcceptUrl);
|
||||
return true;
|
||||
|
||||
} else {
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace SparkleShare {
|
|||
string key_file_path = Path.Combine (output_path, key_name);
|
||||
|
||||
if (File.Exists (key_file_path)) {
|
||||
SparkleHelpers.DebugInfo ("Auth", "A key pair exists ('" + key_name + "'), leaving it untouched");
|
||||
SparkleLogger.LogInfo ("Auth", "A key pair exists ('" + key_name + "'), leaving it untouched");
|
||||
return new string [] { key_file_path, key_file_path + ".pub" };
|
||||
|
||||
} else {
|
||||
|
@ -61,9 +61,9 @@ namespace SparkleShare {
|
|||
process.WaitForExit ();
|
||||
|
||||
if (process.ExitCode == 0)
|
||||
SparkleHelpers.DebugInfo ("Auth", "Created keypair '" + key_file_path + "'");
|
||||
SparkleLogger.LogInfo ("Auth", "Created keypair '" + key_file_path + "'");
|
||||
else
|
||||
SparkleHelpers.DebugInfo ("Auth", "Could not create key pair '" + key_file_path + "'");
|
||||
SparkleLogger.LogInfo ("Auth", "Could not create key pair '" + key_file_path + "'");
|
||||
|
||||
return new string [] { key_file_path, key_file_path + ".pub" };
|
||||
}
|
||||
|
@ -83,9 +83,9 @@ namespace SparkleShare {
|
|||
process.WaitForExit ();
|
||||
|
||||
if (process.ExitCode == 0)
|
||||
SparkleHelpers.DebugInfo ("Auth", "Imported key '" + key_file_path + "'");
|
||||
SparkleLogger.LogInfo ("Auth", "Imported key '" + key_file_path + "'");
|
||||
else
|
||||
SparkleHelpers.DebugInfo ("Auth", "Could not import key '" + key_file_path + "'");
|
||||
SparkleLogger.LogInfo ("Auth", "Could not import key '" + key_file_path + "'");
|
||||
}
|
||||
|
||||
|
||||
|
@ -106,7 +106,7 @@ namespace SparkleShare {
|
|||
string keys_in_use = process.StandardOutput.ReadToEnd ();
|
||||
process.WaitForExit ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("Auth", "The following keys may be used: " +
|
||||
SparkleLogger.LogInfo ("Auth", "The following keys may be used: " +
|
||||
Environment.NewLine + keys_in_use.Trim ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -386,11 +386,11 @@ namespace SparkleShare {
|
|||
|
||||
if (new_plugin != null) {
|
||||
Plugins.Insert (1, new_plugin);
|
||||
SparkleHelpers.DebugInfo ("Controller", "Added plugin for " + uri.Host);
|
||||
SparkleLogger.LogInfo ("Controller", "Added plugin for " + uri.Host);
|
||||
}
|
||||
|
||||
} catch {
|
||||
SparkleHelpers.DebugInfo ("Controller", "Failed adding plugin for " + uri.Host);
|
||||
SparkleLogger.LogInfo ("Controller", "Failed adding plugin for " + uri.Host);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue