using System;
using UnityEngine;
namespace AOT.Patch
{
[Serializable]
public class VersionInfo
{
public string appVersionMin = "1.0.0";
public string appVersionMax = "1.0.0";
public string resVersion = "0";
public string cdnRoot = "https://www.xworld.ren/wechat/1.0.0";
public string[] packages = { "DefaultPackage" };
public bool forceUpdate;
public string notice = "";
/// 兼容旧版本字段;当前 UI 仅支持 candy,其他主题值回退到 Candy。
public string uiTheme;
public static VersionInfo FromJson(string json)
{
if (string.IsNullOrEmpty(json))
return null;
try
{
return JsonUtility.FromJson(json);
}
catch (Exception e)
{
Debug.LogError($"[VersionInfo] parse failed: {e.Message}");
return null;
}
}
public static int CompareVersion(string a, string b)
{
if (string.IsNullOrEmpty(a) && string.IsNullOrEmpty(b)) return 0;
if (string.IsNullOrEmpty(a)) return -1;
if (string.IsNullOrEmpty(b)) return 1;
var pa = a.Split('.');
var pb = b.Split('.');
int n = Mathf.Max(pa.Length, pb.Length);
for (int i = 0; i < n; i++)
{
int va = i < pa.Length && int.TryParse(pa[i], out var xa) ? xa : 0;
int vb = i < pb.Length && int.TryParse(pb[i], out var xb) ? xb : 0;
if (va != vb) return va.CompareTo(vb);
}
return 0;
}
}
}