From 410cae21ea1112e3bcb58c8ae02d7b4364dd15c7 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 17 Oct 2022 10:37:42 +0200 Subject: [PATCH] Base: Add Performance class for calling ngen --- Base/Base.vbproj | 3 ++- Base/{ => ECM}/ECM.vb | 0 Base/Performance.vb | 44 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) rename Base/{ => ECM}/ECM.vb (100%) create mode 100644 Base/Performance.vb diff --git a/Base/Base.vbproj b/Base/Base.vbproj index 5dfb5f21..af2f05e0 100644 --- a/Base/Base.vbproj +++ b/Base/Base.vbproj @@ -75,7 +75,7 @@ - + @@ -95,6 +95,7 @@ Settings.settings True + diff --git a/Base/ECM.vb b/Base/ECM/ECM.vb similarity index 100% rename from Base/ECM.vb rename to Base/ECM/ECM.vb diff --git a/Base/Performance.vb b/Base/Performance.vb new file mode 100644 index 00000000..f94d50a6 --- /dev/null +++ b/Base/Performance.vb @@ -0,0 +1,44 @@ +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