|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | | -using System.Diagnostics; |
4 | | -using System.IO; |
5 | 3 | using System.Linq; |
6 | | -using System.Reflection; |
7 | | -using System.Threading; |
8 | 4 | using System.Threading.Tasks; |
9 | 5 | using System.Windows; |
10 | 6 | using System.Windows.Forms; |
@@ -171,46 +167,11 @@ private async Task CheckAdminChangeAndAskForRestartAsync() |
171 | 167 | await ImageLoader.WaitSaveAsync(); |
172 | 168 |
|
173 | 169 | // Restart the app as administrator |
174 | | - RestartAppAsAdministrator(Constant.ExecutablePath); |
| 170 | + App.RestartAppAsAdministrator(); |
175 | 171 | } |
176 | 172 | } |
177 | 173 | } |
178 | 174 |
|
179 | | - // Since Squirrel does not provide a way to restart the app as administrator, |
180 | | - // we need to do it manually by starting the update.exe with the runas verb |
181 | | - private static void RestartAppAsAdministrator(string exeToStart) |
182 | | - { |
183 | | - var startInfo = new ProcessStartInfo |
184 | | - { |
185 | | - FileName = getUpdateExe(), |
186 | | - Arguments = $"--processStartAndWait {exeToStart}", |
187 | | - UseShellExecute = true, |
188 | | - Verb = "runas", |
189 | | - }; |
190 | | - Process.Start(startInfo); |
191 | | - Thread.Sleep(500); |
192 | | - Environment.Exit(0); |
193 | | - |
194 | | - // Local function |
195 | | - static string getUpdateExe() |
196 | | - { |
197 | | - Assembly entryAssembly = Assembly.GetEntryAssembly(); |
198 | | - if (entryAssembly != null && Path.GetFileName(entryAssembly.Location).Equals("update.exe", StringComparison.OrdinalIgnoreCase) && entryAssembly.Location.IndexOf("app-", StringComparison.OrdinalIgnoreCase) == -1 && entryAssembly.Location.IndexOf("SquirrelTemp", StringComparison.OrdinalIgnoreCase) == -1) |
199 | | - { |
200 | | - return Path.GetFullPath(entryAssembly.Location); |
201 | | - } |
202 | | - |
203 | | - entryAssembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); |
204 | | - FileInfo fileInfo = new FileInfo(Path.Combine(Path.GetDirectoryName(entryAssembly.Location), "..\\Update.exe")); |
205 | | - if (!fileInfo.Exists) |
206 | | - { |
207 | | - throw new Exception("Update.exe not found, not a Squirrel-installed app?"); |
208 | | - } |
209 | | - |
210 | | - return fileInfo.FullName; |
211 | | - } |
212 | | - } |
213 | | - |
214 | 175 | public List<SearchWindowScreenData> SearchWindowScreens { get; } = |
215 | 176 | DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreenData>("SearchWindowScreen"); |
216 | 177 |
|
|
0 commit comments