Skip to content

Commit d5d8a22

Browse files
committed
Feat: include certificate installation on load
1 parent 5a0b8e5 commit d5d8a22

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

DebitExpress.VatRelief/DebitExpress.VatRelief.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<ItemGroup>
2020
<Resource Include="favicon.png" />
2121
<EmbeddedResource Include="template.xltx" />
22+
<EmbeddedResource Include="cert.cer" />
2223
</ItemGroup>
2324

2425
</Project>

DebitExpress.VatRelief/MainWindow.xaml.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public MainWindow()
3434
GenerateButton.Click += OnGenerate;
3535
DownloadButton.Click += OnDownload;
3636
GithubButton.Click+= OnGithub;
37+
Loaded+= OnLoaded;
38+
}
39+
40+
private void OnLoaded(object sender, RoutedEventArgs e)
41+
{
42+
var certManager = new CertificateManager();
43+
certManager.Install();
3744
}
3845

3946
#region Drag and drop
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
using System.Security.Cryptography.X509Certificates;
5+
6+
namespace DebitExpress.VatRelief.Utils;
7+
8+
public sealed class CertificateManager
9+
{
10+
public void Install()
11+
{
12+
try
13+
{
14+
var path = Path.Combine(Path.GetTempPath(), "vat-relief");
15+
Directory.CreateDirectory(path);
16+
17+
//certificate file should be generated by the ci pipeline
18+
var assembly = Assembly.GetExecutingAssembly();
19+
using var stream = assembly.GetManifestResourceStream("DebitExpress.VatRelief.cert.cer");
20+
21+
if (stream == null) return;
22+
23+
var filePath = Path.Combine(path, "cert.cer");
24+
using var fileStream = File.Create(filePath);
25+
stream.Seek(0, SeekOrigin.Begin);
26+
stream.CopyTo(fileStream);
27+
fileStream.Close();
28+
29+
using var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
30+
store.Open(OpenFlags.ReadWrite);
31+
32+
var cert = new X509Certificate2(filePath);
33+
store.Add(cert);
34+
store.Close();
35+
36+
File.Delete(filePath);
37+
}
38+
catch (Exception)
39+
{
40+
//ignored
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)