This commit is contained in:
Hylke Bons 2016-04-06 10:12:49 +01:00
parent b9e3c769d9
commit 013a8bff64
6 changed files with 44 additions and 48 deletions

View file

@ -112,7 +112,7 @@ namespace Sparkles {
return this.identifier; return this.identifier;
} else { } else {
string config_identifier = this.local_config.GetIdentifierForFolder (Name); string config_identifier = this.local_config.IdentifierByName (Name);
if (!string.IsNullOrEmpty (config_identifier)) if (!string.IsNullOrEmpty (config_identifier))
this.identifier = config_identifier; this.identifier = config_identifier;
@ -160,7 +160,7 @@ namespace Sparkles {
this.local_config = config; this.local_config = config;
LocalPath = path; LocalPath = path;
Name = Path.GetFileName (LocalPath); Name = Path.GetFileName (LocalPath);
RemoteUrl = new Uri (this.local_config.GetUrlForFolder (Name)); RemoteUrl = new Uri (this.local_config.UrlByName (Name));
IsBuffering = false; IsBuffering = false;
this.identifier = Identifier; this.identifier = Identifier;
ChangeSets = GetChangeSets (); ChangeSets = GetChangeSets ();

View file

@ -83,7 +83,7 @@ namespace Sparkles {
return Path.Combine (custom_path, Name); return Path.Combine (custom_path, Name);
return Path.Combine (Configuration.DefaultConfig.FoldersPath, return Path.Combine (Configuration.DefaultConfig.FoldersPath,
new Uri (Configuration.DefaultConfig.GetUrlForFolder (Name)).Host, new Uri (Configuration.DefaultConfig.UrlByName (Name)).Host,
Name); Name);
} }
} }

View file

