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

📄 liveupdate.cs

📁 飞信的收发使用csharp进行开发
💻 CS
📖 第 1 页 / 共 2 页
字号:
        {
            if (!IsDisabledLiveUpdate())
            {
                Instance._mainWnd = mainWnd;
                Imps.Client.Pc.LiveUpdate instance = Instance;
                instance.OnCheckComplete = (EventHandler<UpdateInfo>) Delegate.Combine(instance.OnCheckComplete, new EventHandler<UpdateInfo>(Instance.Update_OnCheckComplete));
                Random random = new Random(Environment.TickCount);
                Instance._checkSpan = ((random.Next(10, 20) * 60) * 60) * 0x3e8;
                GlobalTimer.Register(delegate {
                    Instance.AsyncCheck(false);
                }, 0x1770, TimerHandlerPriority.Lowest);
                Instance.AsyncCheck(false);
            }
        }

        private static void Download()
        {
        }

        private void ForceCheck()
        {
            this.Check(true);
        }

        private static void Install()
        {
        }

        private static bool IsDisabledLiveUpdate()
        {
            return string.Equals(Imps.Client.Core.FixedClientSetting.Instance.Debug_LiveUpdateSwitch, "Off", StringComparison.OrdinalIgnoreCase);
        }

        private void Update_OnCheckComplete(object sender, UpdateInfo e)
        {
            bool flag2;
            Mutex mutex;
            string fullPath = StaticTools.GetFullPath(this.WorkPath.SvrInfoFile + ".target");
            bool flag = System.IO.File.Exists(fullPath);
            if (_isNotifiedUser)
            {
                return;
            }
            try
            {
                _isNotifiedUser = true;
                if (flag)
                {
                    using (ContinueUpdate update = new ContinueUpdate(e, this._mainWnd))
                    {
                        if (update.ShowUpdate() == DialogResult.Yes)
                        {
                            goto Label_0084;
                        }
                        return;
                    }
                }
                using (PromptLiveUpdate update2 = new PromptLiveUpdate(e, this._mainWnd))
                {
                    if (update2.ShowUpdate() != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }
            finally
            {
                _isNotifiedUser = false;
            }
        Label_0084:
            mutex = new Mutex(true, "Imps.pc.client.liveupdate", out flag2);
            if (flag2)
            {
                try
                {
                    if (!string.IsNullOrEmpty(this._liveupdateUrl))
                    {
                        this._mainWnd.AccountManager.LogoutForcibly();
                        this._mainWnd.HideMainWindow();
                        string path = StaticTools.GetFullPath(this.WorkPath.ClientUpdateFile);
                        string downloadUrl = string.Empty;
                        if (string.IsNullOrEmpty(e.DownloadURL))
                        {
                            downloadUrl = "http://www.fetion.com.cn";
                        }
                        else
                        {
                            try
                            {
                                Uri uri = new Uri(new Uri(this._liveupdateUrl), e.DownloadURL);
                                downloadUrl = uri.AbsoluteUri;
                            }
                            catch
                            {
                                downloadUrl = "http://www.fetion.com.cn";
                            }
                        }
                        if (flag)
                        {
                            UpdateInfo info = new UpdateInfo(fullPath);
                            if (((info.TargetVersion != e.TargetVersion) || (info.HashCode != e.HashCode)) || (info.DownloadURL != e.DownloadURL))
                            {
                                System.IO.File.Delete(path);
                                System.IO.File.Delete(path + ".Downloading");
                            }
                            System.IO.File.Delete(fullPath);
                        }
                        System.IO.File.Move(StaticTools.GetFullPath(this.WorkPath.SvrInfoFile), fullPath);
                        do
                        {
                            if (!System.IO.File.Exists(path))
                            {
                                using (Downloading downloading = new Downloading(e, this._mainWnd, downloadUrl))
                                {
                                    StaticTools.LogMessage(this.WorkPath.LogFile, "开始下载更新包");
                                    if (downloading.ShowDialog() != DialogResult.Yes)
                                    {
                                        Application.Exit();
                                        break;
                                    }
                                    StaticTools.LogMessage(this.WorkPath.LogFile, "成功下载更新包");
                                }
                            }
                            if (e.HashCode != string.Empty)
                            {
                                byte[] buffer = null;
                                using (FileStream stream = new FileStream(StaticTools.GetFullPath(this._workPath.ClientUpdateFile), FileMode.Open))
                                {
                                    buffer = new MD5CryptoServiceProvider().ComputeHash(stream);
                                }
                                if (buffer != null)
                                {
                                    StringBuilder builder = new StringBuilder();
                                    for (int i = 0; i < buffer.Length; i++)
                                    {
                                        builder.Append(buffer[i].ToString("x2"));
                                    }
                                    if (builder.ToString() != e.HashCode)
                                    {
                                        System.IO.File.Delete(path);
                                        if (this._mainWnd.UnifiedMessageBox.ShowConfirmation("下载的文件已经损坏,是否重新下载?\r\n选择“是”重新下载;选择“否”退出应用程序") == DialogResult.No)
                                        {
                                            Application.Exit();
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        while (!System.IO.File.Exists(path));
                        RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Fetion");
                        key.SetValue("TargetBuildTime", Imps.Client.Core.FixedClientSetting.Instance.BuildDate.ToString("yyyyMMddHHmmss"));
                        key.SetValue("UpdateString", ImpsPathInfo.StartupPath);
                        try
                        {
                            StaticTools.LogMessage(this.WorkPath.LogFile, "开始安装更新");
                            Process process = new Process();
                            process.StartInfo = new ProcessStartInfo(path, string.Empty);
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                            process.Start();
                        }
                        catch (Win32Exception exception)
                        {
                            this._mainWnd.UnifiedMessageBox.ShowError("安装更新失败,安装程序没有获得足够的权限!应用程序将退出。");
                            StaticTools.LogError(this.WorkPath.LogFile, exception);
                        }
                        catch (Exception exception2)
                        {
                            this._mainWnd.UnifiedMessageBox.ShowError("安装更新失败,请检查更新文件是否已经损坏!应用程序将退出。");
                            StaticTools.LogError(this.WorkPath.LogFile, exception2);
                        }
                        finally
                        {
                            Application.Exit();
                        }
                    }
                }
                catch (Exception exception3)
                {
                    StaticTools.LogError(this.WorkPath.LogFile, exception3);
                }
                finally
                {
                    mutex.ReleaseMutex();
                }
            }
            else
            {
                this._mainWnd.UnifiedMessageBox.ShowInfo("有其他进程在下载更新!");
            }
        }

        private static Imps.Client.Pc.LiveUpdate Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new Imps.Client.Pc.LiveUpdate();
                }
                return _instance;
            }
        }

        public WorkPathInfo WorkPath
        {
            get
            {
                return this._workPath;
            }
        }
    }
}

⌨️ 快捷键说明

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