|
7 | 7 | using Snap.Hutao.Remastered.Core.Security.Principal; |
8 | 8 | using Snap.Hutao.Remastered.Factory.Process; |
9 | 9 | using Snap.Hutao.Remastered.Service; |
10 | | -using Snap.Hutao.Remastered.Service.Plugin; |
11 | 10 | using Snap.Hutao.Remastered.Win32; |
12 | 11 | using System.Diagnostics; |
13 | 12 | using System.Runtime.CompilerServices; |
@@ -35,6 +34,13 @@ public static void UseNamedPipeRedirection() |
35 | 34 | [STAThread] |
36 | 35 | private static void Main(string[] args) |
37 | 36 | { |
| 37 | + // Check if we should restart as administrator |
| 38 | + if (ShouldRestartAsAdmin()) |
| 39 | + { |
| 40 | + RestartAsAdministrator(); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
38 | 44 | if (Mutex.TryOpenExisting(LockName, out _)) |
39 | 45 | { |
40 | 46 | return; |
@@ -68,17 +74,10 @@ private static void Main(string[] args) |
68 | 74 | ComWrappersSupport.InitializeComWrappers(); |
69 | 75 |
|
70 | 76 | // By adding the using statement, we can dispose the injected services when closing |
71 | | - using (ServiceProvider serviceProvider = DependencyInjection.Initialize()) |
| 77 | + using (ServiceProvider serviceProvider = DependencyInjection.Initialize(true)) |
72 | 78 | { |
73 | 79 | Thread.CurrentThread.Name = "Snap Hutao Remastered Application Main Thread"; |
74 | 80 |
|
75 | | - // Check if we should restart as administrator |
76 | | - if (ShouldRestartAsAdmin(serviceProvider)) |
77 | | - { |
78 | | - RestartAsAdministrator(); |
79 | | - return; |
80 | | - } |
81 | | - |
82 | 81 | // If you hit a COMException REGDB_E_CLASSNOTREG (0x80040154) during debugging |
83 | 82 | // You can delete bin and obj folder and then rebuild. |
84 | 83 | // In a Desktop app this runs a message pump publicly, |
@@ -112,11 +111,11 @@ private static bool IsRunningAsAdministrator() |
112 | 111 | return principal.IsInRole(WindowsBuiltInRole.Administrator); |
113 | 112 | } |
114 | 113 |
|
115 | | - private static bool ShouldRestartAsAdmin(IServiceProvider serviceProvider) |
| 114 | + private static bool ShouldRestartAsAdmin() |
116 | 115 | { |
117 | 116 | try |
118 | 117 | { |
119 | | - AppOptions appOptions = serviceProvider.GetRequiredService<AppOptions>(); |
| 118 | + AppOptions appOptions = DependencyInjection.Initialize().GetRequiredService<AppOptions>(); |
120 | 119 | return !IsRunningAsAdministrator() && appOptions.AutoRestartAsAdmin.Value; |
121 | 120 | } |
122 | 121 | catch (Exception ex) |
|
0 commit comments