fetcher: use FetcherInfo object to wrap parameters and respect AnouncementsUrl

This commit is contained in:
Hylke Bons 2013-01-27 19:24:36 +00:00
parent 857d34d939
commit a2dff5785e
4 changed files with 59 additions and 53 deletions

View file

@ -62,9 +62,7 @@ namespace SparkleLib.Git {
} }
public SparkleFetcher (string server, string required_fingerprint, string remote_path, public SparkleFetcher (SparkleFetcherInfo info) : base (info)
string target_folder, bool fetch_prior_history) : base (server, required_fingerprint,
remote_path, target_folder, fetch_prior_history)
{ {
if (RemoteUrl.ToString ().StartsWith ("ssh+")) if (RemoteUrl.ToString ().StartsWith ("ssh+"))
RemoteUrl = new Uri ("ssh" + RemoteUrl.ToString ().Substring (RemoteUrl.ToString ().IndexOf ("://"))); RemoteUrl = new Uri ("ssh" + RemoteUrl.ToString ().Substring (RemoteUrl.ToString ().IndexOf ("://")));
@ -104,8 +102,7 @@ namespace SparkleLib.Git {
this.use_git_bin = false; // TODO this.use_git_bin = false; // TODO
} }
TargetFolder = target_folder; RemoteUrl = uri;
RemoteUrl = uri;
} }

View file

