56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
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<string> OnClientVersionCheck;
|
|
public event Action<string> OnLatestVersionCheck;
|
|
public event Action<string> OnDownloadLatest;
|
|
public event Action<float> OnDownloadProgress;
|
|
public event Action<string> OnDownloadComplete;
|
|
public event Action OnDetectedLatestVersion;
|
|
|
|
|
|
public override async void OnStart()
|
|
{
|
|
BIT4Log.Log<IApplicationService>("正在初始化...");
|
|
|
|
var clientVersion = ProjectSettings.GetSetting("application/config/version").AsString();
|
|
|
|
BIT4Log.Log<IApplicationService>($"当前版本:{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<IApplicationService>($"最新版本:{version}");
|
|
}
|
|
|
|
public UniTask<string> DownloadLatestVersionAsync()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |