⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liveupdate.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Imps.Client.Pc
{
    using Imps.Client.Base;
    using Imps.Client.Core;
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using Imps.Utils;
    using Microsoft.Win32;
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.IO;
    using System.Net;
    using System.Runtime.CompilerServices;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading;
    using System.Windows.Forms;
    using System.Xml;

    internal class LiveUpdate
    {
        private bool _canLogin = true;
        private double _checkSpan;
        private static DateTime _checkTime;
        private static Imps.Client.Pc.LiveUpdate _instance;
        private static bool _isNotifiedUser = false;
        private string _liveupdateUrl;
        private IFrameworkWindow _mainWnd;
        private WorkPathInfo _workPath = new WorkPathInfo();
        private static object locker = new object();
        private static object signal = new object();
        private UpdateInfo updateInfo;

        public event EventHandler<UpdateInfo> OnCheckComplete;

        private void AsyncCheck(bool forceCheck)
        {
            try
            {
                Thread thread = null;
                if (forceCheck)
                {
                    thread = new Thread(new ThreadStart(this.ForceCheck));
                    thread.Name = "Imps.Client.Pc CheckUpdate.Force";
                    thread.IsBackground = true;
                    thread.Priority = ThreadPriority.Highest;
                }
                else
                {
                    thread = new Thread(new ThreadStart(this.AutoCheck));
                    thread.Name = "Imps.Client.Pc CheckUpdate.Auto";
                    thread.IsBackground = true;
                    thread.Priority = ThreadPriority.Lowest;
                }
                thread.Start();
            }
            catch
            {
                this._canLogin = true;
            }
        }

        private void AutoCheck()
        {
            this.Check(false);
        }

        private bool CanLogin()
        {
            this.Check(true);
            return this._canLogin;
        }

        private void Check(bool forceCheck)
        {
            if (IsDisabledLiveUpdate())
            {
                this._canLogin = true;
            }
            this.updateInfo = null;
            lock (locker)
            {
                DateTime time1 = _checkTime;
                TimeSpan span = (TimeSpan) (DateTime.Now - _checkTime);
                if ((forceCheck && (span.TotalHours < 1)) || (!forceCheck && (span.TotalMilliseconds < this._checkSpan)))
                {
                    return;
                }
                try
                {
                    this._liveupdateUrl = (Imps.Client.Core.FixedClientSetting.Instance.Debug_LiveupdateUrl ?? string.Empty).Trim();
                    ClientLogger.WriteGeneral("检查系统更新……");
                    HttpWebRequest request = ConnectionFactory.CreateHttpWebRequest(Imps.Client.Core.FixedClientSetting.Instance.NavigatorServerUri, this._mainWnd.AccountManager.CurrentUser, true, false);
                    using (Stream w = request.GetRequestStream())
                    {
                        XmlTextWriter writer = new XmlTextWriter(w, Encoding.ASCII);
                        writer.WriteStartElement("config");
                        writer.WriteStartElement("client");
                        writer.WriteAttributeString("type", "PC");
                        writer.WriteAttributeString("version", Imps.Client.Core.Configuration.FixedClientSetting.Version);
                        writer.WriteAttributeString("platform", EnvHelper.GetOsString());
                        writer.WriteEndElement();
                        writer.WriteStartElement("client-config");
                        writer.WriteAttributeString("version", "0");
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                        writer.Flush();
                    }
                    using (HttpWebResponse response = ((HttpWebResponse) request.GetResponse()))
                    {
                        using (Stream inStream = response.GetResponseStream())
                        {
                            XmlDocument document = new XmlDocument();
                            document.Load(inStream);
                            if (string.IsNullOrEmpty(this._liveupdateUrl))
                            {
                                XmlNode node = document.SelectSingleNode("config/client/pc-live-update");
                                if (node != null)
                                {
                                    this._liveupdateUrl = node.Attributes["value"].Value;
                                }
                            }
                            XmlNode node2 = document.SelectSingleNode("config/client-config/item[@key='mobile-no-dist']");
                            if (node2 != null)
                            {
                                try
                                {
                                    ImpsHelper.MobileNoDist = node2.Attributes["value"].Value;
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                    if (!this._liveupdateUrl.EndsWith("/"))
                    {
                        this._liveupdateUrl = this._liveupdateUrl + "/";
                    }
                    if (IsDisabledLiveUpdate() || string.IsNullOrEmpty(this._liveupdateUrl))
                    {
                        return;
                    }
                    string url = this._liveupdateUrl + "UpdateInfo.ashx" + "?Version=" + HttpWebRequestHelper.UrlEncode(Imps.Client.Core.FixedClientSetting.Instance.Version) + "&Switch=" + HttpWebRequestHelper.UrlEncode(Imps.Client.Core.FixedClientSetting.Instance.Debug_LiveUpdateSwitch) + "&Branch=" + HttpWebRequestHelper.UrlEncode(Imps.Client.Core.FixedClientSetting.Instance.Branch);
                    if (!string.IsNullOrEmpty(UserAccounts.LatestId))
                    {
                        url = url + "&MobileNum=" + UserAccounts.LatestId;
                    }
                    else
                    {
                        url = url + "&MobileNum=";
                    }
                    string svrConfigName = StaticTools.GetFullPath(this.WorkPath.SvrInfoFile);
                    this.CheckConfigFile(svrConfigName);
                    StaticTools.LogMessage(this.WorkPath.LogFile, "开始下载ServerVersion.xml");
                    request = ConnectionFactory.CreateHttpWebRequest(url, this._mainWnd.AccountManager.CurrentUser, false, false);
                    StaticTools.LogMessage(this.WorkPath.LogFile, "下载地址:" + url);
                    using (HttpWebResponse response2 = ((HttpWebResponse) request.GetResponse()))
                    {
                        if (response2.StatusCode == HttpStatusCode.OK)
                        {
                            using (Stream configStream = response2.GetResponseStream())
                            {
                                this.updateInfo = new UpdateInfo(configStream);
                            }
                        }
                        StaticTools.LogMessage(this.WorkPath.LogFile, "下载http应答:" + response2.StatusCode.ToString());
                    }
                    StaticTools.LogMessage(this.WorkPath.LogFile, "成功下载ServerVersion.xml");
                    _checkTime = DateTime.Now;
                    if ((this.updateInfo == null) || (this.updateInfo.Type != UpdateType.force))
                    {
                        this._canLogin = true;
                    }
                    else
                    {
                        this._canLogin = false;
                    }
                }
                catch (Exception exception)
                {
                    ClientLogger.WriteGeneral("检查更新失败", exception.ToString(), 20);
                    try
                    {
                        StaticTools.LogError(this.WorkPath.LogFile, exception);
                    }
                    catch
                    {
                    }
                    this._liveupdateUrl = string.Empty;
                    this.updateInfo = null;
                    try
                    {
                        File.Delete(StaticTools.GetFullPath(this.WorkPath.SvrInfoFile));
                        File.Delete(StaticTools.GetFullPath(this.WorkPath.SvrInfoFile + ".downloading"));
                    }
                    catch
                    {
                    }
                    this._canLogin = true;
                    return;
                }
            }
            if (((this.updateInfo != null) && (this.updateInfo.TargetVersion != HttpWebRequestHelper.UrlEncode(Imps.Client.Core.FixedClientSetting.Instance.Version))) && (this.OnCheckComplete != null))
            {
                FuncDispatcher.InvokeEventHandlerInUiThread<UpdateInfo>(this, this.OnCheckComplete, this.updateInfo);
            }
            else
            {
                StaticTools.LogMessage(this.WorkPath.LogFile, "不需要进行更新");
                try
                {
                    File.Delete(StaticTools.GetFullPath(this.WorkPath.SvrInfoFile));
                    File.Delete(StaticTools.GetFullPath(this.WorkPath.SvrInfoFile + ".target"));
                    File.Delete(StaticTools.GetFullPath(this.WorkPath.SvrInfoFile + ".Downloading"));
                    File.Delete(StaticTools.GetFullPath(this.WorkPath.ClientUpdateFile));
                    File.Delete(StaticTools.GetFullPath(this.WorkPath.ClientUpdateFile + ".Downloading"));
                }
                catch
                {
                }
            }
        }

        private void CheckConfigFile(string svrConfigName)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -