|
1 | 1 | using DNSChanger.Structs; |
2 | 2 | using Microsoft.Win32.TaskScheduler; |
3 | 3 | using System; |
4 | | -using System.Diagnostics; |
5 | 4 | using System.Linq; |
6 | 5 | using System.Text.RegularExpressions; |
7 | 6 |
|
8 | 7 | namespace DNSChanger |
9 | 8 | { |
10 | 9 | public static class DNSValidate |
11 | 10 | { |
12 | | - private const string TaskPath = "DNSChanger-ValidationTask"; |
| 11 | + private static readonly string TaskPath = GlobalVars.Name + "-ValidationTask"; |
13 | 12 |
|
14 | 13 | static DNSValidate() |
15 | 14 | { |
16 | | - if (!VerifyProcessPath()) |
| 15 | + if (!ValidateAutoStartProcessPath()) |
17 | 16 | { |
18 | 17 | var @interface = GetInterfaceToValidate(); |
19 | 18 | if (@interface.HasValue) |
@@ -52,14 +51,14 @@ private static Task Get() |
52 | 51 | return TaskService.Instance.GetTask(TaskPath); |
53 | 52 | } |
54 | 53 |
|
55 | | - private static bool VerifyProcessPath() |
| 54 | + private static bool ValidateAutoStartProcessPath() |
56 | 55 | { |
57 | 56 | var tsk = Get(); |
58 | 57 | if (tsk == null) return true; |
59 | 58 |
|
60 | 59 | var action = (ExecAction) tsk.Definition.Actions[0]; |
61 | 60 |
|
62 | | - return action.Path == Process.GetCurrentProcess().MainModule.FileName; |
| 61 | + return action.Path == Utilities.GetProcessPath(); |
63 | 62 | } |
64 | 63 |
|
65 | 64 | public static Interface? GetInterfaceToValidate() |
@@ -111,8 +110,9 @@ public static void Enable(Interface @interface) |
111 | 110 | var task = ts.NewTask(); |
112 | 111 | task.Principal.RunLevel = TaskRunLevel.Highest; |
113 | 112 | task.RegistrationInfo.Description = "Performs DNS validation procedure on boot"; |
| 113 | + task.RegistrationInfo.Author = GlobalVars.Name; |
114 | 114 | task.Triggers.Add(new BootTrigger()); |
115 | | - task.Actions.Add(Process.GetCurrentProcess().MainModule.FileName, $"-validate \"{@interface.Name}\" \"{AggregateDnsEntries(@interface)}\""); |
| 115 | + task.Actions.Add(Utilities.GetProcessPath(), $"-validate \"{@interface.Name}\" \"{AggregateDnsEntries(@interface)}\""); |
116 | 116 |
|
117 | 117 | ts.RootFolder.RegisterTaskDefinition(TaskPath, task); |
118 | 118 | } |
|
0 commit comments