You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Apewer
|
|
{
|
|
|
|
/// <summary>系统实用工具。</summary>
|
|
public class SystemUtility
|
|
{
|
|
|
|
#if NETSTD || NETCORE
|
|
|
|
/// <summary>当前操作系统是 Windows。</summary>
|
|
public static bool IsWindows { get => System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); }
|
|
|
|
/// <summary>当前操作系统是 OS X 或 macOS。</summary>
|
|
public static bool IsOSX { get => System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX); }
|
|
|
|
/// <summary>当前操作系统是 Linux。</summary>
|
|
public static bool IsLinux { get => System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux); }
|
|
|
|
#endif
|
|
|
|
/// <summary></summary>
|
|
public static void SetConsoleCtrlCancel(Func<bool> exit)
|
|
{
|
|
const string postfix = " - 按 CTRL + C 可安全退出";
|
|
var title = Console.Title;
|
|
if (!title.EndsWith(postfix))
|
|
{
|
|
title = title + postfix;
|
|
Console.Title = title;
|
|
}
|
|
|
|
if (exit == null) return;
|
|
Console.CancelKeyPress += (s, e) =>
|
|
{
|
|
e.Cancel = !exit();
|
|
};
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|