using System; using System.Data; using System.Net.Http; using Cysharp.Threading.Tasks; using Godot; using IDIS; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace BITKit.Apps; public partial class GodotBasedApplicationService:EntityComponent, 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; private ILogger _logger; public override void BuildService(IServiceCollection serviceCollection) { serviceCollection.AddSingleton(this); } public override async void OnStart() { _logger = Entity.ServiceProvider.GetRequiredService>(); var clientVersion = ProjectSettings.GetSetting("application/config/version").AsString(); _logger.LogInformation($"当前版本:{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(); } _logger.LogInformation($"最新版本:{version}"); } public UniTask DownloadLatestVersionAsync() { throw new NotImplementedException(); } }