Minecraft-Console-Client/MinecraftClient/Scripting/DataPath.cs

56 lines
2 KiB
C#
Raw Permalink Normal View History

Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
using System;
using System.IO;
namespace MinecraftClient.Scripting
{
public static class DataPath
{
private static string? relativePath;
private static string? absolutePath;
public enum PathType
{
Relative,
Absolute
}
/// <summary>
/// 初始化数据目录(修正版)
/// Initialize the data directory (Revised version)
Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
/// 需要手动传入脚本文件名(不含.cs扩展名
/// Requires manually passing the script file name (without the .cs extension)
Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
/// </summary>
/// <param name="scriptName">脚本文件名不含扩展名Script file name (without extension)</param>
Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
public static void Init(string scriptName)
{
if (string.IsNullOrEmpty(scriptName))
throw new ArgumentNullException(nameof(scriptName), "Script name cannot be null or empty(脚本名称不能为空)");
Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
// 计算路径 Calculate the path
Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
relativePath = scriptName;
absolutePath = Path.Combine(AppContext.BaseDirectory, scriptName);
// 创建目录 Create the directory
Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
if (!Directory.Exists(absolutePath))
Directory.CreateDirectory(absolutePath);
}
/// <summary>
/// 获取路径
/// Get the path
Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
/// </summary>
public static string Get(PathType pathType = PathType.Relative)
{
if (string.IsNullOrEmpty(relativePath) || string.IsNullOrEmpty(absolutePath))
throw new InvalidOperationException("Please call DataPath.Init() first to initialize(请先调用DataPath.Init()初始化)");
Add DataPath.cs and revert CSharpRunner.cs changes # Submission Instructions ## Content of this submission ### 1. Synchronize official CSharpRunner.cs - Synchronize `CSharpRunner.cs` to the latest official version - **Removed** extended support for non-standard metadata formats (XML, C# style, JS style) - Restore to the official standard metadata parsing method ### 2. Migrate DataPath.cs - Migrate `DataPath.cs` to the new version of the code repository - Maintain the original functionality unchanged: - `DataPath.Init("ScriptName")` - create a configuration folder - `DataPath.Get()` - Gets the path of the configuration folder ## Reason for change 1. **Facilitate official merging**: Retaining custom metadata formats increases the risk of conflicts with the official codebase. Removing them allows for smoother acceptance of official updates 2. **Reduce maintenance costs**: The official CSharpRunner.cs undergoes frequent changes, making the maintenance of custom branches a significant workload 3. **Maintain consistency**: Keep consistent with the official version to avoid compatibility issues caused by format differences ## Scope of impact - Previously supported non-standard metadata formats (XML, C# style, JS style) will no longer be recognized - Only supports official standard metadata formats - The functionality of DataPath.cs remains unaffected, and the configuration management function is still operational and available ## Remarks - DataPath.cs and CSharpRunner.cs have previously been modified, and this time it is only for migration and synchronization purposes - AI-assisted participation was involved in the previous modification process
2026-06-19 13:18:04 +08:00
return pathType switch
{
PathType.Relative => relativePath,
PathType.Absolute => absolutePath,
_ => throw new ArgumentOutOfRangeException(nameof(pathType))
};
}
}
}