-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (51 loc) · 1.99 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (51 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PDFWatermarker
{
public class Program
{
private static PATH_TO_CHECK_CLASS PATH = new PATH_TO_CHECK_CLASS { PATH_TO_CHECK = string.Format(@"{0}\Documents\Scanned", Environment.GetEnvironmentVariable("USERPROFILE")) };
private static readonly RegistryKey rb = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
public static void Main(string[] args)
{
CheckRegistryExists();
CreateHostBuilder(args).Build().Run();
}
private static void CheckRegistryExists()
{
using (RegistryKey readKey = rb.OpenSubKey(@"SOFTWARE\PDFWatermarker"))
{
if (readKey != null)
{
Object o = readKey.GetValue("PATH_TO_CHECK");
Console.WriteLine(o.ToString());
PATH.PATH_TO_CHECK = o.ToString();
}
else
{
using RegistryKey writeKey = rb.CreateSubKey(@"SOFTWARE\PDFWatermarker");
writeKey.SetValue("PATH_TO_CHECK", PATH.PATH_TO_CHECK);
}
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(loggerFactory => loggerFactory.AddEventLog())
.UseWindowsService()
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
services.AddSingleton(PATH);
});
public class PATH_TO_CHECK_CLASS {
public string PATH_TO_CHECK { get; set; }
public string PATH_TO_SAVE { get; set; }
}
}
}