45 lines
1.5 KiB
VB.net
45 lines
1.5 KiB
VB.net
Imports System.IO
|
|
Imports System.Reflection
|
|
Imports System.Runtime.InteropServices
|
|
Imports System.Security.Cryptography
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Public Class Performance
|
|
Public Sub New(pLogConfig As LogConfig, pAppDataPath As String)
|
|
Dim savedHash = String.Empty
|
|
Dim assemblyLocation = Assembly.GetEntryAssembly().Location
|
|
|
|
Dim hashPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "hash.txt")
|
|
If Not File.Exists(hashPath) Then
|
|
File.Create(hashPath)
|
|
Else
|
|
savedHash = File.ReadAllText(hashPath)
|
|
End If
|
|
|
|
Dim hash = String.Concat(SHA1.Create().ComputeHash(File.ReadAllBytes(assemblyLocation)).Select(Function(x) x.ToString("x2")))
|
|
If hash.Equals(savedHash) Then
|
|
Return
|
|
End If
|
|
|
|
Dim dotNetRuntimePath = RuntimeEnvironment.GetRuntimeDirectory()
|
|
Dim ngenPath = Path.Combine(dotNetRuntimePath, "ngen.exe")
|
|
|
|
Dim process = New Process With {
|
|
.StartInfo = New ProcessStartInfo With {
|
|
.FileName = ngenPath,
|
|
.Arguments = $"install ""{assemblyLocation}"" /nologo",
|
|
.CreateNoWindow = True,
|
|
.UseShellExecute = True,
|
|
.Verb = "runas"
|
|
}
|
|
}
|
|
Try
|
|
process.Start()
|
|
process.WaitForExit()
|
|
File.WriteAllText(hashPath, hash)
|
|
Catch
|
|
' ...
|
|
End Try
|
|
End Sub
|
|
End Class
|