Skip to content

Commit

Permalink
Added try/catch to FileSHA.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerbas-ad-astra committed Sep 17, 2015
1 parent d564533 commit 1577326
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("2.6.10")]
[assembly: AssemblyVersion("2.6.11")]
[assembly: KSPAssembly("ModuleManager", 2, 5)]

// The following attributes are used to specify the signing key for the assembly,
Expand Down
46 changes: 27 additions & 19 deletions moduleManager.cs
Expand Up @@ -910,25 +910,33 @@ static bool checkValues(ConfigNode node)

private string FileSHA(string filename)
{
if (File.Exists(filename))
{
System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create();

byte[] data = null;
using (FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read))
{
data = sha.ComputeHash(fs);
}

string hashedValue = string.Empty;

foreach (byte b in data)
{
hashedValue += String.Format("{0,2:x2}", b);
}

return hashedValue;
}
try
{
if (File.Exists(filename))
{
System.Security.Cryptography.SHA256 sha = System.Security.Cryptography.SHA256.Create();

byte[] data = null;
using (FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read))
{
data = sha.ComputeHash(fs);
}

string hashedValue = string.Empty;

foreach (byte b in data)
{
hashedValue += String.Format("{0,2:x2}", b);
}

return hashedValue;
}
}
catch (Exception e)
{
log("Exception hashing file " + filename + "\n" + e.ToString());
return "0";
}
return "0";
}

Expand Down

0 comments on commit 1577326

Please sign in to comment.