fetcher: use FetcherInfo object to wrap parameters and respect AnouncementsUrl
This commit is contained in:
parent
5b43da1012
commit
515db5bb9f
|
@ -62,9 +62,7 @@ namespace SparkleLib.Git {
|
|||
}
|
||||
|
||||
|
||||
public SparkleFetcher (string server, string required_fingerprint, string remote_path,
|
||||
string target_folder, bool fetch_prior_history) : base (server, required_fingerprint,
|
||||
remote_path, target_folder, fetch_prior_history)
|
||||
public SparkleFetcher (SparkleFetcherInfo info) : base (info)
|
||||
{
|
||||
if (RemoteUrl.ToString ().StartsWith ("ssh+"))
|
||||
RemoteUrl = new Uri ("ssh" + RemoteUrl.ToString ().Substring (RemoteUrl.ToString ().IndexOf ("://")));
|
||||
|
@ -104,8 +102,7 @@ namespace SparkleLib.Git {
|
|||
this.use_git_bin = false; // TODO
|
||||
}
|
||||
|
||||
TargetFolder = target_folder;
|
||||
RemoteUrl = uri;
|
||||
RemoteUrl = uri;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,7 +24,16 @@ using System.Threading;
|
|||
|
||||
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 event Action Started = delegate { };
|
||||
|
@ -49,6 +58,7 @@ namespace SparkleLib {
|
|||
public string TargetFolder { get; protected set; }
|
||||
public bool IsActive { get; private set; }
|
||||
public string Identifier;
|
||||
public SparkleFetcherInfo OriginalFetcherInfo;
|
||||
|
||||
public string [] Warnings {
|
||||
get {
|
||||
|
@ -73,7 +83,7 @@ namespace SparkleLib {
|
|||
"*.part", "*.crdownload", // Firefox and Chromium temporary download files
|
||||
".*.sw[a-z]", "*.un~", "*.swp", "*.swo", // vi(m)
|
||||
".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
|
||||
"Thumbs.db", "Desktop.ini", // Windows
|
||||
"~*.tmp", "~*.TMP", "*~*.tmp", "*~*.TMP", // MS Office
|
||||
|
@ -90,25 +100,26 @@ namespace SparkleLib {
|
|||
private Thread thread;
|
||||
|
||||
|
||||
public SparkleFetcherBase (string server, string required_fingerprint,
|
||||
string remote_path, string target_folder, bool fetch_prior_history)
|
||||
public SparkleFetcherBase (SparkleFetcherInfo info)
|
||||
{
|
||||
RequiredFingerprint = required_fingerprint;
|
||||
FetchPriorHistory = fetch_prior_history;
|
||||
remote_path = remote_path.Trim ("/".ToCharArray ());
|
||||
OriginalFetcherInfo = info;
|
||||
RequiredFingerprint = info.Fingerprint;
|
||||
FetchPriorHistory = info.FetchPriorHistory;
|
||||
string remote_path = info.RemotePath.Trim ("/".ToCharArray ());
|
||||
string address = info.Address;
|
||||
|
||||
if (server.EndsWith ("/"))
|
||||
server = server.Substring (0, server.Length - 1);
|
||||
if (address.EndsWith ("/"))
|
||||
address = address.Substring (0, address.Length - 1);
|
||||
|
||||
if (!remote_path.StartsWith ("/"))
|
||||
remote_path = "/" + remote_path;
|
||||
|
||||
if (!server.Contains ("://"))
|
||||
server = "ssh://" + server;
|
||||
if (!address.Contains ("://"))
|
||||
address = "ssh://" + address;
|
||||
|
||||
TargetFolder = target_folder;
|
||||
TargetFolder = info.TargetDirectory;
|
||||
|
||||
RemoteUrl = new Uri (server + remote_path);
|
||||
RemoteUrl = new Uri (address + remote_path);
|
||||
IsActive = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,9 +78,7 @@ namespace SparkleShare {
|
|||
|
||||
|
||||
public bool FirstRun {
|
||||
get {
|
||||
return this.config.User.Email.Equals ("Unknown");
|
||||
}
|
||||
get { return this.config.User.Email.Equals ("Unknown"); }
|
||||
}
|
||||
|
||||
public List<string> Folders {
|
||||
|
@ -91,19 +89,12 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
public string ConfigPath {
|
||||
get {
|
||||
return this.config.LogFilePath;
|
||||
}
|
||||
get { return this.config.LogFilePath; }
|
||||
}
|
||||
|
||||
public SparkleUser CurrentUser {
|
||||
get {
|
||||
return this.config.User;
|
||||
}
|
||||
|
||||
set {
|
||||
this.config.User = value;
|
||||
}
|
||||
get { return this.config.User; }
|
||||
set { this.config.User = value; }
|
||||
}
|
||||
|
||||
public bool NotificationsEnabled {
|
||||
|
@ -541,12 +532,8 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
public void StartFetcher (string address, string required_fingerprint,
|
||||
string remote_path, string announcements_url, bool fetch_prior_history)
|
||||
public void StartFetcher (SparkleFetcherInfo info)
|
||||
{
|
||||
if (announcements_url != null)
|
||||
announcements_url = announcements_url.Trim ();
|
||||
|
||||
string tmp_path = this.config.TmpPath;
|
||||
|
||||
if (!Directory.Exists (tmp_path)) {
|
||||
|
@ -554,21 +541,19 @@ namespace SparkleShare {
|
|||
File.SetAttributes (tmp_path, File.GetAttributes (tmp_path) | FileAttributes.Hidden);
|
||||
}
|
||||
|
||||
string canonical_name = Path.GetFileName (remote_path);
|
||||
string tmp_folder = Path.Combine (tmp_path, canonical_name);
|
||||
string backend = SparkleFetcherBase.GetBackend (address);
|
||||
string canonical_name = Path.GetFileName (info.RemotePath);
|
||||
string backend = SparkleFetcherBase.GetBackend (info.Address);
|
||||
info.TargetDirectory = Path.Combine (tmp_path, canonical_name);
|
||||
|
||||
try {
|
||||
this.fetcher = (SparkleFetcherBase) Activator.CreateInstance (
|
||||
Type.GetType ("SparkleLib." + backend + ".SparkleFetcher, SparkleLib." + backend),
|
||||
address, required_fingerprint, remote_path, tmp_folder, fetch_prior_history
|
||||
);
|
||||
Type.GetType ("SparkleLib." + backend + ".SparkleFetcher, SparkleLib." + backend), info);
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleLogger.LogInfo ("Controller",
|
||||
"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 + "\""});
|
||||
|
||||
return;
|
||||
|
@ -689,8 +674,12 @@ namespace SparkleShare {
|
|||
this.config.AddFolder (target_folder_name, this.fetcher.Identifier,
|
||||
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 ());
|
||||
|
||||
AddRepository (target_folder_path);
|
||||
|
|
|
@ -371,11 +371,15 @@ namespace SparkleShare {
|
|||
Program.Controller.FolderFetchError += AddPageFetchErrorDelegate;
|
||||
Program.Controller.FolderFetching += SyncingPageFetchingDelegate;
|
||||
|
||||
new Thread (() => {
|
||||
Program.Controller.StartFetcher (address, SelectedPlugin.Fingerprint, remote_path,
|
||||
SelectedPlugin.AnnouncementsUrl, this.fetch_prior_history);
|
||||
SparkleFetcherInfo info = new SparkleFetcherInfo {
|
||||
Address = address,
|
||||
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
|
||||
|
@ -448,9 +452,7 @@ namespace SparkleShare {
|
|||
|
||||
new Thread (() => {
|
||||
if (!PendingInvite.Accept (Program.Controller.CurrentUser.PublicKey)) {
|
||||
PreviousUrl = PendingInvite.Address +
|
||||
PendingInvite.RemotePath.TrimStart ("/".ToCharArray ());
|
||||
|
||||
PreviousUrl = PendingInvite.Address + PendingInvite.RemotePath.TrimStart ("/".ToCharArray ());
|
||||
ChangePageEvent (PageType.Error, new string [] { "error: Failed to upload the public key" });
|
||||
return;
|
||||
}
|
||||
|
@ -459,8 +461,15 @@ namespace SparkleShare {
|
|||
Program.Controller.FolderFetchError += InvitePageFetchErrorDelegate;
|
||||
Program.Controller.FolderFetching += SyncingPageFetchingDelegate;
|
||||
|
||||
Program.Controller.StartFetcher (PendingInvite.Address, PendingInvite.Fingerprint,
|
||||
PendingInvite.RemotePath, PendingInvite.AnnouncementsUrl, false); // TODO: checkbox on invite page
|
||||
SparkleFetcherInfo info = new SparkleFetcherInfo {
|
||||
Address = PendingInvite.Address,
|
||||
Fingerprint = PendingInvite.Fingerprint,
|
||||
RemotePath = PendingInvite.RemotePath,
|
||||
FetchPriorHistory = false, // TODO: checkbox on invite page
|
||||
AnnouncementsUrl = PendingInvite.AnnouncementsUrl
|
||||
};
|
||||
|
||||
Program.Controller.StartFetcher (info);
|
||||
|
||||
}).Start ();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue