File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 19
19
<ItemGroup >
20
20
<Resource Include =" favicon.png" />
21
21
<EmbeddedResource Include =" template.xltx" />
22
+ <EmbeddedResource Include =" cert.cer" />
22
23
</ItemGroup >
23
24
24
25
</Project >
Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ public MainWindow()
34
34
GenerateButton . Click += OnGenerate ;
35
35
DownloadButton . Click += OnDownload ;
36
36
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 ( ) ;
37
44
}
38
45
39
46
#region Drag and drop
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments