@@ -7,49 +7,40 @@ public class {X}
77{
88 static string FindCommand(string commandid)
99 {
10- var baseDir = Path.GetDirectoryName(typeof({X}).Assembly.Location) ?? "";
11-
12- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
13- {
14- baseDir = Path.Combine(baseDir, "windows-x64");
15- }
16- else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
10+ var dirBase = "windows";
11+ if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
1712 {
18- var osxPath = Path.Combine(baseDir, "osx");
19- if (!File.Exists(osxPath))
20- {
21- osxPath = RuntimeInformation.ProcessArchitecture switch
22- {
23- Architecture.Arm or Architecture.Arm64 => Path.Combine(baseDir, "osx-arm64"),
24- _ => Path.Combine(baseDir, "osx-x64")
25- };
26- }
27- baseDir = osxPath;
13+ dirBase = "osx";
2814 }
2915 else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
3016 {
31- baseDir = RuntimeInformation.ProcessArchitecture switch
32- {
33- Architecture.Arm or Architecture.Arm64 => Path.Combine(baseDir, "linux-arm64"),
34- _ => Path.Combine(baseDir, "linux-x64")
35- };
17+ dirBase = "linux";
3618 }
3719
38- var pathsToCheck = new string[] {
39- Path.Combine(baseDir, commandid),
40- Path.Combine(baseDir, "bin", commandid)
20+ var dirsToCheck = new string[] {
21+ dirBase,
22+ $"{dirBase}-{((RuntimeInformation.ProcessArchitecture == Architecture.Arm || RuntimeInformation.ProcessArchitecture == Architecture.Arm64) ? "arm64" : "x64")}"
23+ };
24+
25+ var commandsToCheck = new string[] {
26+ commandid,
27+ Path.Combine("bin", commandid)
4128 };
4229
43- foreach(var path in pathsToCheck )
30+ foreach (var dir in dirsToCheck )
4431 {
45- if (File.Exists(path) )
32+ foreach (var com in commandsToCheck )
4633 {
47- return path;
48- }
34+ var path = Path.Combine(AppContext.BaseDirectory, dir, com);
35+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
36+ {
37+ path += ".exe";
38+ }
4939
50- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && File.Exists(path + ".exe"))
51- {
52- return path;
40+ if (File.Exists(path))
41+ {
42+ return path;
43+ }
5344 }
5445 }
5546
0 commit comments