Fix configuration issues
This commit is contained in:
parent
8b887d9b76
commit
865582eef6
|
@ -19,6 +19,7 @@ using System;
|
|||
namespace SparkleLib {
|
||||
|
||||
public class Defines {
|
||||
|
||||
public const string VERSION = "@VERSION@";
|
||||
public const string LOCALE_DIR = "@prefix@/share/locale";
|
||||
public const string DATAROOTDIR = "@expanded_datadir@";
|
||||
|
|
|
@ -302,7 +302,7 @@ namespace SparkleLib {
|
|||
|
||||
// Append a timestamp to local version
|
||||
string timestamp = DateTime.Now.ToString ("HH:mm MMM d");
|
||||
string their_path = conflicting_path + " (" + UserName + ", " + timestamp + ")";
|
||||
string their_path = conflicting_path + " (" + SparkleConfig.DefaultConfig.UserName + ", " + timestamp + ")";
|
||||
string abs_conflicting_path = Path.Combine (LocalPath, conflicting_path);
|
||||
string abs_their_path = Path.Combine (LocalPath, their_path);
|
||||
|
||||
|
|
|
@ -20,26 +20,65 @@ using System.IO;
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
||||
using Mono.Unix;
|
||||
|
||||
namespace SparkleLib {
|
||||
|
||||
public class SparkleConfig : XmlDocument {
|
||||
|
||||
public static SparkleConfig DefaultConfig = new SparkleConfig (
|
||||
System.IO.Path.Combine (SparklePaths.SparkleConfigPath, "config.xml"));
|
||||
SparklePaths.SparkleConfigPath, "config.xml");
|
||||
|
||||
public string Path;
|
||||
|
||||
|
||||
public SparkleConfig (string path)
|
||||
public SparkleConfig (string config_path, string config_file_name)
|
||||
{
|
||||
if (!File.Exists (path))
|
||||
throw new ConfigFileNotFoundException (path + " does not exist");
|
||||
Path = System.IO.Path.Combine (config_path, config_file_name);
|
||||
|
||||
if (!Directory.Exists (config_path)) {
|
||||
Directory.CreateDirectory (config_path);
|
||||
SparkleHelpers.DebugInfo ("Config", "Created \"" + config_path + "\"");
|
||||
}
|
||||
|
||||
string icons_path = System.IO.Path.Combine (config_path, "icons");
|
||||
if (!Directory.Exists (icons_path)) {
|
||||
Directory.CreateDirectory (icons_path);
|
||||
SparkleHelpers.DebugInfo ("Config", "Created '" + icons_path + "'");
|
||||
}
|
||||
|
||||
if (!File.Exists (Path))
|
||||
CreateInitialConfig ();
|
||||
|
||||
Path = path;
|
||||
Load (Path);
|
||||
}
|
||||
|
||||
|
||||
private void CreateInitialConfig ()
|
||||
{
|
||||
string user_name = new UnixUserInfo (UnixEnvironment.UserName).RealName;
|
||||
|
||||
if (string.IsNullOrEmpty (user_name))
|
||||
user_name = "";
|
||||
else
|
||||
user_name = user_name.TrimEnd (",".ToCharArray());
|
||||
|
||||
TextWriter writer = new StreamWriter (Path);
|
||||
string n = Environment.NewLine;
|
||||
|
||||
writer.Write ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + n +
|
||||
"<sparkleshare>" + n +
|
||||
" <user>" + n +
|
||||
" <name>" + user_name + "</name>" + n +
|
||||
" <email>Unknown</email>" + n +
|
||||
" </user>" + n +
|
||||
"</sparkleshare>");
|
||||
writer.Close ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("Config", "Created \"" + Path + "\"");
|
||||
}
|
||||
|
||||
|
||||
public string UserName {
|
||||
get {
|
||||
XmlNode node = SelectSingleNode ("/sparkleshare/user/name/text()");
|
||||
|
@ -57,12 +96,12 @@ namespace SparkleLib {
|
|||
|
||||
public string UserEmail {
|
||||
get {
|
||||
XmlNode node = SelectSingleNode ("/sparkleshare/user/name/email()");
|
||||
XmlNode node = SelectSingleNode ("/sparkleshare/user/email/text()");
|
||||
return node.Value;
|
||||
}
|
||||
|
||||
set {
|
||||
XmlNode node = SelectSingleNode ("/sparkleshare/user/name/email()");
|
||||
XmlNode node = SelectSingleNode ("/sparkleshare/user/email/text()");
|
||||
node.InnerText = value;
|
||||
|
||||
Save ();
|
||||
|
@ -70,14 +109,14 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
public string [] Folders {
|
||||
public List<string> Folders {
|
||||
get {
|
||||
List<string> folders = new List<string> ();
|
||||
|
||||
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder"))
|
||||
folders.Add (node_folder ["name"].InnerText);
|
||||
|
||||
return folders.ToArray ();
|
||||
return folders;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,12 +174,44 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
public string GetConfigOption (string name)
|
||||
{
|
||||
XmlNode node = SelectSingleNode ("/sparkleshare/" + name);
|
||||
|
||||
if (node != null)
|
||||
return node.InnerText;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void SetConfigOption (string name, string content)
|
||||
{
|
||||
XmlNode node = SelectSingleNode ("/sparkleshare/" + name);
|
||||
|
||||
if (node != null) {
|
||||
node.InnerText = content;
|
||||
|
||||
} else {
|
||||
node = CreateElement (name);
|
||||
node.InnerText = content;
|
||||
|
||||
XmlNode node_root = SelectSingleNode ("/sparkleshare");
|
||||
node_root.AppendChild (node);
|
||||
}
|
||||
|
||||
SparkleHelpers.DebugInfo ("Config", "Updated " + name + ":" + content);
|
||||
Save ();
|
||||
}
|
||||
|
||||
|
||||
public void Save ()
|
||||
{
|
||||
if (!File.Exists (Path))
|
||||
throw new ConfigFileNotFoundException (Path + " does not exist");
|
||||
|
||||
Save (Path);
|
||||
SparkleHelpers.DebugInfo ("Config", "Updated \"" + Path + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,4 +221,4 @@ namespace SparkleLib {
|
|||
public ConfigFileNotFoundException (string message) :
|
||||
base (message) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -451,22 +451,6 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
protected string UserName
|
||||
{
|
||||
get {
|
||||
return SparkleConfig.DefaultConfig.UserName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected string UserEmail
|
||||
{
|
||||
get {
|
||||
return SparkleConfig.DefaultConfig.UserEmail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Recursively gets a folder's size in bytes
|
||||
private double CalculateFolderSize (DirectoryInfo parent)
|
||||
{
|
||||
|
|
|
@ -35,7 +35,6 @@ namespace SparkleShare {
|
|||
|
||||
public List <SparkleRepoBase> Repositories;
|
||||
public string FolderSize;
|
||||
public bool FirstRun;
|
||||
public readonly string SparklePath;
|
||||
|
||||
public event OnQuitWhileSyncingEventHandler OnQuitWhileSyncing;
|
||||
|
@ -106,22 +105,14 @@ namespace SparkleShare {
|
|||
|
||||
FolderSize = GetFolderSize ();
|
||||
|
||||
string global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config.xml");
|
||||
// TODO: Legacy. Remove at some later point
|
||||
string old_global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config");
|
||||
if (File.Exists (old_global_config_file_path))
|
||||
MigrateConfig ();
|
||||
|
||||
// Show the introduction screen if SparkleShare isn't configured
|
||||
if (!File.Exists (global_config_file_path)) {
|
||||
if (File.Exists (old_global_config_file_path)) {
|
||||
MigrateConfig ();
|
||||
FirstRun = false;
|
||||
|
||||
} else {
|
||||
WriteDefaultConfig ("Unknown", "");
|
||||
FirstRun = true;
|
||||
}
|
||||
|
||||
if (FirstRun) {
|
||||
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
|
||||
} else {
|
||||
FirstRun = false;
|
||||
AddKey ();
|
||||
}
|
||||
|
||||
|
@ -165,13 +156,19 @@ namespace SparkleShare {
|
|||
}
|
||||
};
|
||||
|
||||
CreateConfigurationFolders ();
|
||||
new Thread (new ThreadStart (PopulateRepositories)).Start ();
|
||||
}
|
||||
|
||||
|
||||
// TODO: remove this later
|
||||
private void MigrateConfig () {
|
||||
public bool FirstRun {
|
||||
get {
|
||||
return SparkleConfig.DefaultConfig.UserEmail.Equals ("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void MigrateConfig ()
|
||||
{
|
||||
string old_global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config");
|
||||
|
||||
StreamReader reader = new StreamReader (old_global_config_file_path);
|
||||
|
@ -188,7 +185,8 @@ namespace SparkleShare {
|
|||
|
||||
string user_email = match.Groups [1].Value;
|
||||
|
||||
WriteDefaultConfig (user_name, user_email);
|
||||
SparkleConfig.DefaultConfig.UserName = user_name;
|
||||
SparkleConfig.DefaultConfig.UserEmail = user_email;
|
||||
|
||||
File.Delete (old_global_config_file_path);
|
||||
}
|
||||
|
@ -229,12 +227,7 @@ namespace SparkleShare {
|
|||
|
||||
public List<string> Folders {
|
||||
get {
|
||||
List<string> folders = new List <string> ();
|
||||
|
||||
foreach (SparkleRepoBase repo in Repositories)
|
||||
folders.Add (repo.LocalPath);
|
||||
|
||||
return folders;
|
||||
return SparkleConfig.DefaultConfig.Folders;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,34 +408,6 @@ namespace SparkleShare {
|
|||
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log);
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
// Creates a folder in the user's home folder to store configuration
|
||||
private void CreateConfigurationFolders ()
|
||||
{
|
||||
if (!Directory.Exists (SparklePaths.SparkleTmpPath))
|
||||
Directory.CreateDirectory (SparklePaths.SparkleTmpPath);
|
||||
|
||||
string config_path = SparklePaths.SparkleConfigPath;
|
||||
string local_icon_path = SparklePaths.SparkleLocalIconPath;
|
||||
|
||||
if (!Directory.Exists (config_path)) {
|
||||
|
||||
// Create a folder to store settings
|
||||
Directory.CreateDirectory (config_path);
|
||||
SparkleHelpers.DebugInfo ("Config", "Created '" + config_path + "'");
|
||||
|
||||
// Create a folder to store the avatars
|
||||
Directory.CreateDirectory (local_icon_path);
|
||||
SparkleHelpers.DebugInfo ("Config", "Created '" + local_icon_path + "'");
|
||||
|
||||
string notify_setting_file = SparkleHelpers.CombineMore (config_path, "sparkleshare.notify");
|
||||
|
||||
// Enable notifications by default
|
||||
if (!File.Exists (notify_setting_file))
|
||||
File.Create (notify_setting_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Creates a .desktop entry in autostart folder to
|
||||
|
@ -604,22 +569,29 @@ namespace SparkleShare {
|
|||
|
||||
public bool NotificationsEnabled {
|
||||
get {
|
||||
string notify_setting_file_path = Path.Combine (SparklePaths.SparkleConfigPath,
|
||||
"sparkleshare.notify");
|
||||
string notifications_enabled =
|
||||
SparkleConfig.DefaultConfig.GetConfigOption ("notifications");
|
||||
|
||||
return File.Exists (notify_setting_file_path);
|
||||
if (String.IsNullOrEmpty (notifications_enabled)) {
|
||||
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return notifications_enabled.Equals (bool.TrueString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ToggleNotifications () {
|
||||
string notify_setting_file_path = Path.Combine (SparklePaths.SparkleConfigPath,
|
||||
"sparkleshare.notify");
|
||||
|
||||
if (File.Exists (notify_setting_file_path))
|
||||
File.Delete (notify_setting_file_path);
|
||||
bool notifications_enabled =
|
||||
SparkleConfig.DefaultConfig.GetConfigOption ("notifications")
|
||||
.Equals (bool.TrueString);
|
||||
|
||||
if (notifications_enabled)
|
||||
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.FalseString);
|
||||
else
|
||||
File.Create (notify_setting_file_path);
|
||||
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
|
||||
}
|
||||
|
||||
|
||||
|
@ -768,31 +740,7 @@ namespace SparkleShare {
|
|||
public string UserEmail
|
||||
{
|
||||
get {
|
||||
string global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config.xml");
|
||||
|
||||
if (File.Exists (global_config_file_path)) {
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.Load (global_config_file_path);
|
||||
|
||||
XmlNode node = xml.SelectSingleNode("//user/email/text()");
|
||||
return node.Value;
|
||||
|
||||
} else {
|
||||
string keys_path = SparklePaths.SparkleKeysPath;
|
||||
|
||||
if (!Directory.Exists (keys_path))
|
||||
return "";
|
||||
|
||||
foreach (string file_path in Directory.GetFiles (keys_path)) {
|
||||
Regex regex = new Regex (@"sparkleshare\.(.+)\.key");
|
||||
Match match = regex.Match (Path.GetFileName (file_path));
|
||||
|
||||
if (match.Success)
|
||||
return match.Groups [1].Value;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
return SparkleConfig.DefaultConfig.UserEmail;
|
||||
}
|
||||
|
||||
set {
|
||||
|
@ -800,26 +748,6 @@ namespace SparkleShare {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void WriteDefaultConfig (string user_name, string user_email)
|
||||
{
|
||||
string global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config.xml");
|
||||
|
||||
// Write the user's information to a text file
|
||||
TextWriter writer = new StreamWriter (global_config_file_path);
|
||||
string n = Environment.NewLine;
|
||||
writer.WriteLine ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + n +
|
||||
"<sparkleshare>" + n +
|
||||
" <user>" + n +
|
||||
" <name>" + user_name + "</name>" + n +
|
||||
" <email>" + user_email + "</email>" + n +
|
||||
" </user>" + n +
|
||||
"</sparkleshare>" + n);
|
||||
writer.Close ();
|
||||
|
||||
SparkleHelpers.DebugInfo ("Config", "Updated '" + global_config_file_path + "'");
|
||||
}
|
||||
|
||||
|
||||
// Generates and installs an RSA keypair to identify this system
|
||||
public void GenerateKeyPair ()
|
||||
|
|
|
@ -78,22 +78,17 @@ namespace SparkleShare {
|
|||
RowSpacing = 6
|
||||
};
|
||||
|
||||
string full_name = new UnixUserInfo (UnixEnvironment.UserName).RealName;
|
||||
if (string.IsNullOrEmpty (full_name))
|
||||
full_name = "";
|
||||
|
||||
Label name_label = new Label ("<b>" + _("Full Name:") + "</b>") {
|
||||
UseMarkup = true,
|
||||
Xalign = 0
|
||||
};
|
||||
|
||||
NameEntry = new Entry (full_name.TrimEnd (",".ToCharArray()));
|
||||
NameEntry = new Entry (SparkleShare.Controller.UserName);
|
||||
NameEntry.Changed += delegate {
|
||||
CheckAccountForm ();
|
||||
};
|
||||
|
||||
|
||||
EmailEntry = new Entry (SparkleShare.Controller.UserEmail);
|
||||
EmailEntry = new Entry ();
|
||||
EmailEntry.Changed += delegate {
|
||||
CheckAccountForm ();
|
||||
};
|
||||
|
@ -128,7 +123,6 @@ namespace SparkleShare {
|
|||
SparkleShare.Controller.GenerateKeyPair ();
|
||||
SparkleShare.Controller.AddKey ();
|
||||
|
||||
SparkleShare.Controller.FirstRun = false;
|
||||
SparkleUI.StatusIcon.CreateMenu ();
|
||||
|
||||
Deletable = true;
|
||||
|
|
|
@ -131,9 +131,6 @@ namespace SparkleShare {
|
|||
Directory.CreateDirectory (SparklePaths.SparklePath);
|
||||
SparkleHelpers.DebugInfo ("Controller", "Created '" + SparklePaths.SparklePath + "'");
|
||||
|
||||
string icon_file_path = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "icons", "hicolor",
|
||||
"48x48", "apps", "folder-sparkleshare.png");
|
||||
|
||||
string gvfs_command_path = SparkleHelpers.CombineMore (Path.VolumeSeparatorChar.ToString (),
|
||||
"usr", "bin", "gvfs-set-attribute");
|
||||
|
||||
|
|
Loading…
Reference in a new issue