-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeController.cs
More file actions
48 lines (44 loc) · 1.57 KB
/
Copy pathHomeController.cs
File metadata and controls
48 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
using System.Security.Cryptography;
using System.Web.Mvc;
namespace Lib.Controllers;
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult Ping()
{
var loadedLibFileInfo = new FileInfo(typeof(HomeController).Assembly.Location);
var builtLibFileInfo = new FileInfo(@$"{AppDomain.CurrentDomain.BaseDirectory}..\..\Lib.dll");
var builtFileHash = GetFileHash(builtLibFileInfo.FullName);
var loadedFileHash = GetFileHash(loadedLibFileInfo.FullName);
return Json(new
{
Same = builtFileHash == loadedFileHash,
Built = new
{
builtLibFileInfo.FullName,
LastWriteTime = builtLibFileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"),
FileHash = builtFileHash
},
Loaded = new
{
FullName = loadedLibFileInfo.FullName.Replace(Environment.GetEnvironmentVariable("TEMP"), "$env:TEMP"),
LastWriteTime = loadedLibFileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"),
FileHash = loadedFileHash
}
}, JsonRequestBehavior.AllowGet);
static string GetFileHash(string filePath)
{
using var sha256 = SHA256.Create();
using var stream = System.IO.File.OpenRead(filePath);
var hash = sha256.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "");
}
}
}