Files
better-genshin-impact/BetterGenshinImpact/Core/Script/Project/Manifest.cs
辉鸭蛋 6b41b52008 warning when script version number is too high
更新程序集版本号并添加版本号比较逻辑

更新了 `BetterGenshinImpact.csproj` 文件中的程序集版本号,从 `0.35.0` 更新到 `0.35.1`。

在 `Manifest.cs` 文件中,增加了对 `BetterGenshinImpact.GameTask.Common` 和 `Microsoft.Extensions.Logging` 的引用,并在 `Manifest` 类中增加了版本号比较的逻辑,如果脚本要求的版本号大于当前版本号,则记录错误日志。

在 `ScriptProject` 类的构造函数中,增加了对脚本文件夹是否存在的检查,如果不存在则抛出 `DirectoryNotFoundException` 异常。

在 `PathingTask.cs` 文件中,增加了对 `BetterGenshinImpact.Core.Config`、`BetterGenshinImpact.GameTask.Common` 和 `Microsoft.Extensions.Logging` 的引用,并在 `PathingTask` 类中增加了版本号比较的逻辑,如果路径追踪任务要求的版本号大于当前版本号,则记录错误日志。
2024-10-20 15:47:03 +08:00

80 lines
2.6 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 BetterGenshinImpact.Service;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.GameTask.Common;
using BetterGenshinImpact.Model;
using Microsoft.Extensions.Logging;
namespace BetterGenshinImpact.Core.Script.Project;
[Serializable]
public class Manifest
{
public int ManifestVersion { get; set; } = 1;
public string Name { get; set; } = string.Empty;
public string Version { get; set; } = string.Empty;
public string? BgiVersion { get; set; }
public string Description { get; set; } = string.Empty;
public List<Author> Authors { get; set; } = [];
public string Main { get; set; } = string.Empty;
public string SettingsUi { get; set; } = string.Empty;
public string[] Scripts { get; set; } = [];
public string[] Library { get; set; } = [];
public static Manifest FromJson(string json)
{
var manifest = JsonSerializer.Deserialize<Manifest>(json, Global.ManifestJsonOptions) ?? throw new Exception("Failed to deserialize JSON.");
return manifest;
}
public void Validate(string path)
{
if (string.IsNullOrWhiteSpace(Name))
{
throw new Exception("manifest.json: name is required.");
}
if (string.IsNullOrWhiteSpace(Version))
{
throw new Exception("manifest.json: version is required.");
}
if (string.IsNullOrWhiteSpace(Main))
{
throw new Exception("manifest.json: main script is required.");
}
if (!File.Exists(Path.Combine(path, Main)))
{
throw new FileNotFoundException("main js file not found.");
}
// 比较版本号大小 BgiVersion
if (!string.IsNullOrWhiteSpace(BgiVersion) && Global.IsNewVersion(BgiVersion))
{
TaskControl.Logger.LogError("脚本 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} 脚本可能无法正常工作,请更新 BetterGI 版本!", Name, BgiVersion, Global.Version);
}
}
public List<SettingItem> LoadSettingItems(string path)
{
if (string.IsNullOrWhiteSpace(SettingsUi))
{
return [];
}
var settingItems = new List<SettingItem>();
var settingFile = Path.Combine(path, SettingsUi);
if (File.Exists(settingFile))
{
var json = File.ReadAllText(settingFile);
settingItems = JsonSerializer.Deserialize<List<SettingItem>>(json, ConfigService.JsonOptions) ?? [];
}
return settingItems;
}
}