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

View file

@ -281,22 +281,21 @@ namespace SparkleShare {
{
Program.Controller.CurrentUser = new SparkleUser (full_name, email);
new Thread (
new ThreadStart (delegate {
string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath);
string key_file_name = "sparkleshare." + Program.Controller.CurrentUser.Email;
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 [] key_pair = SparkleKeys.GenerateKeyPair (keys_path, key_file_name);
SparkleKeys.ImportPrivateKey (key_pair [0]);
string link_code_file_path = Path.Combine (Program.Controller.FoldersPath,
Program.Controller.CurrentUser.Name + "'s link code.txt");
string link_code_file_path = Path.Combine (Program.Controller.FoldersPath,
Program.Controller.CurrentUser.Name + "'s 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 ();
// 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 ();
TutorialPageNumber = 1;
@ -421,12 +420,11 @@ namespace SparkleShare {
Program.Controller.FolderFetchError += AddPageFetchErrorDelegate;
Program.Controller.FolderFetching += SyncingPageFetchingDelegate;
new Thread (
new ThreadStart (delegate {
Program.Controller.StartFetcher (address, SelectedPlugin.Fingerprint, remote_path,
SelectedPlugin.AnnouncementsUrl, this.fetch_prior_history);
})
).Start ();
new Thread (() => {
Program.Controller.StartFetcher (address, SelectedPlugin.Fingerprint, remote_path,
SelectedPlugin.AnnouncementsUrl, this.fetch_prior_history);
}).Start ();
}
// The following private methods are
@ -602,12 +600,11 @@ namespace SparkleShare {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Syncing, null);
new Thread (
new ThreadStart (delegate {
Thread.Sleep (1000);
Program.Controller.FinishFetcher (password);
})
).Start ();
new Thread (() => {
Thread.Sleep (1000);
Program.Controller.FinishFetcher (password);
}).Start ();
}

View file

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