Skip to content

Commit

Permalink
🔖 1.23.10912.11322
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Sep 12, 2023
1 parent e258b48 commit a133b62
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
63 changes: 44 additions & 19 deletions src/BD.Common/Diagnostics/Process2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class Process2
/// <para>或 参数的长度与该进程的完整路径的长度的总和超过了 2080。 与此异常关联的错误消息可能为以下消息之一:“传递到系统调用的数据区域太小。” 或“拒绝访问。”</para>
/// </exception>
/// <exception cref="PlatformNotSupportedException">不支持 shell 的操作系统(如,仅适用于.NET Core 的 Nano Server)不支持此方法</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Process? StartPath(string fileName, string path)
{
if (OperatingSystem.IsMacOS())
Expand All @@ -43,25 +44,9 @@ public static class Process2
}
}

/// <summary>
/// 通过指定应用程序的名称和一组命令行参数来启动一个进程资源,并将该资源与新的 Process 组件相关联
/// </summary>
/// <param name="fileName">要在进程中运行的应用程序文件的名称</param>
/// <param name="arguments">启动该进程时传递的命令行参数</param>
/// <param name="useShellExecute">获取或设置指示是否使用操作系统 shell 启动进程的值</param>
/// <param name="workingDirectory">当 useShellExecute 属性为 <see langword="false"/> 时,将获取或设置要启动的进程的工作目录。 当 useShellExecute 为 <see langword="true"/> 时,获取或设置包含要启动的进程的目录<para>注意:当 UseShellExecute 为 <see langword="true"/> 时,是包含要启动的进程的目录的完全限定名</para></param>
/// <param name="environment"></param>
/// <returns></returns>
/// <exception cref="ObjectDisposedException">已释放此进程对象</exception>
/// <exception cref="Win32Exception">
/// <para>打开关联的文件时出错</para>
/// <para>或 fileName 中指定的文件未找到</para>
/// <para>或 参数的长度与该进程的完整路径的长度的总和超过了 2080。 与此异常关联的错误消息可能为以下消息之一:“传递到系统调用的数据区域太小。” 或“拒绝访问。”</para>
/// </exception>
/// <exception cref="PlatformNotSupportedException">不支持 shell 的操作系统(如,仅适用于.NET Core 的 Nano Server)不支持此方法</exception>
public static Process? Start(string fileName, string? arguments = null, bool useShellExecute = false, string? workingDirectory = null, IReadOnlyDictionary<string, string>? environment = null)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static ProcessStartInfo GetProcessStartInfo(string fileName, string? arguments = null, bool useShellExecute = false, string? workingDirectory = null, IReadOnlyDictionary<string, string>? environment = null)
{
if (string.IsNullOrEmpty(fileName)) return null;
var p = new ProcessStartInfo(fileName);
if (!string.IsNullOrEmpty(arguments))
{
Expand All @@ -87,9 +72,48 @@ public static class Process2
}
}
p.UseShellExecute = useShellExecute;
return Process.Start(p);

return p;
}

/// <summary>
/// 通过指定应用程序的名称和一组命令行参数来启动一个进程资源,并将该资源与新的 Process 组件相关联
/// </summary>
/// <param name="fileName">要在进程中运行的应用程序文件的名称</param>
/// <param name="arguments">启动该进程时传递的命令行参数</param>
/// <param name="useShellExecute">获取或设置指示是否使用操作系统 shell 启动进程的值</param>
/// <param name="workingDirectory">当 useShellExecute 属性为 <see langword="false"/> 时,将获取或设置要启动的进程的工作目录。 当 useShellExecute 为 <see langword="true"/> 时,获取或设置包含要启动的进程的目录<para>注意:当 UseShellExecute 为 <see langword="true"/> 时,是包含要启动的进程的目录的完全限定名</para></param>
/// <param name="environment"></param>
/// <returns></returns>
/// <exception cref="ObjectDisposedException">已释放此进程对象</exception>
/// <exception cref="Win32Exception">
/// <para>打开关联的文件时出错</para>
/// <para>或 fileName 中指定的文件未找到</para>
/// <para>或 参数的长度与该进程的完整路径的长度的总和超过了 2080。 与此异常关联的错误消息可能为以下消息之一:“传递到系统调用的数据区域太小。” 或“拒绝访问。”</para>
/// </exception>
/// <exception cref="PlatformNotSupportedException">不支持 shell 的操作系统(如,仅适用于.NET Core 的 Nano Server)不支持此方法</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Process? Start(string fileName, string? arguments = null, bool useShellExecute = false, string? workingDirectory = null, IReadOnlyDictionary<string, string>? environment = null)
{
if (string.IsNullOrEmpty(fileName)) return null;
var p = GetProcessStartInfo(fileName, arguments, useShellExecute, workingDirectory, environment);
try
{
return Process.Start(p);
}
catch (Win32Exception)
{
if (!p.UseShellExecute)
{
// System.ComponentModel.Win32Exception: An error occurred trying to start process 'a.exe' with working directory 'path'. 请求的操作需要提升。
p = GetProcessStartInfo(fileName, arguments, true, workingDirectory: null, environment);
return Process.Start(p);
}
}
return null;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool OpenCoreByProcess(string url, Action<string>? onError = null)
{
try
Expand All @@ -106,6 +130,7 @@ public static bool OpenCoreByProcess(string url, Action<string>? onError = null)
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string RunShell(string fileName, string value, Action<Exception>? onError = null)
{
try
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<IsTrimmable>true</IsTrimmable>
<!--<Version>1.yy.1MMdd.1hhmm</Version>-->
<Version>1.23.10831.10300</Version>
<Version>1.23.10912.11322</Version>
<PackageIconUrl>https://avatars.githubusercontent.com/u/79355691?s=200&amp;v=4</PackageIconUrl>
<Company>江苏蒸汽凡星科技有限公司</Company>
<Copyright>©️ $(Company). All rights reserved.</Copyright>
Expand Down

0 comments on commit a133b62

Please sign in to comment.