More cleanup of SparkleLib API
This commit is contained in:
parent
3370a283ea
commit
f2b9e7bce7
|
@ -79,8 +79,8 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
base.target_folder = target_folder;
|
||||
base.remote_url = uri.ToString ();
|
||||
TargetFolder = target_folder;
|
||||
RemoteUrl = uri.ToString ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -89,7 +89,7 @@ namespace SparkleLib {
|
|||
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"clone " +
|
||||
"--progress " + // Redirects progress stats to standarderror
|
||||
"\"" + base.remote_url + "\" " + "\"" + base.target_folder + "\"");
|
||||
"\"" + RemoteUrl + "\" " + "\"" + TargetFolder + "\"");
|
||||
|
||||
this.git.StartInfo.RedirectStandardError = true;
|
||||
this.git.Start ();
|
||||
|
@ -139,13 +139,14 @@ namespace SparkleLib {
|
|||
} else {
|
||||
InstallConfiguration ();
|
||||
InstallExcludeRules ();
|
||||
AddWarnings ();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override string [] Warnings {
|
||||
get {
|
||||
private void AddWarnings ()
|
||||
{
|
||||
SparkleGit git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||
"config --global core.excludesfile");
|
||||
|
||||
|
@ -157,16 +158,16 @@ namespace SparkleLib {
|
|||
git.WaitForExit ();
|
||||
|
||||
if (string.IsNullOrEmpty (output)) {
|
||||
return null;
|
||||
return;
|
||||
|
||||
} else {
|
||||
return new string [] {
|
||||
Warnings = new string [] {
|
||||
string.Format ("You seem to have configured a system ‘gitignore’ file. " +
|
||||
"This may interfere with SparkleShare.\n({0})", output)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Stop ()
|
||||
{
|
||||
|
@ -175,7 +176,7 @@ namespace SparkleLib {
|
|||
this.git.Dispose ();
|
||||
}
|
||||
|
||||
base.Stop ();
|
||||
Dispose ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -183,7 +184,7 @@ namespace SparkleLib {
|
|||
// the newly cloned repository
|
||||
private void InstallConfiguration ()
|
||||
{
|
||||
string repo_config_file_path = SparkleHelpers.CombineMore (base.target_folder, ".git", "config");
|
||||
string repo_config_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "config");
|
||||
string config = String.Join (Environment.NewLine, File.ReadAllLines (repo_config_file_path));
|
||||
|
||||
string n = Environment.NewLine;
|
||||
|
@ -219,7 +220,7 @@ namespace SparkleLib {
|
|||
private void InstallExcludeRules ()
|
||||
{
|
||||
DirectoryInfo info = Directory.CreateDirectory (
|
||||
SparkleHelpers.CombineMore (this.target_folder, ".git", "info"));
|
||||
SparkleHelpers.CombineMore (TargetFolder, ".git", "info"));
|
||||
|
||||
// File that lists the files we want git to ignore
|
||||
string exclude_rules_file_path = Path.Combine (info.FullName, "exclude");
|
||||
|
|
|
@ -244,7 +244,7 @@ namespace SparkleLib {
|
|||
|
||||
if (number >= percentage) {
|
||||
percentage = number;
|
||||
base.OnSyncProgressChanged (percentage, speed);
|
||||
base.OnProgressChanged (percentage, speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ namespace SparkleLib {
|
|||
|
||||
if (number >= percentage) {
|
||||
percentage = number;
|
||||
base.OnSyncProgressChanged (percentage, speed);
|
||||
base.OnProgressChanged (percentage, speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,18 +35,21 @@ namespace SparkleLib {
|
|||
public event FailedEventHandler Failed;
|
||||
public event ProgressChangedEventHandler ProgressChanged;
|
||||
|
||||
public string [] ExcludeRules;
|
||||
public abstract bool Fetch ();
|
||||
public abstract void Stop ();
|
||||
|
||||
protected string target_folder;
|
||||
protected string remote_url;
|
||||
public string TargetFolder;
|
||||
public string RemoteUrl;
|
||||
public string [] ExcludeRules;
|
||||
public string [] Warnings;
|
||||
|
||||
private Thread thread;
|
||||
|
||||
|
||||
public SparkleFetcherBase (string server, string remote_folder, string target_folder)
|
||||
{
|
||||
this.target_folder = target_folder;
|
||||
this.remote_url = server + "/" + remote_folder;
|
||||
TargetFolder = target_folder;
|
||||
RemoteUrl = server + "/" + remote_folder;
|
||||
|
||||
ExcludeRules = new string [] {
|
||||
// gedit and emacs
|
||||
|
@ -119,22 +122,18 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
public abstract bool Fetch ();
|
||||
public abstract string [] Warnings { get; }
|
||||
|
||||
|
||||
// Clones the remote repository
|
||||
public void Start ()
|
||||
{
|
||||
SparkleHelpers.DebugInfo ("Fetcher", "[" + this.target_folder + "] Fetching folder: " + this.remote_url);
|
||||
SparkleHelpers.DebugInfo ("Fetcher", "[" + TargetFolder + "] Fetching folder: " + RemoteUrl);
|
||||
|
||||
if (Started != null)
|
||||
Started ();
|
||||
|
||||
if (Directory.Exists (this.target_folder))
|
||||
Directory.Delete (this.target_folder, true);
|
||||
if (Directory.Exists (TargetFolder))
|
||||
Directory.Delete (TargetFolder, true);
|
||||
|
||||
string host = GetHost (this.remote_url);
|
||||
string host = GetHost (RemoteUrl);
|
||||
|
||||
if (String.IsNullOrEmpty (host)) {
|
||||
if (Failed != null)
|
||||
|
@ -168,20 +167,6 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
public virtual void Stop ()
|
||||
{
|
||||
this.thread.Abort ();
|
||||
this.thread.Join ();
|
||||
}
|
||||
|
||||
|
||||
public string RemoteUrl {
|
||||
get {
|
||||
return this.remote_url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
if (this.thread != null) {
|
||||
|
|
|
@ -38,45 +38,28 @@ namespace SparkleLib {
|
|||
|
||||
private TimeSpan short_interval = new TimeSpan (0, 0, 3, 0);
|
||||
private TimeSpan long_interval = new TimeSpan (0, 0, 10, 0);
|
||||
|
||||
private TimeSpan poll_interval;
|
||||
private SparkleWatcher watcher;
|
||||
private SparkleListenerBase listener;
|
||||
private TimeSpan poll_interval;
|
||||
private System.Timers.Timer local_timer = new System.Timers.Timer () { Interval = 0.25 * 1000 };
|
||||
private System.Timers.Timer remote_timer = new System.Timers.Timer () { Interval = 10 * 1000 };
|
||||
private DateTime last_poll = DateTime.Now;
|
||||
private List<double> size_buffer = new List<double> ();
|
||||
private bool has_changed = false;
|
||||
private Object change_lock = new Object ();
|
||||
private Object watch_lock = new Object ();
|
||||
private double progress_percentage = 0.0;
|
||||
private string progress_speed = "";
|
||||
private SyncStatus status;
|
||||
|
||||
private bool has_changed = false;
|
||||
private bool is_buffering = false;
|
||||
private bool server_online = true;
|
||||
private SyncStatus status;
|
||||
|
||||
public readonly string LocalPath;
|
||||
public readonly string Name;
|
||||
public readonly Uri Url;
|
||||
|
||||
public abstract bool HasLocalChanges { get; }
|
||||
public abstract string Identifier { get; }
|
||||
public abstract string CurrentRevision { get; }
|
||||
public abstract bool SyncUp ();
|
||||
public abstract bool SyncDown ();
|
||||
public abstract bool HasUnsyncedChanges { get; set; }
|
||||
public abstract bool HasRemoteChanges { get; }
|
||||
public abstract List<string> ExcludePaths { get; }
|
||||
|
||||
public abstract double Size { get; }
|
||||
public abstract double HistorySize { get; }
|
||||
|
||||
public delegate void SyncStatusChangedEventHandler (SyncStatus new_status);
|
||||
public event SyncStatusChangedEventHandler SyncStatusChanged;
|
||||
|
||||
public delegate void SyncProgressChangedEventHandler (double percentage, string speed);
|
||||
public event SyncProgressChangedEventHandler SyncProgressChanged;
|
||||
public delegate void ProgressChangedEventHandler (double percentage, string speed);
|
||||
public event ProgressChangedEventHandler SyncProgressChanged;
|
||||
|
||||
public delegate void NewChangeSetEventHandler (SparkleChangeSet change_set);
|
||||
public event NewChangeSetEventHandler NewChangeSet;
|
||||
|
@ -91,41 +74,53 @@ namespace SparkleLib {
|
|||
public event ChangesDetectedEventHandler ChangesDetected;
|
||||
|
||||
|
||||
public readonly string LocalPath;
|
||||
public readonly string Name;
|
||||
public readonly Uri Url;
|
||||
|
||||
public abstract string Identifier { get; }
|
||||
public abstract string CurrentRevision { get; }
|
||||
public abstract double Size { get; }
|
||||
public abstract double HistorySize { get; }
|
||||
public abstract List<string> ExcludePaths { get; }
|
||||
public abstract bool HasUnsyncedChanges { get; set; }
|
||||
public abstract bool HasLocalChanges { get; }
|
||||
public abstract bool HasRemoteChanges { get; }
|
||||
public abstract bool SyncUp ();
|
||||
public abstract bool SyncDown ();
|
||||
public abstract List<SparkleChangeSet> GetChangeSets (int count);
|
||||
|
||||
|
||||
public bool ServerOnline {
|
||||
get {
|
||||
return this.server_online;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SyncStatus Status {
|
||||
get {
|
||||
return this.status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double ProgressPercentage {
|
||||
get {
|
||||
return this.progress_percentage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string ProgressSpeed {
|
||||
get {
|
||||
return this.progress_speed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual string [] UnsyncedFilePaths {
|
||||
get {
|
||||
return new string [0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsSyncing {
|
||||
get {
|
||||
return (Status == SyncStatus.SyncUp ||
|
||||
|
@ -134,7 +129,6 @@ namespace SparkleLib {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsBuffering {
|
||||
get {
|
||||
return this.is_buffering;
|
||||
|
@ -213,11 +207,6 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
public virtual List<SparkleChangeSet> GetChangeSets (int count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Disposes all resourses of this object
|
||||
public void Dispose ()
|
||||
{
|
||||
|
@ -585,7 +574,7 @@ namespace SparkleLib {
|
|||
private DateTime progress_last_change = DateTime.Now;
|
||||
private TimeSpan progress_change_interval = new TimeSpan (0, 0, 0, 1);
|
||||
|
||||
protected void OnSyncProgressChanged (double progress_percentage, string progress_speed)
|
||||
protected void OnProgressChanged (double progress_percentage, string progress_speed)
|
||||
{
|
||||
if (DateTime.Compare (this.progress_last_change,
|
||||
DateTime.Now.Subtract (this.progress_change_interval)) < 0) {
|
||||
|
@ -614,8 +603,7 @@ namespace SparkleLib {
|
|||
writer.WriteLine ("Congratulations, you've successfully created a SparkleShare repository!");
|
||||
writer.WriteLine ("");
|
||||
writer.WriteLine ("Any files you add or change in this folder will be automatically synced to ");
|
||||
writer.WriteLine (SparkleConfig.DefaultConfig.GetUrlForFolder (Name) + " and everyone connected to it.");
|
||||
// TODO: Url property? ^
|
||||
writer.WriteLine (Url + " and everyone connected to it.");
|
||||
|
||||
writer.WriteLine ("");
|
||||
writer.WriteLine ("SparkleShare is a Free and Open Source software program that helps people ");
|
||||
|
@ -649,8 +637,6 @@ namespace SparkleLib {
|
|||
|
||||
double size = 0;
|
||||
|
||||
// Ignore the temporary 'rebase-apply' and '.tmp' directories. This prevents potential
|
||||
// crashes when files are being queried whilst the files have already been deleted.
|
||||
if (ExcludePaths.Contains (parent.Name))
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -615,7 +615,7 @@ namespace SparkleShare {
|
|||
}
|
||||
};
|
||||
|
||||
repo.SyncProgressChanged += delegate (double percentage, string speed) {
|
||||
repo.ProgressChanged += delegate (double percentage, string speed) {
|
||||
ProgressPercentage = percentage;
|
||||
ProgressSpeed = speed;
|
||||
|
||||
|
|
Loading…
Reference in a new issue