XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
UTF-8
using ApplicationUpgradeManager.Core.Model;
using SpaceEngineersBlueprintEditor.Profiles;
using System.Diagnostics;
using System.Reflection;
using XFEExtension.NetCore.UpgradeHelper.Utilities;

namespace SpaceEngineersBlueprintEditor.Utilities.Helpers;

public static class UpgradeHelper
{
    public static string RequestAddress => UnloadProfile.ServerUrl;
    public static Upgrader Upgrader { get; set; } = new(RequestAddress);
    public static Version Version => Assembly.GetExecutingAssembly().GetName().Version ?? new Version(1, 0, 0);

    /// <summary>
    /// 检测是否需要更新
    /// </summary>
    /// <returns></returns>
    public static async Task<bool> NeedUpgrade() => (await Upgrader.GetReleaseNotes("太空工程师蓝图编辑器", Version.ToString())).IsLatest;

    /// <summary>
    /// 获取更新信息
    /// </summary>
    /// <returns></returns>
    public static async Task<UpgradeInfoNotes> GetReleaseNotes() => await Upgrader.GetReleaseNotes("太空工程师蓝图编辑器", Version.ToString());

    /// <summary>
    /// 开始更新
    /// </summary>
    public static void StartUpdate(string downloadUrl)
    {
        var startInfo = new ProcessStartInfo("SpaceEngineersBlueprintEditor.Installer.exe")
        {
            UseShellExecute = true,
            Verb = "runas"
        };
        startInfo.ArgumentList.Add("Upgrade");
        startInfo.ArgumentList.Add(downloadUrl);
        startInfo.ArgumentList.Add("");
        Process.Start(startInfo);
        Process.GetCurrentProcess().Kill();
        Application.Current.Exit();
    }
}