Skip to content

Commit b12cbff

Browse files
committed
Follow up to 006e76c
Fixed functionality for .NET 8 builds
1 parent 006e76c commit b12cbff

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

dnSpy/dnSpy/MainApp/Constants.cs

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License
1717
along with dnSpy. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20+
using System.IO;
21+
using System.Reflection;
2022
using System.Security.Principal;
2123

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

2830
public static bool IsRunningAsAdministrator { get; }
2931

32+
public static string ExecutablePath { get; }
33+
3034
static Constants() {
3135
using var id = WindowsIdentity.GetCurrent();
3236
IsRunningAsAdministrator = new WindowsPrincipal(id).IsInRole(WindowsBuiltInRole.Administrator);
37+
38+
ExecutablePath = Assembly.GetEntryAssembly()!.Location;
39+
#if NET
40+
// Use the native exe and not the managed file
41+
ExecutablePath = Path.ChangeExtension(ExecutablePath, "exe");
42+
if (!File.Exists(ExecutablePath)) {
43+
// All .NET files could be in a bin sub dir
44+
if (Path.GetDirectoryName(Path.GetDirectoryName(ExecutablePath)) is string baseDir)
45+
ExecutablePath = Path.Combine(baseDir, Path.GetFileName(ExecutablePath));
46+
}
47+
#endif
3348
}
3449
}
3550
}

dnSpy/dnSpy/MainApp/RestartAsAdministratorCommand.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@ void OnMainWindowClosing(object? sender, CancelEventArgs args) {
4545
// If a different handler canceled the close operation, don't restart.
4646
if (args.Cancel)
4747
return;
48-
var location = Assembly.GetEntryAssembly()?.Location;
49-
if (location is null) {
50-
args.Cancel = true;
51-
return;
52-
}
5348
try {
54-
Process.Start(new ProcessStartInfo(location) { UseShellExecute = true, Verb = "runas" });
49+
Process.Start(new ProcessStartInfo(Constants.ExecutablePath) { UseShellExecute = true, Verb = "runas" });
5550
}
5651
catch {
5752
args.Cancel = true;

dnSpy/dnSpy/MainApp/Settings/WindowsExplorerIntegration.cs

+1-10
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,7 @@ public bool? WindowsExplorerIntegration {
7474
return;
7575
bool enabled = value.Value;
7676

77-
var path = Assembly.GetEntryAssembly()!.Location;
78-
#if NET
79-
// Use the native exe and not the managed file
80-
path = Path.ChangeExtension(path, "exe");
81-
if (!File.Exists(path)) {
82-
// All .NET files could be in a bin sub dir
83-
if (Path.GetDirectoryName(Path.GetDirectoryName(path)) is string baseDir)
84-
path = Path.Combine(baseDir, Path.GetFileName(path));
85-
}
86-
#endif
77+
var path = Constants.ExecutablePath;
8778
if (!File.Exists(path)) {
8879
messageBoxService.Show("Cannot locate dnSpy!");
8980
return;

0 commit comments

Comments
 (0)