Пример #1
0
        /// <summary>
        /// 处理上次可能失败的升级流程
        /// </summary>
        /// <returns>是否执行异常处理</returns>
        private static bool HandleProcException()
        {
            bool res = false;

            try
            {
                BarControl.InitAllParam();
                if (Utils.SetServerUrl())
                {
                    BarControl.IsHandleEx = true;
                    if (File.Exists(updateZipPath))
                    {
                        config = Utils.GetUpdateConfig();
                        Logger.Info("Has UpdatePackage.zip,continue operate");
                        string zipMD5 = Utils.GetMD5Value(updateZipPath);
                        if (zipMD5 == config.MD5)
                        {
                            res = true;
                            Task.Factory.StartNew(() =>
                            {
                                Application.Run(new Form1());
                            });
                            if (Utils.ExtractFile(updateZipPath, basePath))
                            {
                                Logger.Info("ExtractFile success");
                                RunUpateProc();
                            }
                            else
                            {
                                Logger.Info("Extract file failed");
                                ClearAllPackage();
                                //解压文件失败
                                BarControl.IsEndFail = true;
                            }
                        }
                        else
                        {
                            Logger.Warn("MD5 is defferent,delete zip file");
                            Utils.DeleteFile(updateZipPath);
                            ClearAllPackage();
                        }
                    }
                }
                else
                {
                    Logger.Info("UpdateUrl is null");
                }
            }
            catch (Exception ex)
            {
                Logger.Error("HandleProcException err:" + ex);
            }
            finally
            {
                BarControl.SetAllARE();
            }
            return(res);
        }
Пример #2
0
        private static bool CheckUpdate()
        {
            try
            {
                if (Utils.SetServerUrl())
                {
                    curVersion = Utils.GetCurVersion();

                    config = Utils.GetUpdateConfig();
                    if (Utils.IsNewVersion(config.Version, curVersion))
                    {
                        while (true)
                        {
                            if (config.Mandatory)
                            {
                                downloadPackagePath = GetUpdatePackage(config);
                                return(true);
                            }
                            else
                            {
                                if (Utils.NoticeUser(config.Message))
                                {
                                    Task.Factory.StartNew(() =>
                                    {
                                        Application.Run(new Form1());
                                    });
                                    downloadPackagePath = GetUpdatePackage(config);
                                    return(true);
                                }
                                else
                                {
                                    Thread.Sleep(config.TimSpan * 1000);
                                }
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    Logger.Info("UpdateUrl is null");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("CheckUpdate err:" + ex.Message);
                return(false);
            }
            finally
            {
                BarControl.SetBarStep(BarStep.Download);
            }
        }
Пример #3
0
 private static string GetUpdatePackage(UpdateConfig config)
 {
     try
     {
         string filePath = Utils.DownloadPackage(config.Url, Cst.PackageName);
         string md5      = Utils.GetMD5Value(filePath);
         if (config.MD5 == md5)
         {
             return(filePath);
         }
         else
         {
             Utils.DeleteFile(filePath);
             throw new ArgumentException("Validate MD5 err");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }