Skip to content

Commit

Permalink
keys: don't be anal about key file names and use all available keys
Browse files Browse the repository at this point in the history
  • Loading branch information
hbons committed Jul 17, 2012
1 parent ccc0262 commit 6603a18
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 49 deletions.
34 changes: 15 additions & 19 deletions SparkleShare/SparkleControllerBase.cs
Expand Up @@ -200,31 +200,27 @@ public virtual void Initialize ()
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 ();
}

Expand Down
47 changes: 22 additions & 25 deletions SparkleShare/SparkleSetupController.cs
Expand Up @@ -281,22 +281,21 @@ public void SetupPageCompleted (string full_name, string email)
{
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;

Expand Down Expand Up @@ -421,12 +420,11 @@ public void AddPageCompleted (string address, string remote_path)
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
Expand Down Expand Up @@ -602,12 +600,11 @@ public void CryptoPasswordPageCompleted (string password)
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 ();
}


Expand Down
9 changes: 4 additions & 5 deletions SparkleShare/SparkleStatusIconController.cs
Expand Up @@ -254,11 +254,10 @@ public void AddHostedProjectClicked ()

public void OpenRecentEventsClicked ()
{
new Threading.Thread (
new Threading.ThreadStart (delegate {
Program.Controller.ShowEventLogWindow ();
})
).Start ();
new Threading.Thread (() => {
Program.Controller.ShowEventLogWindow ();
}).Start ();
}


Expand Down

0 comments on commit 6603a18

Please sign in to comment.