setup: Create a reusable plugin for each succesfully used host. Closes #547
This commit is contained in:
parent
68d36ef00b
commit
ab9358fcdf
|
@ -145,8 +145,8 @@ namespace SparkleLib.Git {
|
|||
if (percentage >= 100)
|
||||
break;
|
||||
|
||||
Thread.Sleep (500);
|
||||
base.OnProgressChanged (percentage);
|
||||
Thread.Sleep (750);
|
||||
}
|
||||
|
||||
base.OnProgressChanged (100);
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace SparkleShare {
|
|||
|
||||
|
||||
public event FolderFetchedEventHandler FolderFetched;
|
||||
public delegate void FolderFetchedEventHandler (string [] warnings);
|
||||
public delegate void FolderFetchedEventHandler (string remote_url, string [] warnings);
|
||||
|
||||
public event FolderFetchErrorHandler FolderFetchError;
|
||||
public delegate void FolderFetchErrorHandler (string remote_url);
|
||||
|
@ -134,6 +134,7 @@ namespace SparkleShare {
|
|||
|
||||
public virtual void Initialize ()
|
||||
{
|
||||
SparklePlugin.PluginsPath = PluginsPath;
|
||||
InstallProtocolHandler ();
|
||||
|
||||
// Create the SparkleShare folder and add it to the bookmarks
|
||||
|
@ -1057,6 +1058,7 @@ namespace SparkleShare {
|
|||
|
||||
try {
|
||||
Directory.Move (tmp_folder, target_folder_path);
|
||||
|
||||
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, this.fetcher.RemoteUrl, backend);
|
||||
|
||||
if (!string.IsNullOrEmpty (announcements_url)) {
|
||||
|
@ -1064,25 +1066,23 @@ namespace SparkleShare {
|
|||
"announcements_url", announcements_url);
|
||||
}
|
||||
|
||||
|
||||
AddRepository (target_folder_path);
|
||||
|
||||
if (FolderFetched != null)
|
||||
FolderFetched (warnings);
|
||||
FolderFetched (this.fetcher.RemoteUrl, warnings);
|
||||
|
||||
if (FolderListChanged != null)
|
||||
FolderListChanged ();
|
||||
|
||||
this.fetcher.Dispose ();
|
||||
|
||||
if (Directory.Exists (tmp_path))
|
||||
Directory.Delete (tmp_path, true);
|
||||
|
||||
} catch (Exception e) {
|
||||
SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message);
|
||||
}
|
||||
|
||||
this.fetcher.Dispose ();
|
||||
this.fetcher = null;
|
||||
|
||||
if (Directory.Exists (tmp_path))
|
||||
Directory.Delete (tmp_path, true);
|
||||
};
|
||||
|
||||
this.fetcher.Failed += delegate {
|
||||
|
|
|
@ -16,12 +16,20 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
namespace SparkleShare {
|
||||
|
||||
public class SparklePlugin {
|
||||
|
||||
public static string PluginsPath = "";
|
||||
|
||||
public static string LocalPluginsPath =
|
||||
new string [] { Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
|
||||
"sparkleshare", "plugins" }.Combine ();
|
||||
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return GetValue ("info", "name");
|
||||
|
@ -36,10 +44,18 @@ namespace SparkleShare {
|
|||
|
||||
public string ImagePath {
|
||||
get {
|
||||
return System.IO.Path.Combine (
|
||||
string image_file_name = GetValue ("info", "icon");
|
||||
|
||||
string image_path = System.IO.Path.Combine (
|
||||
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 {
|
||||
get {
|
||||
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 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)
|
||||
{
|
||||
XmlNode node = this.xml.SelectSingleNode (
|
||||
"/sparkleshare/plugin/" + a + "/" + b + "/text()");
|
||||
|
||||
if (node != null)
|
||||
if (node != null && !string.IsNullOrEmpty (node.Value))
|
||||
return node.Value;
|
||||
else
|
||||
return null;
|
||||
|
|
|
@ -114,16 +114,18 @@ namespace SparkleShare {
|
|||
PreviousUrl = "";
|
||||
SyncingFolder = "";
|
||||
|
||||
string local_plugins_path = SparkleHelpers.CombineMore (
|
||||
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
|
||||
"sparkleshare", "plugins");
|
||||
string local_plugins_path = SparklePlugin.LocalPluginsPath;
|
||||
|
||||
// Import all of the plugins
|
||||
if (Directory.Exists (local_plugins_path))
|
||||
// Local plugins go first...
|
||||
foreach (string xml_file_path in Directory.GetFiles (local_plugins_path, "*.xml"))
|
||||
Plugins.Add (new SparklePlugin (xml_file_path));
|
||||
|
||||
// ...system plugins after that...
|
||||
if (Directory.Exists (Program.Controller.PluginsPath)) {
|
||||
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"))
|
||||
Plugins.Insert (0, new SparklePlugin (xml_file_path));
|
||||
else
|
||||
|
@ -154,7 +156,6 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
if (page_type == PageType.Add) {
|
||||
|
||||
if (!Program.Controller.FirstRun && TutorialPageNumber == 0) {
|
||||
if (ChangePageEvent != null)
|
||||
ChangePageEvent (page_type, null);
|
||||
|
@ -324,10 +325,32 @@ namespace SparkleShare {
|
|||
// The following private methods are
|
||||
// delegates used by the previous method
|
||||
|
||||
private void AddPageFetchedDelegate (string [] warnings)
|
||||
private void AddPageFetchedDelegate (string remote_url, string [] warnings)
|
||||
{
|
||||
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)
|
||||
ChangePageEvent (PageType.Finished, warnings);
|
||||
|
||||
|
@ -383,7 +406,7 @@ namespace SparkleShare {
|
|||
// The following private methods are
|
||||
// delegates used by the previous method
|
||||
|
||||
private void InvitePageFetchedDelegate (string [] warnings)
|
||||
private void InvitePageFetchedDelegate (string remote_url, string [] warnings)
|
||||
{
|
||||
SyncingFolder = "";
|
||||
PendingInvite = null;
|
||||
|
|
Loading…
Reference in a new issue