Exemplo n.º 1
0
        public static void CloseApplication()
        {
            OperProcess op = new OperProcess();

            //启动进程
            op.StartProcess();
        }
Exemplo n.º 2
0
 void InitCheckUpdate()
 {
     #region check and download new version program
     bool         bHasError   = false;
     IAutoUpdater autoUpdater = new KnightsWarriorAutoupdater.AutoUpdater();
     try
     {
         autoUpdater.Update();
     }
     catch (WebException exp)
     {
         MessageBox.Show("服务器连接失败");
         bHasError = true;
     }
     catch (XmlException exp)
     {
         bHasError = true;
         MessageBox.Show("下载更新文件错误");
     }
     catch (NotSupportedException exp)
     {
         bHasError = true;
         MessageBox.Show("升级文件配置错误");
     }
     catch (ArgumentException exp)
     {
         bHasError = true;
         MessageBox.Show("下载升级文件错误");
     }
     catch (Exception exp)
     {
         bHasError = true;
         MessageBox.Show("更新过程中出现错误");
     }
     finally
     {
         if (bHasError == true)
         {
             try
             {
                 autoUpdater.RollBack();
             }
             catch (Exception)
             {
                 //Log the message to your file or database
             }
         }
         OperProcess op = new OperProcess();
         //启动进程
         op.StartProcess();
         //  this.Close();
     }
     #endregion
 }
Exemplo n.º 3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            AutoUpdater au = new AutoUpdater();

            try
            {
                au.Update();
            }
            catch (WebException exp)
            {
                MessageBox.Show(String.Format("无法找到指定资源\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (XmlException exp)
            {
                MessageBox.Show(String.Format("下载的升级文件有错误\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (NotSupportedException exp)
            {
                MessageBox.Show(String.Format("升级地址配置错误\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (ArgumentException exp)
            {
                MessageBox.Show(String.Format("下载的升级文件有错误\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception exp)
            {
                MessageBox.Show(String.Format("升级过程中发生错误\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                OperProcess oper   = new OperProcess();
                Config      config = Config.LoadConfig(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FILENAME));
                //如果用户点击过更新但是没有更新完,则强制用户继续更新
                if (config.IsUpdate)
                {
                    Application.Exit();
                }
                else
                {
                    oper.StartProcess();
                }
            }
        }
Exemplo n.º 4
0
        public void Update()
        {
            if (!config.Enabled)
            {
                return;
            }

            Dictionary <string, RemoteFile> listRemotFile = ParseRemoteXml(config.ServerUrl);
            List <DownloadFileInfo>         downloadList  = new List <DownloadFileInfo>();

            foreach (LocalFile file in config.UpdateFileList)
            {
                if (listRemotFile.ContainsKey(file.Path))
                {
                    RemoteFile rf = listRemotFile[file.Path];
                    //Version v1 = new Version(rf.LastVer);
                    //Version v2 = new Version(file.LastVer);
                    //if (v1 > v2)
                    string v1 = rf.Verison;
                    string v2 = file.Version;
                    if (v1 != v2)
                    {
                        downloadList.Add(new DownloadFileInfo(rf.Url, rf.Path, rf.LastVer, rf.Size, rf.Verison));
                        file.Path    = rf.Path;
                        file.LastVer = rf.LastVer;
                        file.Size    = rf.Size;
                        file.Version = rf.Verison;
                        if (rf.NeedRestart)
                        {
                            bNeedRestart = true;
                        }

                        bDownload = true;
                    }

                    listRemotFile.Remove(file.Path);
                }
            }

            foreach (RemoteFile file in listRemotFile.Values)
            {
                downloadList.Add(new DownloadFileInfo(file.Url, file.Path, file.LastVer, file.Size, file.Verison));
                bDownload = true;
                config.UpdateFileList.Add(new LocalFile(file.Path, file.LastVer, file.Size, file.Verison));
                if (file.NeedRestart)
                {
                    bNeedRestart = true;
                }
            }

            downloadFileListTemp = downloadList;

            if (bDownload)
            {
                OperProcess op = new OperProcess();
                op.InitUpdateEnvironment();
                DownloadConfirm dc = new DownloadConfirm(downloadList);

                if (this.OnShow != null)
                {
                    this.OnShow();
                }
                StartDownload(downloadList);
            }
        }
Exemplo n.º 5
0
        void InitCheckUpdate()
        {
            #region check and download new version program
            bool         bHasError   = false;
            IAutoUpdater autoUpdater = new Autoupdater.AutoUpdater();
            try
            {
                autoUpdater.CheckUpdate();
                if (autoUpdater.HasUpdate)
                {
                    DialogResult result = MessageBox.Show("发现有新版本!确定要更新吗?如选择更新,将关闭此程序,请自行重启!", "新版本提醒", MessageBoxButtons.OKCancel);
                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        //杀死进程
                        System.Diagnostics.Process[] process1 = System.Diagnostics.Process.GetProcessesByName("DEncryptTool");
                        foreach (var process in process1)
                        {
                            process.Kill();
                        }
                        System.Diagnostics.Process[] process2 = System.Diagnostics.Process.GetProcessesByName("Codematic");
                        foreach (var process in process2)
                        {
                            process.Kill();
                        }
                        System.Diagnostics.Process[] process3 = System.Diagnostics.Process.GetProcessesByName("StartCodematic");
                        foreach (var process in process3)
                        {
                            process.Kill();
                        }

                        //执行更新
                        autoUpdater.StartUpdate();
                    }
                }
            }
            catch (WebException exp)
            {
                MessageBox.Show("服务器连接失败");
                bHasError = true;
            }
            catch (XmlException exp)
            {
                bHasError = true;
                MessageBox.Show("下载更新文件错误");
            }
            catch (NotSupportedException exp)
            {
                bHasError = true;
                MessageBox.Show("升级文件配置错误");
            }
            catch (ArgumentException exp)
            {
                bHasError = true;
                MessageBox.Show("下载升级文件错误");
            }
            catch (Exception exp)
            {
                bHasError = true;
                MessageBox.Show("更新过程中出现错误");
            }
            finally
            {
                if (bHasError == true)
                {
                    try
                    {
                        autoUpdater.RollBack();
                    }
                    catch (Exception)
                    {
                        //Log the message to your file or database
                    }
                }
                OperProcess op = new OperProcess();
                //启动进程
                op.StartProcess();
                //  this.Close();
            }
            #endregion
        }