using System; using System.Data; using System.Net.Http; using Cysharp.Threading.Tasks; using Godot; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace BITKit.Apps; [CustomType(typeof(IApplicationService))] public partial class GodotBasedApplicationService:EntityBehaviour, IApplicationService { private static readonly System.Net.Http.HttpClient _httpClient = new(); [Export] public string DownloadLatestUrl { get; set; } [Export] public string CheckLatestVersionUrl { get; set; } public event Action OnClientVersionCheck; public event Action OnLatestVersionCheck; public event Action OnDownloadLatest; public event Action OnDownloadProgress; public event Action OnDownloadComplete; public event Action OnDetectedLatestVersion; public override async void OnStart() { BIT4Log.Log("正在初始化..."); var clientVersion = ProjectSettings.GetSetting("application/config/version").AsString(); BIT4Log.Log($"当前版本:{clientVersion}"); OnClientVersionCheck?.Invoke(clientVersion); var response =await _httpClient.GetAsync(CheckLatestVersionUrl,Entity.CancellationToken); if (response.IsSuccessStatusCode is false) { throw new HttpRequestException(response.StatusCode.ToString()); } var version =await response.Content.ReadAsStringAsync(Entity.CancellationToken); OnLatestVersionCheck?.Invoke(version); if (clientVersion != version) { OnDetectedLatestVersion?.Invoke(); } BIT4Log.Log($"最新版本:{version}"); } public UniTask DownloadLatestVersionAsync() { throw new NotImplementedException(); } }