diff --git a/SparkleLib/Defines.cs.in b/SparkleLib/Defines.cs.in
index 2b61dcdb..c6b415e7 100644
--- a/SparkleLib/Defines.cs.in
+++ b/SparkleLib/Defines.cs.in
@@ -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@";
diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs
index ddaa43d8..bc181ae8 100644
--- a/SparkleLib/Git/SparkleRepoGit.cs
+++ b/SparkleLib/Git/SparkleRepoGit.cs
@@ -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);
diff --git a/SparkleLib/SparkleConfig.cs b/SparkleLib/SparkleConfig.cs
index 479f6653..e4132fd8 100644
--- a/SparkleLib/SparkleConfig.cs
+++ b/SparkleLib/SparkleConfig.cs
@@ -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 ("" + n +
+ "" + n +
+ " " + n +
+ " " + user_name + "" + n +
+ " Unknown" + n +
+ " " + n +
+ "");
+ 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 Folders {
get {
List folders = new List ();
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) { }
}
-}
\ No newline at end of file
+}
diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs
index 461b99d8..fe645951 100644
--- a/SparkleLib/SparkleRepoBase.cs
+++ b/SparkleLib/SparkleRepoBase.cs
@@ -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)
{
diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs
index e91bd517..d5744689 100644
--- a/SparkleShare/SparkleController.cs
+++ b/SparkleShare/SparkleController.cs
@@ -35,7 +35,6 @@ namespace SparkleShare {
public List 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 Folders {
get {
- List folders = new List ();
-
- 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);
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 ("" + n +
- "" + n +
- " " + n +
- " " + user_name + "" + n +
- " " + user_email + "" + n +
- " " + n +
- "" + n);
- writer.Close ();
-
- SparkleHelpers.DebugInfo ("Config", "Updated '" + global_config_file_path + "'");
- }
-
// Generates and installs an RSA keypair to identify this system
public void GenerateKeyPair ()
diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs
index 786b6e93..a05c2ab1 100644
--- a/SparkleShare/SparkleIntro.cs
+++ b/SparkleShare/SparkleIntro.cs
@@ -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 ("" + _("Full Name:") + "") {
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;
diff --git a/SparkleShare/SparkleLinController.cs b/SparkleShare/SparkleLinController.cs
index 80cef769..408bfba6 100644
--- a/SparkleShare/SparkleLinController.cs
+++ b/SparkleShare/SparkleLinController.cs
@@ -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");