2011-10-01 21:15:46 +00:00
|
|
|
// SparkleShare, a collaboration and sharing tool.
|
2017-07-23 12:47:54 +00:00
|
|
|
// Copyright (C) 2010 Hylke Bons (hi@planetpeanut.uk)
|
2011-10-01 21:15:46 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see (http://www.gnu.org/licenses/).
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Xml;
|
2018-02-18 14:16:33 +00:00
|
|
|
using System.Xml.Linq;
|
2011-10-01 21:15:46 +00:00
|
|
|
|
2012-07-18 21:12:51 +00:00
|
|
|
using IO = System.IO;
|
|
|
|
|
2016-04-01 08:15:47 +00:00
|
|
|
namespace Sparkles {
|
2011-10-01 21:15:46 +00:00
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
public class Preset : XmlDocument {
|
2011-10-01 21:15:46 +00:00
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
public static string PresetsPath = "";
|
2012-03-01 23:56:44 +00:00
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
public static string LocalPresetsPath = IO.Path.Combine (
|
2018-01-06 11:24:24 +00:00
|
|
|
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), "org.sparkleshare.SparkleShare", "presets");
|
2012-03-01 23:56:44 +00:00
|
|
|
|
2012-12-02 17:36:37 +00:00
|
|
|
new public string Name { get { return GetValue ("info", "name"); } }
|
2012-07-28 16:13:50 +00:00
|
|
|
public string Description { get { return GetValue ("info", "description"); } }
|
|
|
|
public string Backend { get { return GetValue ("info", "backend"); } }
|
|
|
|
public string Fingerprint { get { return GetValue ("info", "fingerprint"); } }
|
|
|
|
public string AnnouncementsUrl { get { return GetValue ("info", "announcements_url"); } }
|
|
|
|
public string Address { get { return GetValue ("address", "value"); } }
|
|
|
|
public string AddressExample { get { return GetValue ("address", "example"); } }
|
|
|
|
public string Path { get { return GetValue ("path", "value"); } }
|
|
|
|
public string PathExample { get { return GetValue ("path", "example"); } }
|
2011-10-01 21:15:46 +00:00
|
|
|
|
2012-02-08 13:51:07 +00:00
|
|
|
public string ImagePath {
|
|
|
|
get {
|
2012-03-01 23:56:44 +00:00
|
|
|
string image_file_name = GetValue ("info", "icon");
|
2016-03-31 08:35:26 +00:00
|
|
|
string image_path = IO.Path.Combine (preset_directory, image_file_name);
|
2013-03-23 17:48:47 +00:00
|
|
|
|
2012-07-18 21:12:51 +00:00
|
|
|
if (IO.File.Exists (image_path))
|
2012-03-01 23:56:44 +00:00
|
|
|
return image_path;
|
2016-03-31 08:35:26 +00:00
|
|
|
|
|
|
|
return IO.Path.Combine (PresetsPath, image_file_name);
|
2012-02-08 13:51:07 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-20 22:25:36 +00:00
|
|
|
|
2012-03-25 17:00:54 +00:00
|
|
|
public bool PathUsesLowerCase {
|
2012-03-23 15:33:48 +00:00
|
|
|
get {
|
2012-03-25 17:00:54 +00:00
|
|
|
string uses_lower_case = GetValue ("path", "uses_lower_case");
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty (uses_lower_case))
|
|
|
|
return uses_lower_case.Equals (bool.TrueString);
|
2012-03-23 15:33:48 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-23 15:31:18 +00:00
|
|
|
}
|
2012-03-01 23:56:44 +00:00
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
string preset_directory;
|
2011-10-01 21:15:46 +00:00
|
|
|
|
2012-08-29 12:06:46 +00:00
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
public Preset (string preset_path)
|
2012-02-08 13:51:07 +00:00
|
|
|
{
|
2016-03-31 08:35:26 +00:00
|
|
|
preset_directory = IO.Path.GetDirectoryName (preset_path);
|
|
|
|
Load (preset_path);
|
2012-02-08 13:51:07 +00:00
|
|
|
}
|
2011-10-01 21:15:46 +00:00
|
|
|
|
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
public static Preset Create (string name, string description, string address_value,
|
2012-03-01 23:56:44 +00:00
|
|
|
string address_example, string path_value, string path_example)
|
|
|
|
{
|
2016-03-31 08:35:26 +00:00
|
|
|
string preset_path = IO.Path.Combine (LocalPresetsPath, name + ".xml");
|
2012-03-01 23:56:44 +00:00
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
if (IO.File.Exists (preset_path))
|
2012-03-01 23:56:44 +00:00
|
|
|
return null;
|
|
|
|
|
2018-02-18 14:16:33 +00:00
|
|
|
string icon_name = "own-server.png";
|
|
|
|
|
|
|
|
XElement xml =
|
|
|
|
new XElement ("sparkleshare",
|
|
|
|
new XElement ("preset",
|
|
|
|
new XElement ("info",
|
|
|
|
new XElement ("name", name),
|
|
|
|
new XElement ("description", description),
|
|
|
|
new XElement ("icon", icon_name)
|
|
|
|
),
|
|
|
|
new XElement ("address",
|
|
|
|
new XElement ("value", address_value),
|
|
|
|
new XElement ("example", address_example)
|
|
|
|
),
|
|
|
|
new XElement ("path",
|
|
|
|
new XElement ("value", path_value),
|
|
|
|
new XElement ("example", path_example)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2012-03-01 23:56:44 +00:00
|
|
|
|
2016-03-31 08:35:26 +00:00
|
|
|
if (!IO.Directory.Exists (LocalPresetsPath))
|
|
|
|
IO.Directory.CreateDirectory (LocalPresetsPath);
|
2012-03-01 23:56:44 +00:00
|
|
|
|
2018-02-18 14:16:33 +00:00
|
|
|
IO.File.WriteAllText (preset_path, xml.ToString ());
|
2016-03-31 08:35:26 +00:00
|
|
|
return new Preset (preset_path);
|
2012-03-01 23:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-08 13:51:07 +00:00
|
|
|
private string GetValue (string a, string b)
|
|
|
|
{
|
2016-03-31 08:35:26 +00:00
|
|
|
XmlNode node = SelectSingleNode ("/sparkleshare/preset/" + a + "/" + b + "/text()");
|
2011-10-01 21:15:46 +00:00
|
|
|
|
2012-03-01 23:56:44 +00:00
|
|
|
if (node != null && !string.IsNullOrEmpty (node.Value))
|
2012-02-08 13:51:07 +00:00
|
|
|
return node.Value;
|
|
|
|
else
|
|
|
|
return null;
|
2011-10-01 21:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-31 08:35:26 +00:00
|
|
|
}
|