@ -24,7 +24,16 @@ using System.Threading;
namespace SparkleLib { namespace SparkleLib {
// Sets up a fetcher that can get remote folders public class SparkleFetcherInfo {
public string Address;
public string Fingerprint;
public string RemotePath;
public string TargetDirectory;
public string AnnouncementsUrl;
public bool FetchPriorHistory;
}
public abstract class SparkleFetcherBase { public abstract class SparkleFetcherBase {
public event Action Started = delegate { }; public event Action Started = delegate { };
@ -49,6 +58,7 @@ namespace SparkleLib {
public string TargetFolder { get; protected set; } public string TargetFolder { get; protected set; }
public bool IsActive { get; private set; } public bool IsActive { get; private set; }
public string Identifier; public string Identifier;
public SparkleFetcherInfo OriginalFetcherInfo;
public string [] Warnings { public string [] Warnings {
get { get {
@ -73,7 +83,7 @@ namespace SparkleLib {
"*.part", "*.crdownload", // Firefox and Chromium temporary download files "*.part", "*.crdownload", // Firefox and Chromium temporary download files
".*.sw[a-z]", "*.un~", "*.swp", "*.swo", // vi(m) ".*.sw[a-z]", "*.un~", "*.swp", "*.swo", // vi(m)
".directory", // KDE ".directory", // KDE
".DS_Store", "Icon\r\r", "._*", ".Spotlight-V100", ".Trashes", // Mac OS X ".DS_Store", "Icon\r", "._*", ".Spotlight-V100", ".Trashes", // Mac OS X
"*(Autosaved).graffle", // Omnigraffle "*(Autosaved).graffle", // Omnigraffle
"Thumbs.db", "Desktop.ini", // Windows "Thumbs.db", "Desktop.ini", // Windows
"~*.tmp", "~*.TMP", "*~*.tmp", "*~*.TMP", // MS Office "~*.tmp", "~*.TMP", "*~*.tmp", "*~*.TMP", // MS Office
@ -90,25 +100,26 @@ namespace SparkleLib {
private Thread thread; private Thread thread;
public SparkleFetcherBase (string server, string required_fingerprint, public SparkleFetcherBase (SparkleFetcherInfo info)
string remote_path, string target_folder, bool fetch_prior_history)
{ {
RequiredFingerprint = required_fingerprint; OriginalFetcherInfo = info;
FetchPriorHistory = fetch_prior_history; RequiredFingerprint = info.Fingerprint;
remote_path = remote_path.Trim ("/".ToCharArray ()); FetchPriorHistory = info.FetchPriorHistory;
string remote_path = info.RemotePath.Trim ("/".ToCharArray ());
string address = info.Address;
if (server.EndsWith ("/")) if (address.EndsWith ("/"))
server = server.Substring (0, server.Length - 1); address = address.Substring (0, address.Length - 1);
if (!remote_path.StartsWith ("/")) if (!remote_path.StartsWith ("/"))
remote_path = "/" + remote_path; remote_path = "/" + remote_path;
if (!server.Contains ("://")) if (!address.Contains ("://"))
server = "ssh://" + server; address = "ssh://" + address;
TargetFolder = target_folder; TargetFolder = info.TargetDirectory;
RemoteUrl = new Uri (server + remote_path); RemoteUrl = new Uri (address + remote_path);
IsActive = false; IsActive = false;
} }

View file

@ -78,9 +78,7 @@ namespace SparkleShare {
public bool FirstRun { public bool FirstRun {
get { get { return this.config.User.Email.Equals ("Unknown"); }
return this.config.User.Email.Equals ("Unknown");
}
} }
public List<string> Folders { public List<string> Folders {
@ -91,19 +89,12 @@ namespace SparkleShare {
} }
public string ConfigPath { public string ConfigPath {
get { get { return this.config.LogFilePath; }
return this.config.LogFilePath;
}
} }
public SparkleUser CurrentUser { public SparkleUser CurrentUser {
get { get { return this.config.User; }
return this.config.User; set { this.config.User = value; }
}
set {
this.config.User = value;
}
} }
public bool NotificationsEnabled { public bool NotificationsEnabled {
@ -541,12 +532,8 @@ namespace SparkleShare {
} }
public void StartFetcher (string address, string required_fingerprint, public void StartFetcher (SparkleFetcherInfo info)
string remote_path, string announcements_url, bool fetch_prior_history)
{ {
if (announcements_url != null)
announcements_url = announcements_url.Trim ();
string tmp_path = this.config.TmpPath; string tmp_path = this.config.TmpPath;
if (!Directory.Exists (tmp_path)) { if (!Directory.Exists (tmp_path)) {
@ -554,21 +541,19 @@ namespace SparkleShare {
File.SetAttributes (tmp_path, File.GetAttributes (tmp_path) | FileAttributes.Hidden); File.SetAttributes (tmp_path, File.GetAttributes (tmp_path) | FileAttributes.Hidden);
} }
string canonical_name = Path.GetFileName (remote_path); string canonical_name = Path.GetFileName (info.RemotePath);
string tmp_folder = Path.Combine (tmp_path, canonical_name); string backend = SparkleFetcherBase.GetBackend (info.Address);
string backend = SparkleFetcherBase.GetBackend (address); info.TargetDirectory = Path.Combine (tmp_path, canonical_name);
try { try {
this.fetcher = (SparkleFetcherBase) Activator.CreateInstance ( this.fetcher = (SparkleFetcherBase) Activator.CreateInstance (
Type.GetType ("SparkleLib." + backend + ".SparkleFetcher, SparkleLib." + backend), Type.GetType ("SparkleLib." + backend + ".SparkleFetcher, SparkleLib." + backend), info);
address, required_fingerprint, remote_path, tmp_folder, fetch_prior_history
);
} catch (Exception e) { } catch (Exception e) {
SparkleLogger.LogInfo ("Controller", SparkleLogger.LogInfo ("Controller",
"Failed to load '" + backend + "' backend for '" + canonical_name + "' " + e.Message); "Failed to load '" + backend + "' backend for '" + canonical_name + "' " + e.Message);
FolderFetchError (Path.Combine (address, remote_path).Replace (@"\", "/"), FolderFetchError (Path.Combine (info.Address, info.RemotePath).Replace (@"\", "/"),
new string [] {"Failed to load \"" + backend + "\" backend for \"" + canonical_name + "\""}); new string [] {"Failed to load \"" + backend + "\" backend for \"" + canonical_name + "\""});
return; return;
@ -689,8 +674,12 @@ namespace SparkleShare {
this.config.AddFolder (target_folder_name, this.fetcher.Identifier, this.config.AddFolder (target_folder_name, this.fetcher.Identifier,
this.fetcher.RemoteUrl.ToString (), backend); this.fetcher.RemoteUrl.ToString (), backend);
RepositoriesLoaded = true; if (this.fetcher.OriginalFetcherInfo.AnnouncementsUrl != null) {
this.config.SetFolderOptionalAttribute (target_folder_name, "announcements_url",
this.fetcher.OriginalFetcherInfo.AnnouncementsUrl);
}
RepositoriesLoaded = true;
FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ()); FolderFetched (this.fetcher.RemoteUrl.ToString (), this.fetcher.Warnings.ToArray ());
AddRepository (target_folder_path); AddRepository (target_folder_path);

View file

@ -371,11 +371,15 @@ namespace SparkleShare {
Program.Controller.FolderFetchError += AddPageFetchErrorDelegate; Program.Controller.FolderFetchError += AddPageFetchErrorDelegate;
Program.Controller.FolderFetching += SyncingPageFetchingDelegate; Program.Controller.FolderFetching += SyncingPageFetchingDelegate;
new Thread (() => { SparkleFetcherInfo info = new SparkleFetcherInfo {
Program.Controller.StartFetcher (address, SelectedPlugin.Fingerprint, remote_path, Address = address,
SelectedPlugin.AnnouncementsUrl, this.fetch_prior_history); Fingerprint = SelectedPlugin.Fingerprint,
RemotePath = remote_path,
FetchPriorHistory = this.fetch_prior_history,
AnnouncementsUrl = SelectedPlugin.AnnouncementsUrl
};
}).Start (); new Thread (() => { Program.Controller.StartFetcher (info); }).Start ();
} }
// The following private methods are // The following private methods are
@ -448,9 +452,7 @@ namespace SparkleShare {
new Thread (() => { new Thread (() => {
if (!PendingInvite.Accept (Program.Controller.CurrentUser.PublicKey)) { if (!PendingInvite.Accept (Program.Controller.CurrentUser.PublicKey)) {
PreviousUrl = PendingInvite.Address + PreviousUrl = PendingInvite.Address + PendingInvite.RemotePath.TrimStart ("/".ToCharArray ());
PendingInvite.RemotePath.TrimStart ("/".ToCharArray ());
ChangePageEvent (PageType.Error, new string [] { "error: Failed to upload the public key" }); ChangePageEvent (PageType.Error, new string [] { "error: Failed to upload the public key" });
return; return;
} }
@ -459,8 +461,15 @@ namespace SparkleShare {
Program.Controller.FolderFetchError += InvitePageFetchErrorDelegate; Program.Controller.FolderFetchError += InvitePageFetchErrorDelegate;
Program.Controller.FolderFetching += SyncingPageFetchingDelegate; Program.Controller.FolderFetching += SyncingPageFetchingDelegate;
Program.Controller.StartFetcher (PendingInvite.Address, PendingInvite.Fingerprint, SparkleFetcherInfo info = new SparkleFetcherInfo {
PendingInvite.RemotePath, PendingInvite.AnnouncementsUrl, false); // TODO: checkbox on invite page Address = PendingInvite.Address,
Fingerprint = PendingInvite.Fingerprint,
RemotePath = PendingInvite.RemotePath,
FetchPriorHistory = false, // TODO: checkbox on invite page
AnnouncementsUrl = PendingInvite.AnnouncementsUrl
};
Program.Controller.StartFetcher (info);
}).Start (); }).Start ();
} }