@ -36,8 +36,8 @@ namespace Sparkles {
get { get {
if (InstallationInfo.Platform == PlatformID.Win32NT) if (InstallationInfo.Platform == PlatformID.Win32NT)
return Environment.GetFolderPath (Environment.SpecialFolder.UserProfile); return Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
else
return Environment.GetFolderPath (Environment.SpecialFolder.Personal); return Environment.GetFolderPath (Environment.SpecialFolder.Personal);
} }
} }
@ -46,8 +46,8 @@ namespace Sparkles {
get { get {
if (GetConfigOption ("folders_path") != null) if (GetConfigOption ("folders_path") != null)
return GetConfigOption ("folders_path"); return GetConfigOption ("folders_path");
else
return Path.Combine (HomePath, "SparkleShare"); return Path.Combine (HomePath, "SparkleShare");
} }
} }
@ -79,7 +79,7 @@ namespace Sparkles {
Directory.CreateDirectory (config_path); Directory.CreateDirectory (config_path);
try { try {
Load (FullPath); Load (FullPath);
} catch (TypeInitializationException) { } catch (TypeInitializationException) {
CreateInitialConfig (); CreateInitialConfig ();
@ -88,7 +88,7 @@ namespace Sparkles {
CreateInitialConfig (); CreateInitialConfig ();
} catch (XmlException) { } catch (XmlException) {
FileInfo file = new FileInfo (FullPath); var file = new FileInfo (FullPath);
if (file.Length == 0) { if (file.Length == 0) {
File.Delete (FullPath); File.Delete (FullPath);
@ -106,21 +106,17 @@ namespace Sparkles {
} }
private void CreateInitialConfig () void CreateInitialConfig ()
{ {
string user_name = "Unknown"; string user_name = Environment.UserName;
if (InstallationInfo.Platform == PlatformID.Unix || if (InstallationInfo.Platform == PlatformID.Unix ||
InstallationInfo.Platform == PlatformID.MacOSX) { InstallationInfo.Platform == PlatformID.MacOSX) {
user_name = Environment.UserName;
if (string.IsNullOrEmpty (user_name)) if (string.IsNullOrEmpty (user_name))
user_name = "Unknown"; user_name = "Unknown";
else else
user_name = user_name.TrimEnd (",".ToCharArray ()); user_name = user_name.TrimEnd (',');
} else {
user_name = Environment.UserName;
} }
// TODO: Don't do this manually // TODO: Don't do this manually
@ -139,23 +135,15 @@ namespace Sparkles {
public User User { public User User {
get { get {
XmlNode name_node = SelectSingleNode ("/sparkleshare/user/name/text()"); string name = SelectSingleNode ("/sparkleshare/user/name/text()").Value;
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()"); string email = SelectSingleNode ("/sparkleshare/user/email/text()").Value;
string name = name_node.Value;
string email = email_node.Value;
return new User (name, email); return new User (name, email);
} }
set { set {
User user = (User) value; SelectSingleNode ("/sparkleshare/user/name/text()").InnerText = value.Name;
SelectSingleNode ("/sparkleshare/user/email/text()").InnerText = value.Email;
XmlNode name_node = SelectSingleNode ("/sparkleshare/user/name/text()");
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
name_node.InnerText = user.Name;
email_node.InnerText = user.Email;
Save (); Save ();
} }
@ -164,13 +152,12 @@ namespace Sparkles {
public List<string> Folders { public List<string> Folders {
get { get {
List<string> folders = new List<string> (); var folders = new List<string> ();
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder")) foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder"))
folders.Add (node_folder ["name"].InnerText); folders.Add (node_folder ["name"].InnerText);
folders.Sort (); folders.Sort ();
return folders; return folders;
} }
} }
@ -213,31 +200,31 @@ namespace Sparkles {
} }
public void RenameFolder (string identifier, string name) public void RenameFolder (string identifier, string new_name)
{ {
XmlNode node_folder = SelectSingleNode ( XmlNode node_folder = SelectSingleNode (
string.Format ("/sparkleshare/folder[identifier=\"{0}\"]", identifier)); string.Format ("/sparkleshare/folder[identifier=\"{0}\"]", identifier));
node_folder ["name"].InnerText = name; node_folder ["name"].InnerText = new_name;
Save (); Save ();
} }
public string GetBackendForFolder (string name) public string BackendByName (string name)
{ {
return GetFolderValue (name, "backend"); return FolderValueByKey (name, "backend");
} }
public string GetIdentifierForFolder (string name) public string IdentifierByName (string name)
{ {
return GetFolderValue (name, "identifier"); return FolderValueByKey (name, "identifier");
} }
public string GetUrlForFolder (string name) public string UrlByName (string name)
{ {
return GetFolderValue (name, "url"); return FolderValueByKey (name, "url");
} }
@ -259,7 +246,7 @@ namespace Sparkles {
public bool SetFolderOptionalAttribute (string folder_name, string key, string value) public bool SetFolderOptionalAttribute (string folder_name, string key, string value)
{ {
XmlNode folder = GetFolder (folder_name); XmlNode folder = FolderByName (folder_name);
if (folder == null) if (folder == null)
return false; return false;
@ -281,7 +268,7 @@ namespace Sparkles {
public string GetFolderOptionalAttribute (string folder_name, string key) public string GetFolderOptionalAttribute (string folder_name, string key)
{ {
XmlNode folder = GetFolder (folder_name); XmlNode folder = FolderByName (folder_name);
if (folder != null) { if (folder != null) {
if (folder [key] != null) if (folder [key] != null)
@ -326,24 +313,24 @@ namespace Sparkles {
} }
private XmlNode GetFolder (string name) XmlNode FolderByName (string name)
{ {
return SelectSingleNode (string.Format ("/sparkleshare/folder[name=\"{0}\"]", name)); return SelectSingleNode (string.Format ("/sparkleshare/folder[name=\"{0}\"]", name));
} }
private string GetFolderValue (string name, string key) string FolderValueByKey (string name, string key)
{ {
XmlNode folder = GetFolder(name); XmlNode folder = FolderByName(name);
if ((folder != null) && (folder [key] != null)) if ((folder != null) && (folder [key] != null))
return folder [key].InnerText; return folder [key].InnerText;
else
return null; return null;
} }
private void Save () void Save ()
{ {
if (!File.Exists (FullPath)) if (!File.Exists (FullPath))
throw new FileNotFoundException (FullPath + " does not exist"); throw new FileNotFoundException (FullPath + " does not exist");

View file

@ -52,10 +52,15 @@ namespace Sparkles.Git {
if (!RemoteUrl.Scheme.Equals ("ssh") && !RemoteUrl.Scheme.Equals ("git")) if (!RemoteUrl.Scheme.Equals ("ssh") && !RemoteUrl.Scheme.Equals ("git"))
uri_builder.Scheme = "ssh"; uri_builder.Scheme = "ssh";
if (RemoteUrl.Host.Equals ("github.com")) { if (RemoteUrl.Host.Equals ("github.com") ||
RemoteUrl.Host.Equals ("gitlab.com")) {
uri_builder.Scheme = "ssh"; uri_builder.Scheme = "ssh";
uri_builder.UserName = "git"; uri_builder.UserName = "git";
if (!RemoteUrl.AbsolutePath.EndsWith (".git"))
uri_builder.Path += ".git";
} else if (string.IsNullOrEmpty (RemoteUrl.UserInfo)) { } else if (string.IsNullOrEmpty (RemoteUrl.UserInfo)) {
uri_builder.UserName = "storage"; uri_builder.UserName = "storage";
} }
@ -273,6 +278,7 @@ namespace Sparkles.Git {
git_config_clean.StartAndWaitForExit (); git_config_clean.StartAndWaitForExit ();
// Pass all files through the encryption filter // Pass all files through the encryption filter
// TODO: diff=encryption merge=encryption -text?
string git_attributes_file_path = Path.Combine (TargetFolder, ".git", "info", "attributes"); string git_attributes_file_path = Path.Combine (TargetFolder, ".git", "info", "attributes");
File.WriteAllText (git_attributes_file_path, "* filter=encryption"); File.WriteAllText (git_attributes_file_path, "* filter=encryption");

View file

@ -81,7 +81,7 @@ namespace Sparkles {
if (IO.File.Exists (preset_path)) if (IO.File.Exists (preset_path))
return null; return null;
// TODO: Don't write maually // TODO: Don't write manually
string preset_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + string preset_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<sparkleshare>" + "<sparkleshare>" +
" <preset>" + " <preset>" +

3
key.text Normal file
View file

@ -0,0 +1,3 @@
gitlab.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bNKTBSpIYDEGk9KxsGh3mySTRgMtXL583qmBpzeQ+jqCMRgBqB98u3z++J1sKlXHWfM9dyhSevkMwSbhoR8XIq/U0tCNyokEi/ueaBMCvbcTHhO7FcwzY92WK4Yt0aGROY5qX2UKSeOvuP4D6TPqKF1onrSzH9bx9XUf2lEdWT/ia1NEKjunUqu1xOB/StKDHMoX4/OKyIzuS0q/T1zOATthvasJFoPrAjkohTyaDUz2LN5JoH839hViyEG82yB+MjcFV5MU3N1l1QL3cVUCh93xSaua1N85qivl+siMkPGbO5xR/En4iEY6K2XPASUEMaieWVNTRCtJ4S8H+9
gitlab.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=
gitlab.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf