示例#1
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);
            }
        }
示例#2
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);
            }
        }
示例#3
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);
            }
        }