Skip to content

Commit

Permalink
Follow up to 006e76c
Browse files Browse the repository at this point in the history
Fixed functionality for .NET 8 builds
  • Loading branch information
ElektroKill committed Feb 13, 2024
1 parent 006e76c commit b12cbff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
15 changes: 15 additions & 0 deletions dnSpy/dnSpy/MainApp/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License
along with dnSpy. If not, see <http://www.gnu.org/licenses/>.
*/

using System.IO;
using System.Reflection;
using System.Security.Principal;

namespace dnSpy.MainApp {
Expand All @@ -27,9 +29,22 @@ static class Constants {

public static bool IsRunningAsAdministrator { get; }

public static string ExecutablePath { get; }

static Constants() {
using var id = WindowsIdentity.GetCurrent();
IsRunningAsAdministrator = new WindowsPrincipal(id).IsInRole(WindowsBuiltInRole.Administrator);

ExecutablePath = Assembly.GetEntryAssembly()!.Location;
#if NET
// Use the native exe and not the managed file
ExecutablePath = Path.ChangeExtension(ExecutablePath, "exe");
if (!File.Exists(ExecutablePath)) {
// All .NET files could be in a bin sub dir
if (Path.GetDirectoryName(Path.GetDirectoryName(ExecutablePath)) is string baseDir)
ExecutablePath = Path.Combine(baseDir, Path.GetFileName(ExecutablePath));
}
#endif
}
}
}
7 changes: 1 addition & 6 deletions dnSpy/dnSpy/MainApp/RestartAsAdministratorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,8 @@ void OnMainWindowClosing(object? sender, CancelEventArgs args) {
// If a different handler canceled the close operation, don't restart.
if (args.Cancel)
return;
var location = Assembly.GetEntryAssembly()?.Location;
if (location is null) {
args.Cancel = true;
return;
}
try {
Process.Start(new ProcessStartInfo(location) { UseShellExecute = true, Verb = "runas" });
Process.Start(new ProcessStartInfo(Constants.ExecutablePath) { UseShellExecute = true, Verb = "runas" });
}
catch {
args.Cancel = true;
Expand Down
11 changes: 1 addition & 10 deletions dnSpy/dnSpy/MainApp/Settings/WindowsExplorerIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,7 @@ public bool? WindowsExplorerIntegration {
return;
bool enabled = value.Value;

var path = Assembly.GetEntryAssembly()!.Location;
#if NET
// Use the native exe and not the managed file
path = Path.ChangeExtension(path, "exe");
if (!File.Exists(path)) {
// All .NET files could be in a bin sub dir
if (Path.GetDirectoryName(Path.GetDirectoryName(path)) is string baseDir)
path = Path.Combine(baseDir, Path.GetFileName(path));
}
#endif
var path = Constants.ExecutablePath;
if (!File.Exists(path)) {
messageBoxService.Show("Cannot locate dnSpy!");
return;
Expand Down

0 comments on commit b12cbff

Please sign in to comment.