示例#1
0
        /// <summary>
        /// 解压zip文件
        /// </summary>
        /// <param name="zipFilePath">.zip压缩包路径</param>
        /// <param name="extractPath">存放解压后文件路径</param>
        /// <returns></returns>
        public static bool ExtractFile(string zipFilePath, string extractPath)
        {
            if (string.IsNullOrEmpty(zipFilePath))
            {
                Logger.Error("zipFilePath can not null.");
                return(false);
            }
            if (!Directory.Exists(extractPath))
            {
                Directory.CreateDirectory(extractPath);
            }
            var name = Path.GetFileNameWithoutExtension(zipFilePath);

            try
            {
                var filePath = Path.Combine(extractPath, name);
                if (Directory.Exists(filePath))
                {
                    Directory.Delete(filePath, true);
                }

                ZipFile.ExtractToDirectory(zipFilePath, filePath);
                return(true);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("ExtractFile err,file:{0},{1}", zipFilePath, ex);
                return(false);
            }
            finally
            {
                BarControl.SetBarStep(BarStep.Extract);
            }
        }
示例#2
0
        public static bool Update()
        {
            try
            {
                desPathList.Clear();
                //Save Path
                GreateDesUpdatePath(updatePath);

                //backUp
                bakCount = 0;
                BakFile();
                Logger.Info("BakFile count:" + bakCount);

                //stop.exe
                Utils.RunCmd(1);

                //Replace
                rpcCount = 0;
                ReplaceFile();
                Logger.Info("ReplaceFile count:" + rpcCount);

                //start .exe
                Utils.RunCmd(0);
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error("Update err:" + ex);
                return(false);
            }
            finally
            {
                BarControl.SetBarStep(BarStep.Replace);
            }
        }
示例#3
0
 public static void RunUpdateProcByTimeSpan()
 {
     while (true)
     {
         Logger.Info("Start check update server version");
         BarControl.InitAllParam();
         if (CheckUpdate())
         {
             if (Utils.ExtractFile(downloadPackagePath, basePath))
             {
                 Logger.Info("ExtractFile success");
                 RunUpateProc();
             }
             else
             {
                 Logger.Info("Extract file failed");
                 ClearAllPackage();
                 //解压文件失败
                 BarControl.IsEndFail = true;
             }
         }
         else
         {
             BarControl.IsEndFail = true;
         }
         BarControl.SetAllARE();
         Thread.Sleep(timeSpan * 60 * 1000);
     }
 }
示例#4
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);
        }
示例#5
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);
            }
        }