Skip to content

Commit

Permalink
Log DLLs and KSP exe SHA
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Aug 4, 2015
1 parent af68966 commit 7fb3ca2
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions moduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,14 @@ private List<String> PrePatchInit()

#region List of mods

string envinfo = "ModuleManager env info\n";
envinfo += Environment.OSVersion.Platform + " " + ModuleManager.intPtr.ToInt64().ToString("X16") + "\n";
envinfo += "Args: " + string.Join(" ", Environment.GetCommandLineArgs().Skip(1).ToArray());
log(envinfo);
string envInfo = "ModuleManager env info\n";
envInfo += " " + Environment.OSVersion.Platform + " " + ModuleManager.intPtr.ToInt64().ToString("X16") + "\n";
//envInfo += " " + Convert.ToString(ModuleManager.intPtr.ToInt64(), 2) + " " + Convert.ToString(ModuleManager.intPtr.ToInt64() >> 63, 2) + "\n";
string gamePath = Environment.GetCommandLineArgs()[0];
envInfo += " Args: " + gamePath.Split(Path.DirectorySeparatorChar).Last() + string.Join(" ", Environment.GetCommandLineArgs().Skip(1).ToArray()) + "\n";
envInfo += " Executable SHA256 " + FileSHA(gamePath);

log(envInfo);

mods = new List<string>();

Expand All @@ -588,11 +592,18 @@ private List<String> PrePatchInit()

AssemblyName assemblyName = mod.assembly.GetName();

modlist += " " + assemblyName.Name
+ " v" + assemblyName.Version
+ (fileVersionInfo.ProductVersion != " " && fileVersionInfo.ProductVersion != assemblyName.Version.ToString() ? " / v" + fileVersionInfo.ProductVersion : "")
+ (fileVersionInfo.FileVersion != " " && fileVersionInfo.FileVersion != assemblyName.Version.ToString() && fileVersionInfo.FileVersion != fileVersionInfo.ProductVersion ? " / v" + fileVersionInfo.FileVersion : "")
+ "\n";
string modInfo = " " + assemblyName.Name
+ " v" + assemblyName.Version
+
(fileVersionInfo.ProductVersion != " " && fileVersionInfo.ProductVersion != assemblyName.Version.ToString()
? " / v" + fileVersionInfo.ProductVersion
: "")
+
(fileVersionInfo.FileVersion != " " &&fileVersionInfo.FileVersion != assemblyName.Version.ToString() && fileVersionInfo.FileVersion != fileVersionInfo.ProductVersion
? " / v" + fileVersionInfo.FileVersion
: "");

modlist += String.Format(" {0,-50} SHA256 {1}\n", modInfo, FileSHA(mod.assembly.Location));

if (!mods.Contains(assemblyName.Name, StringComparer.OrdinalIgnoreCase))
mods.Add(assemblyName.Name);
Expand Down Expand Up @@ -846,6 +857,30 @@ static bool checkValues(ConfigNode node)
return false;
}

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;
}
return "0";
}

private void IsCacheUpToDate()
{
Stopwatch sw = new Stopwatch();
Expand Down

0 comments on commit 7fb3ca2

Please sign in to comment.