2024-07-22 15:47:01 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using ColdMint.scripts.serialization;
|
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.mod;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Module manifest file</para>
|
|
|
|
|
/// <para>模组清单文件</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ModManifest
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>模组Id</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Mod name</para>
|
|
|
|
|
/// <para>模组名称</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? Name { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Dll path list of the mod</para>
|
|
|
|
|
/// <para>模组的Dll路径列表</para>
|
|
|
|
|
/// </summary>
|
2024-07-23 15:03:03 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
///<para>Allow relative paths, such as:... / Points to the parent directory.</para>
|
|
|
|
|
///<para>允许使用相对路径,例如: ../指向上级目录。</para>
|
|
|
|
|
/// </remarks>
|
2024-07-25 12:32:59 +00:00
|
|
|
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
2024-07-22 15:47:01 +00:00
|
|
|
|
public string[]? DllList { get; set; }
|
2024-07-25 12:32:59 +00:00
|
|
|
|
// ReSharper restore UnusedAutoPropertyAccessor.Global
|
2024-07-22 15:47:01 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Pck path list of mod</para>
|
|
|
|
|
/// <para>模组的Pck路径列表</para>
|
|
|
|
|
/// </summary>
|
2024-07-23 15:03:03 +00:00
|
|
|
|
/// <remarks>
|
|
|
|
|
///<para>Allow relative paths, such as:... / Points to the parent directory.</para>
|
|
|
|
|
///<para>允许使用相对路径,例如: ../指向上级目录。</para>
|
|
|
|
|
/// </remarks>
|
2024-07-25 12:32:59 +00:00
|
|
|
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
2024-07-22 15:47:01 +00:00
|
|
|
|
public string[]? PckList { get; set; }
|
2024-07-25 12:32:59 +00:00
|
|
|
|
// ReSharper restore UnusedAutoPropertyAccessor.Global
|
2024-07-22 15:47:01 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Creates module list information from a path</para>
|
|
|
|
|
/// <para>从路径创建模组清单信息</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="filePath">
|
|
|
|
|
///<para>filePath</para>
|
|
|
|
|
///<para>文件路径</para>
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <exception cref="ArgumentException">
|
|
|
|
|
///<para>When a given path is not to <see cref="Config.ModManifestFileName"/> end throw this exception.</para>
|
|
|
|
|
///<para>当给定的路径不是以<see cref="Config.ModManifestFileName"/>结尾时抛出此异常。</para>
|
|
|
|
|
/// </exception>
|
|
|
|
|
/// <exception cref="FileNotFoundException">
|
|
|
|
|
///<para>This exception is thrown when the given path does not exist.</para>
|
|
|
|
|
///<para>当给定的路径不存在时,抛出此异常。</para>
|
|
|
|
|
/// </exception>
|
|
|
|
|
/// <returns></returns>
|
2024-07-23 15:03:03 +00:00
|
|
|
|
public static ModManifest? CreateModManifestFromPath(string filePath)
|
2024-07-22 15:47:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (!filePath.EndsWith(Config.ModManifestFileName))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("path must end with " + Config.ModManifestFileName + ".");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
throw new FileNotFoundException("The file at " + filePath + " does not exist.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var content = File.ReadAllText(filePath);
|
|
|
|
|
return YamlSerialization.Deserialize<ModManifest>(content);
|
|
|
|
|
}
|
|
|
|
|
}
|