Traveller/scripts/utils/ExplorerUtils.cs
Cold-Mint 2e64f57749
Support for saving node data to json files.
支持将节点数据转存为json文件了。
2024-05-15 21:52:07 +08:00

80 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Diagnostics;
namespace ColdMint.scripts.utils;
/// <summary>
/// <para>Explorer Utils</para>
/// <para>资源管理器工具</para>
/// </summary>
public class ExplorerUtils
{
/// <summary>
/// <para>Call Explorer to open the directory</para>
/// <para>调用资源管理器打开目录</para>
/// </summary>
/// <param name="path">
///<para>要打开的目录路径</para>
///<para>The path of the directory to open</para>
/// </param>
public static void OpenFolder(string path)
{
var osEnum = Config.GetOs();
switch (osEnum)
{
case Config.OsEnum.Windows:
var startInfoWindows = new ProcessStartInfo
{
Arguments = path,
FileName = "explorer.exe"
};
Process.Start(startInfoWindows);
break;
case Config.OsEnum.Linux:
// Use the xdg-open command to open the directory on Linux
// 使用xdg-open命令在Linux上打开目录
var startInfoLinux = new ProcessStartInfo
{
Arguments = path,
FileName = "xdg-open"
};
Process.Start(startInfoLinux);
break;
case Config.OsEnum.Android:
// A different approach may be required on Android, as there is usually no desktop environment
// A general Intent is used here to open the file manager, but a specific implementation may be required
// The following code is only an indication, the actual implementation may need to be adjusted according to the Android API
// Android上可能需要使用不同的方法因为通常没有桌面环境
// 这里使用一个通用的Intent来打开文件管理器但可能需要具体的实现
// 以下代码只是一个示意实际的实现可能需要根据Android API进行调整
var startInfoAndroid = new ProcessStartInfo
{
Arguments = "VIEW",
FileName = "content://com.android.externalstorage.documents/tree/primary%3ADocuments"
};
Process.Start(startInfoAndroid);
break;
default:
throw new NotImplementedException($"No implementation for OS: {osEnum}");
}
}
/// <summary>
/// <para>Whether opening directories using Explorer is supported on the current system</para>
/// <para>在当前系统上是否支持使用资源管理器打开目录</para>
/// </summary>
/// <returns></returns>
public static bool SupportOpenDirectory()
{
var osEnum = Config.GetOs();
switch (osEnum)
{
case Config.OsEnum.Windows:
case Config.OsEnum.Linux:
case Config.OsEnum.Android:
return true;
default:
return false;
}
}
}