11using Microsoft . Extensions . DependencyInjection ;
22using Microsoft . Extensions . Hosting ;
33using Microsoft . Extensions . Logging ;
4+ using Microsoft . Win32 ;
45using System ;
56using System . Collections . Generic ;
67using System . Linq ;
@@ -10,17 +11,47 @@ namespace PDFWatermarker
1011{
1112 public class Program
1213 {
14+
15+ private static PATH_TO_CHECK_CLASS PATH = new PATH_TO_CHECK_CLASS { PATH_TO_CHECK = string . Format ( @"{0}\Documents\Scanned" , Environment . GetEnvironmentVariable ( "USERPROFILE" ) ) } ;
1316 public static void Main ( string [ ] args )
1417 {
18+ CheckRegistryExists ( ) ;
1519 CreateHostBuilder ( args ) . Build ( ) . Run ( ) ;
1620 }
1721
22+ private static void CheckRegistryExists ( )
23+ {
24+ using ( RegistryKey readKey = Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\PDFWatermarker" ) )
25+ {
26+ if ( readKey != null )
27+ {
28+ Object o = readKey . GetValue ( "PATH_TO_CHECK" ) ;
29+ Console . WriteLine ( o . ToString ( ) ) ;
30+ PATH . PATH_TO_CHECK = o . ToString ( ) ;
31+ }
32+ else
33+ {
34+ using RegistryKey writeKey = Registry . CurrentUser . CreateSubKey ( @"SOFTWARE\PDFWatermarker" ) ;
35+
36+ writeKey . SetValue ( "PATH_TO_CHECK" , PATH . PATH_TO_CHECK ) ;
37+ }
38+ }
39+
40+
41+ }
42+
1843 public static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
1944 Host . CreateDefaultBuilder ( args )
2045 . ConfigureLogging ( loggerFactory => loggerFactory . AddEventLog ( ) )
2146 . ConfigureServices ( ( hostContext , services ) =>
2247 {
2348 services . AddHostedService < Worker > ( ) ;
49+ services . AddSingleton ( PATH ) ;
2450 } ) ;
51+
52+ public class PATH_TO_CHECK_CLASS {
53+ public string PATH_TO_CHECK { get ; set ; }
54+ public string PATH_TO_SAVE { get ; set ; }
55+ }
2556 }
2657}
0 commit comments