From f0640f1982e0aaa26728a1e80139652612f689de Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 9 Oct 2012 14:28:07 +0200 Subject: [PATCH] create a link code on first start, then rename it after the user entered a name --- SparkleShare/SparkleControllerBase.cs | 24 +++++++++++++++++++++++- SparkleShare/SparkleSetupController.cs | 19 ++++++++++--------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 7e3eec39..e25c0f6c 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -200,7 +200,14 @@ namespace SparkleShare { if (!string.IsNullOrEmpty (key_file_path)) { string public_key_file_path = key_file_path + ".pub"; - string link_code_file_path = Path.Combine (FoldersPath, CurrentUser.Name + "'s link code.txt"); + string name = Program.Controller.CurrentUser.Name.Split (" ".ToCharArray ()) [0]; + + if (name.EndsWith ("s")) + name += "'"; + else + name += "'s"; + + string link_code_file_path = Path.Combine (FoldersPath, name + " link code.txt"); // Create an easily accessible copy of the public // key in the user's SparkleShare folder @@ -233,6 +240,21 @@ namespace SparkleShare { if (FirstRun) { ShowSetupWindow (PageType.Setup); + new Thread (() => { + string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath); + string key_file_name = DateTime.Now.ToString ("yyyy-MM-dd HH\\hmm"); + + string [] key_pair = SparkleKeys.GenerateKeyPair (keys_path, key_file_name); + SparkleKeys.ImportPrivateKey (key_pair [0]); + + string link_code_file_path = Path.Combine (Program.Controller.FoldersPath, "Your link code.txt"); + + // Create an easily accessible copy of the public + // key in the user's SparkleShare folder + File.Copy (key_pair [1], link_code_file_path, true); + + }).Start (); + } else { new Thread (() => { CheckRepositories (); diff --git a/SparkleShare/SparkleSetupController.cs b/SparkleShare/SparkleSetupController.cs index 4c7ddbc5..5d17f93e 100755 --- a/SparkleShare/SparkleSetupController.cs +++ b/SparkleShare/SparkleSetupController.cs @@ -237,18 +237,19 @@ namespace SparkleShare { Program.Controller.CurrentUser = new SparkleUser (full_name, email); new Thread (() => { - string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath); - string key_file_name = DateTime.Now.ToString ("yyyy-MM-dd HH\\hmm"); + string link_code_file_path = Path.Combine (Program.Controller.FoldersPath, "Your link code.txt"); - string [] key_pair = SparkleKeys.GenerateKeyPair (keys_path, key_file_name); - SparkleKeys.ImportPrivateKey (key_pair [0]); + if (File.Exists (link_code_file_path)) { + string name = Program.Controller.CurrentUser.Name.Split (" ".ToCharArray ()) [0]; - string link_code_file_path = Path.Combine (Program.Controller.FoldersPath, - Program.Controller.CurrentUser.Name + "'s link code.txt"); + if (name.EndsWith ("s")) + name += "'"; + else + name += "'s"; - // Create an easily accessible copy of the public - // key in the user's SparkleShare folder - File.Copy (key_pair [1], link_code_file_path, true); + string new_file_path = Path.Combine (Program.Controller.FoldersPath, name + " link code.txt"); + File.Move (link_code_file_path, new_file_path); + } }).Start ();