keys: don't be anal about key file names and use all available keys

This commit is contained in:
Hylke Bons 2012-07-17 12:31:42 +02:00
parent 286cb5dcb6
commit 8ca3bd3b6b
3 changed files with 41 additions and 49 deletions

View file

@ -200,31 +200,27 @@ namespace SparkleShare {
this.config.SetConfigOption ("notifications", bool.TrueString); this.config.SetConfigOption ("notifications", bool.TrueString);
} else { } else {
string keys_path = Path.GetDirectoryName (this.config.FullPath); string keys_path = Path.GetDirectoryName (this.config.FullPath);
string key_file_name = "sparkleshare." + CurrentUser.Email + ".key"; string key_file_path = "";
string key_file_path = Path.Combine (keys_path, key_file_name);
// Be forgiving about the key's file name foreach (string file_name in Directory.GetFiles (keys_path)) {
if (!File.Exists (key_file_path)) { if (file_name.EndsWith (".key")) {
foreach (string file_name in Directory.GetFiles (keys_path)) { key_file_path = Path.Combine (keys_path, file_name);
if (file_name.StartsWith ("sparkleshare") && SparkleKeys.ImportPrivateKey (key_file_path);
file_name.EndsWith (".key")) {
key_file_path = Path.Combine (keys_path, file_name);
break;
}
} }
} }
string pubkey_file_path = key_file_path + ".pub"; if (!string.IsNullOrEmpty (key_file_path)) {
string link_code_file_path = Path.Combine (FoldersPath, CurrentUser.Name + "'s link code.txt"); string pubkey_file_path = key_file_path + ".pub";
string link_code_file_path = Path.Combine (FoldersPath, CurrentUser.Name + "'s link code.txt");
// Create an easily accessible copy of the public // Create an easily accessible copy of the public
// key in the user's SparkleShare folder // key in the user's SparkleShare folder
if (File.Exists (pubkey_file_path) && !File.Exists (link_code_file_path)) if (File.Exists (pubkey_file_path) && !File.Exists (link_code_file_path))
File.Copy (pubkey_file_path, link_code_file_path, true /* Overwriting allowed */ ); File.Copy (pubkey_file_path, link_code_file_path, true /* Overwriting allowed */ );
}
SparkleKeys.ImportPrivateKey (key_file_path);
SparkleKeys.ListPrivateKeys (); SparkleKeys.ListPrivateKeys ();
} }

View file

@ -281,22 +281,21 @@ namespace SparkleShare {
{ {
Program.Controller.CurrentUser = new SparkleUser (full_name, email); Program.Controller.CurrentUser = new SparkleUser (full_name, email);
new Thread ( new Thread (() => {
new ThreadStart (delegate { string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath);
string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath); string key_file_name = DateTime.Now.ToString ("YYYY-MM-dd HH\\hmm");
string key_file_name = "sparkleshare." + Program.Controller.CurrentUser.Email;
string [] key_pair = SparkleKeys.GenerateKeyPair (keys_path, key_file_name); string [] key_pair = SparkleKeys.GenerateKeyPair (keys_path, key_file_name);
SparkleKeys.ImportPrivateKey (key_pair [0]); SparkleKeys.ImportPrivateKey (key_pair [0]);
string link_code_file_path = Path.Combine (Program.Controller.FoldersPath, string link_code_file_path = Path.Combine (Program.Controller.FoldersPath,
Program.Controller.CurrentUser.Name + "'s link code.txt"); Program.Controller.CurrentUser.Name + "'s link code.txt");
// Create an easily accessible copy of the public // Create an easily accessible copy of the public
// key in the user's SparkleShare folder // key in the user's SparkleShare folder
File.Copy (key_pair [1], link_code_file_path, true); File.Copy (key_pair [1], link_code_file_path, true);
})
).Start (); }).Start ();
TutorialPageNumber = 1; TutorialPageNumber = 1;
@ -421,12 +420,11 @@ namespace SparkleShare {
Program.Controller.FolderFetchError += AddPageFetchErrorDelegate; Program.Controller.FolderFetchError += AddPageFetchErrorDelegate;
Program.Controller.FolderFetching += SyncingPageFetchingDelegate; Program.Controller.FolderFetching += SyncingPageFetchingDelegate;
new Thread ( new Thread (() => {
new ThreadStart (delegate { Program.Controller.StartFetcher (address, SelectedPlugin.Fingerprint, remote_path,
Program.Controller.StartFetcher (address, SelectedPlugin.Fingerprint, remote_path, SelectedPlugin.AnnouncementsUrl, this.fetch_prior_history);
SelectedPlugin.AnnouncementsUrl, this.fetch_prior_history);
}) }).Start ();
).Start ();
} }
// The following private methods are // The following private methods are
@ -602,12 +600,11 @@ namespace SparkleShare {
if (ChangePageEvent != null) if (ChangePageEvent != null)
ChangePageEvent (PageType.Syncing, null); ChangePageEvent (PageType.Syncing, null);
new Thread ( new Thread (() => {
new ThreadStart (delegate { Thread.Sleep (1000);
Thread.Sleep (1000); Program.Controller.FinishFetcher (password);
Program.Controller.FinishFetcher (password);
}) }).Start ();
).Start ();
} }

View file

@ -254,11 +254,10 @@ namespace SparkleShare {
public void OpenRecentEventsClicked () public void OpenRecentEventsClicked ()
{ {
new Threading.Thread ( new Threading.Thread (() => {
new Threading.ThreadStart (delegate { Program.Controller.ShowEventLogWindow ();
Program.Controller.ShowEventLogWindow ();
}) }).Start ();
).Start ();
} }