using System.Text.Json.Serialization; using PCL.Core.Utils.OS; namespace PCL.Core.App; /// /// 启动器版本信息模型 /// /// 基本版本号, 如 2.14.1 /// 后缀, 如 beta.1 /// 内部版本代号, 如 712 /// 上游版本, 如 2.12.0 public sealed record LauncherVersionModel( [property: JsonPropertyName("base")] string BaseVersion, [property: JsonPropertyName("suffix")] string Suffix, [property: JsonPropertyName("code")] int Code, [property: JsonPropertyName("upstream")] string UpstreamVersion ) { private static readonly (string Name, int Code) _CompilationBranchInfo = #if DEBUG ("Debug", 100); #elif CI ("CI", 50); #else ("Publish", 0); #endif private static readonly string? _SecretCommitInfo = EnvironmentInterop.GetSecret("GITHUB_SHA", false); /// /// 基本版本名, 若 存在实际值会附加后缀, 否则与 相同 /// public string BaseName { get; } = BaseVersion + (string.IsNullOrWhiteSpace(Suffix) ? "" : "-" + Suffix); /// /// 发行分支名 /// public string BranchName { get; } = _CompilationBranchInfo.Name; /// /// 发行分支代号 /// public int BranchCode { get; } = _CompilationBranchInfo.Code; /// /// 标准版本号 /// public string StandardVersion { get; } = BaseVersion + "." + _CompilationBranchInfo.Code; /// /// 代码提交版本 hash, 若不存在 (非 CI 构建) 则为 native /// public string Commit { get; } = _SecretCommitInfo ?? "native"; /// /// 代码提交版本 hash 的摘要 (取前 7 位), 若不存在 (非 CI 构建) 则为 native /// public string CommitDigest { get; } = _SecretCommitInfo?[..7] ?? "native"; public override string ToString() { return $"{BranchName} {BaseName} ({Code}, {CommitDigest})"; } } /// /// 第三方内容许可信息模型 /// /// 内容名称 /// 许可信息 /// 网站 URI /// 许可证 URI public sealed record ThirdPartyLicenseModel( [property: JsonPropertyName("name")] string Name, [property: JsonPropertyName("info")] string Information, [property: JsonPropertyName("website")] string? WebsiteUri = null, [property: JsonPropertyName("license")] string? LicenseUri = null ); /// /// 启动器元数据模型 /// /// 程序名称 /// 版本信息 public sealed record MetadataModel( [property: JsonPropertyName("name")] string Name, [property: JsonPropertyName("version")] LauncherVersionModel Version, [property: JsonPropertyName("licenses")] ThirdPartyLicenseModel[] Licenses );