mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
feature<VSCode>: supports to open repository with Visual Studio Code
This commit is contained in:
parent
4a676e094d
commit
4456019968
8 changed files with 65 additions and 19 deletions
26
src/Models/ExecutableFinder.cs
Normal file
26
src/Models/ExecutableFinder.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace SourceGit.Models {
|
||||
/// <summary>
|
||||
/// 用于在PATH中检测可执行文件
|
||||
/// </summary>
|
||||
public class ExecutableFinder {
|
||||
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-pathfindonpathw
|
||||
// https://www.pinvoke.net/default.aspx/shlwapi.PathFindOnPath
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, SetLastError = false)]
|
||||
private static extern bool PathFindOnPath([In, Out] StringBuilder pszFile, [In] string[] ppszOtherDirs);
|
||||
|
||||
/// <summary>
|
||||
/// 从PATH中找到可执行文件路径
|
||||
/// </summary>
|
||||
/// <param name="exec"></param>
|
||||
/// <returns></returns>
|
||||
public static string Find(string exec) {
|
||||
var builder = new StringBuilder(exec, 259);
|
||||
var rs = PathFindOnPath(builder, null);
|
||||
return rs ? builder.ToString() : null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue