Permalink
Browse files

fetcher: simplify some methods

  • Loading branch information...
hbons committed Oct 4, 2012
1 parent b6a6aa6 commit 570c0eb17f73b41451dd4e96df28419e77dd729a
Showing with 20 additions and 33 deletions.
  1. +20 −33 SparkleLib/SparkleFetcherBase.cs
@@ -186,16 +186,15 @@ public virtual void Complete ()
} else {
Identifier = CreateIdentifier ();
File.WriteAllText (identifier_path, Identifier);
- }
- if (IsFetchedRepoEmpty)
CreateInitialChangeSet ();
+ }
}
// Create an initial change set when the
// user has fetched an empty remote folder
- public void CreateInitialChangeSet ()
+ private void CreateInitialChangeSet ()
{
string file_path = Path.Combine (TargetFolder, "SparkleShare.txt");
string n = Environment.NewLine;
@@ -207,7 +206,6 @@ public void CreateInitialChangeSet ()
uri_builder.Password = "";
}
- // TODO: Find better way to determine if folder should have crypto setup
bool repo_is_encrypted = RemoteUrl.ToString ().Contains ("-crypto");
string text;
@@ -237,24 +235,6 @@ public static string CreateIdentifier ()
return random.SHA1 ();
}
-
- public static string GetBackend (string path)
- {
- string extension = Path.GetExtension (path);
-
- if (!string.IsNullOrEmpty (extension)) {
- extension = extension.Substring (1);
- char [] letters = extension.ToCharArray ();
- letters [0] = char.ToUpper (letters [0]);
-
- return new string (letters);
-
- } else {
- return "Git";
- }
- }
-
-
public void Dispose ()
{
if (this.thread != null)
@@ -269,17 +249,7 @@ public void Dispose ()
protected string GenerateCryptoSalt ()
{
- int seed = new Random ().Next (1, int.MaxValue);
- string allowed_chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
- char [] chars = new char [256];
- Random random = new Random (seed);
-
- for (var i = 0; i < 256; i++)
- chars [i] = allowed_chars [random.Next (0, allowed_chars.Length)];
-
- string salt = new string (chars);
- salt = salt.SHA1 ();
-
+ string salt = Path.GetRandomFileName ().SHA1 ();
return salt.Substring (0, 16);
}
@@ -368,5 +338,22 @@ private void AcceptHostKey (string host_key, bool warn)
if (warn)
this.warnings.Add ("The following host key has been accepted:\n" + GetFingerprint (host_key));
}
+
+
+ public static string GetBackend (string path)
+ {
+ string extension = Path.GetExtension (path);
+
+ if (!string.IsNullOrEmpty (extension)) {
+ extension = extension.Substring (1);
+ char [] letters = extension.ToCharArray ();
+ letters [0] = char.ToUpper (letters [0]);
+
+ return new string (letters);
+
+ } else {
+ return "Git";
+ }
+ }
}
}

0 comments on commit 570c0eb

Please sign in to comment.