setup: Create a reusable plugin for each succesfully used host. Closes #547

This commit is contained in:
Hylke Bons 2012-03-01 23:56:44 +00:00
parent 68d36ef00b
commit ab9358fcdf
4 changed files with 105 additions and 27 deletions

View file

@ -145,8 +145,8 @@ namespace SparkleLib.Git {
if (percentage >= 100) if (percentage >= 100)
break; break;
Thread.Sleep (500);
base.OnProgressChanged (percentage); base.OnProgressChanged (percentage);
Thread.Sleep (750);
} }
base.OnProgressChanged (100); base.OnProgressChanged (100);

View file

@ -54,7 +54,7 @@ namespace SparkleShare {
public event FolderFetchedEventHandler FolderFetched; public event FolderFetchedEventHandler FolderFetched;
public delegate void FolderFetchedEventHandler (string [] warnings); public delegate void FolderFetchedEventHandler (string remote_url, string [] warnings);
public event FolderFetchErrorHandler FolderFetchError; public event FolderFetchErrorHandler FolderFetchError;
public delegate void FolderFetchErrorHandler (string remote_url); public delegate void FolderFetchErrorHandler (string remote_url);
@ -134,6 +134,7 @@ namespace SparkleShare {
public virtual void Initialize () public virtual void Initialize ()
{ {
SparklePlugin.PluginsPath = PluginsPath;
InstallProtocolHandler (); InstallProtocolHandler ();
// Create the SparkleShare folder and add it to the bookmarks // Create the SparkleShare folder and add it to the bookmarks
@ -1057,6 +1058,7 @@ namespace SparkleShare {
try { try {
Directory.Move (tmp_folder, target_folder_path); Directory.Move (tmp_folder, target_folder_path);
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, this.fetcher.RemoteUrl, backend); SparkleConfig.DefaultConfig.AddFolder (target_folder_name, this.fetcher.RemoteUrl, backend);
if (!string.IsNullOrEmpty (announcements_url)) { if (!string.IsNullOrEmpty (announcements_url)) {
@ -1064,25 +1066,23 @@ namespace SparkleShare {
"announcements_url", announcements_url); "announcements_url", announcements_url);
} }
AddRepository (target_folder_path); AddRepository (target_folder_path);
if (FolderFetched != null) if (FolderFetched != null)
FolderFetched (warnings); FolderFetched (this.fetcher.RemoteUrl, warnings);
if (FolderListChanged != null) if (FolderListChanged != null)
FolderListChanged (); FolderListChanged ();
this.fetcher.Dispose ();
if (Directory.Exists (tmp_path))
Directory.Delete (tmp_path, true);
} catch (Exception e) { } catch (Exception e) {
SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message); SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message);
} }
this.fetcher.Dispose ();
this.fetcher = null; this.fetcher = null;
if (Directory.Exists (tmp_path))
Directory.Delete (tmp_path, true);
}; };
this.fetcher.Failed += delegate { this.fetcher.Failed += delegate {

View file

@ -16,12 +16,20 @@
using System; using System;
using System.IO;
using System.Xml; using System.Xml;
namespace SparkleShare { namespace SparkleShare {
public class SparklePlugin { public class SparklePlugin {
public static string PluginsPath = "";
public static string LocalPluginsPath =
new string [] { Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"sparkleshare", "plugins" }.Combine ();
public string Name { public string Name {
get { get {
return GetValue ("info", "name"); return GetValue ("info", "name");
@ -36,10 +44,18 @@ namespace SparkleShare {
public string ImagePath { public string ImagePath {
get { get {
return System.IO.Path.Combine ( string image_file_name = GetValue ("info", "icon");
string image_path = System.IO.Path.Combine (
this.plugin_directory, this.plugin_directory,
GetValue ("info", "icon") image_file_name
); );
if (File.Exists (image_path))
return image_path;
else
return System.IO.Path.Combine (
PluginsPath, image_file_name);
} }
} }
@ -49,12 +65,6 @@ namespace SparkleShare {
} }
} }
public string AnnouncementsUrl {
get {
return GetValue ("info", "announcements_url");
}
}
public string Address { public string Address {
get { get {
return GetValue ("address", "value"); return GetValue ("address", "value");
@ -79,6 +89,12 @@ namespace SparkleShare {
} }
} }
public string AnnouncementsUrl {
get {
return GetValue ("info", "announcements_url");
}
}
private XmlDocument xml = new XmlDocument (); private XmlDocument xml = new XmlDocument ();
private string plugin_directory; private string plugin_directory;
@ -90,12 +106,51 @@ namespace SparkleShare {
} }
public static SparklePlugin Create (string name, string description, string address_value,
string address_example, string path_value, string path_example)
{
string plugin_path = System.IO.Path.Combine (LocalPluginsPath, name + ".xml");
if (File.Exists (plugin_path))
return null;
string plugin_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<sparkleshare>" +
" <plugin>" +
" <info>" +
" <name>" + name + "</name>" +
" <description>" + description + "</description>" +
" <icon>own-server.png</icon>" +
" </info>" +
" <address>" +
" <value>" + address_value + "</value>" +
" <example>" + address_example + "</example>" +
" </address>" +
" <path>" +
" <value>" + path_value + "</value>" +
" <example>" + path_example + "</example>" +
" </path>" +
" </plugin>" +
"</sparkleshare>";
plugin_xml = plugin_xml.Replace ("<value></value>", "<value/>");
plugin_xml = plugin_xml.Replace ("<example></example>", "<example/>");
if (!Directory.Exists (LocalPluginsPath))
Directory.CreateDirectory (LocalPluginsPath);
File.WriteAllText (plugin_path, plugin_xml);
return new SparklePlugin (plugin_path);
}
private string GetValue (string a, string b) private string GetValue (string a, string b)
{ {
XmlNode node = this.xml.SelectSingleNode ( XmlNode node = this.xml.SelectSingleNode (
"/sparkleshare/plugin/" + a + "/" + b + "/text()"); "/sparkleshare/plugin/" + a + "/" + b + "/text()");
if (node != null) if (node != null && !string.IsNullOrEmpty (node.Value))
return node.Value; return node.Value;
else else
return null; return null;

View file

@ -114,16 +114,18 @@ namespace SparkleShare {
PreviousUrl = ""; PreviousUrl = "";
SyncingFolder = ""; SyncingFolder = "";
string local_plugins_path = SparkleHelpers.CombineMore ( string local_plugins_path = SparklePlugin.LocalPluginsPath;
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"sparkleshare", "plugins");
// Import all of the plugins
if (Directory.Exists (local_plugins_path)) if (Directory.Exists (local_plugins_path))
// Local plugins go first...
foreach (string xml_file_path in Directory.GetFiles (local_plugins_path, "*.xml")) foreach (string xml_file_path in Directory.GetFiles (local_plugins_path, "*.xml"))
Plugins.Add (new SparklePlugin (xml_file_path)); Plugins.Add (new SparklePlugin (xml_file_path));
// ...system plugins after that...
if (Directory.Exists (Program.Controller.PluginsPath)) { if (Directory.Exists (Program.Controller.PluginsPath)) {
foreach (string xml_file_path in Directory.GetFiles (Program.Controller.PluginsPath, "*.xml")) { foreach (string xml_file_path in Directory.GetFiles (Program.Controller.PluginsPath, "*.xml")) {
// ...and "Own server" at the very top
if (xml_file_path.EndsWith ("own-server.xml")) if (xml_file_path.EndsWith ("own-server.xml"))
Plugins.Insert (0, new SparklePlugin (xml_file_path)); Plugins.Insert (0, new SparklePlugin (xml_file_path));
else else
@ -154,7 +156,6 @@ namespace SparkleShare {
} }
if (page_type == PageType.Add) { if (page_type == PageType.Add) {
if (!Program.Controller.FirstRun && TutorialPageNumber == 0) { if (!Program.Controller.FirstRun && TutorialPageNumber == 0) {
if (ChangePageEvent != null) if (ChangePageEvent != null)
ChangePageEvent (page_type, null); ChangePageEvent (page_type, null);
@ -324,10 +325,32 @@ namespace SparkleShare {
// The following private methods are // The following private methods are
// delegates used by the previous method // delegates used by the previous method
private void AddPageFetchedDelegate (string [] warnings) private void AddPageFetchedDelegate (string remote_url, string [] warnings)
{ {
SyncingFolder = ""; SyncingFolder = "";
// Create a local plugin for succesfully added projects, so
// so the user can easily use the same host again
if (SelectedPluginIndex == 0) {
SparklePlugin new_plugin;
Uri uri = new Uri (remote_url);
try {
string address = remote_url.Replace (uri.AbsolutePath, "");
new_plugin = SparklePlugin.Create (
uri.Host, address, address, "", "", "");
if (new_plugin != null) {
Plugins.Insert (1, new_plugin);
SparkleHelpers.DebugInfo ("Controller", "Added plugin for " + uri.Host);
}
} catch {
SparkleHelpers.DebugInfo ("Controller", "Failed adding plugin for " + uri.Host);
}
}
if (ChangePageEvent != null) if (ChangePageEvent != null)
ChangePageEvent (PageType.Finished, warnings); ChangePageEvent (PageType.Finished, warnings);
@ -383,7 +406,7 @@ namespace SparkleShare {
// The following private methods are // The following private methods are
// delegates used by the previous method // delegates used by the previous method
private void InvitePageFetchedDelegate (string [] warnings) private void InvitePageFetchedDelegate (string remote_url, string [] warnings)
{ {
SyncingFolder = ""; SyncingFolder = "";
PendingInvite = null; PendingInvite = null;