Skip to content

Commit

Permalink
Improved RestartAs function (check if it can find the executeable).
Browse files Browse the repository at this point in the history
  • Loading branch information
DeStilleGast committed Jun 27, 2019
1 parent 3ffa18e commit 813a458
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions dnSpy Restart as/RestartMenuCommandProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using dnSpy.Contracts.Menus;
using dnSpy.Contracts.App;
using dnSpy.Contracts.Menus;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -24,18 +25,19 @@ public static bool IsAdministrator() {
}

public static void RestartAs(object context, bool bit32, bool asAdmin) {
var dnSpyLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"dnSpy{(bit32 ? "-x86" : "")}.exe");

ProcessStartInfo startInfo = new ProcessStartInfo(dnSpyLocation);

if (!File.Exists(startInfo.FileName)) {
MsgBox.Instance.Show($"Could not find '{new FileInfo(startInfo.FileName).Name}' in the folder where dnSpy is located, can not restart as {(bit32 ? "32" : "64")}bit !");
return;
}

// Close dnSpy (save all settings so dnSpy can open correctly again)
((ICommand)ApplicationCommands.Close).Execute(context);


ProcessStartInfo startInfo;

if (bit32) {
startInfo = new ProcessStartInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dnSpy-x86.exe"));
} else {
startInfo = new ProcessStartInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dnSpy.exe"));
}
;
if (asAdmin) {
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
Expand Down

0 comments on commit 813a458

Please sign in to comment.