コード例 #1
0
        /// <summary>
        /// 获得最后的版本信息
        /// </summary>
        void GetLastVersionInfo()
        {
            var path = Path.Combine(CacheManager.Instance.Version.URL, CacheManager.Instance.Version.Path);

            WebClientPro client = new WebClientPro(10 * 1000);

            try
            {
                var bytes = client.DownloadData(path);

                string serviceInfo = Encoding.UTF8.GetString(client.DownloadData(path));
                var serviceUpdate = serviceInfo.XmlDeserailize<ServiceUpdate>();

                // 获取原始路径
                if (File.Exists("target.info"))
                {
                    var targetPath = (string)"target.info".FileDeSerialize();

                    if (Directory.Exists(targetPath))
                        Directory.Delete(targetPath, true);
                }

                var localVersion = new Version(CacheManager.Instance.Version.Version);
                var serviceVersion = new Version(serviceUpdate.Version);

                if (localVersion < serviceVersion)
                {
                    CheckUpdate checkUpdate = new CheckUpdate();
                    checkUpdate.Closed += (s, arg) =>
                    {
                        if (!checkUpdate.DialogResult.Value)
                        {
                            System.Environment.Exit(-1);
                        }
                    };
                    checkUpdate.ShowDialog();
                }
                else
                {
                    LogManager.Logger.Info($"localVersion:{localVersion} serviceVersion:{serviceVersion}");
                }
            }
            catch (Exception ex)
            {
                LogManager.Logger.Warn($"GetLastVersionInfo {ex.Message}");
                return;
            }
        }
コード例 #2
0
        public CheckUpdateModel()
        {
            ZipHelper.ExtractProgress += ZipHelper_ExtractProgress;
            FileHelper.CopyProgress   += FileHelper_CopyProgress;

            if (!System.IO.File.Exists(CommonPath.ClientUpdate.CombineCurrentDirectory()))
            {
                LogManager.Logger.Warn($"没有找到 {CommonPath.ClientUpdate.CombineCurrentDirectory()}");
                return;
            }

            // 获取本地版本
            CacheManager.Instance.Version = CommonPath.ClientUpdate.LoadFromXml <ClientUpdate>();

            // 获取服务端版本
            var path = CacheManager.Instance.Version.URL + CacheManager.Instance.Version.Path;

            try
            {
                WebClientPro client      = new WebClientPro();
                string       serviceInfo = Encoding.UTF8.GetString(client.DownloadData(path));
                _serviceUpdate = serviceInfo.XmlDeserailize <ServiceUpdate>();

                var localVersion   = $"{CacheManager.Instance.Version.Version}_{CacheManager.Instance.Version.VersionType}";
                var serviceVersoin = $"{_serviceUpdate.Version}_{_serviceUpdate.VersionType}";

                this.Message = $"发现最新版本:{serviceVersoin},升级?";

                StringBuilder strb = new StringBuilder();
                strb.AppendLine($"{serviceVersoin} 升级:");
                strb.Append(_serviceUpdate.Conent);

                this.Content = strb.ToString();
            }
            catch (Exception ex)
            {
                LogManager.Logger.Warn($"下载版本信息失败:{ex.Message}");
            }
        }