Exemplo n.º 1
0
        /// <summary>
        /// 解析补丁信息
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        private static PatchInfo ParsePatchInfo(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(null);
            }
            string[] pa = s.Split('&');
            if (pa == null || pa.Length == 0)
            {
                return(null);
            }

            PatchInfo patchInfo = new PatchInfo();

            patchInfo.DownloadPath = pa[0];
            patchInfo.InstallStyle = "update";
            if (pa.Length > 1)
            {
                patchInfo.InstallStyle = pa[1];
            }

            return(patchInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 执行文件升级
        /// </summary>
        /// <param name="patchInfo"></param>
        /// <param name="tempPath"></param>
        /// <param name="updatePath"></param>
        public static void DoUpdate(PatchInfo patchInfo, string tempPath, string updatePath)
        {
            if (patchInfo == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(patchInfo.DownloadPath))
            {
                return;
            }

            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            Directory.CreateDirectory(tempPath);

            string installStyle = patchInfo.InstallStyle.Trim().ToLower();
            string extension    = Path.GetExtension(patchInfo.DownloadPath).ToLower();

            if (installStyle == "update")
            {
                if (extension == ".zip")
                {
                    // 解压缩文件
                    ZipHelper.Extract(patchInfo.DownloadPath, tempPath);
                    CopyFiles(tempPath, updatePath);
                }
                else
                {
                    CopyFileToDir(patchInfo.DownloadPath, updatePath);
                }
            }
            else if (installStyle == "install")
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.UseShellExecute = false;  // 不弹出shell
                if (extension == ".cab")
                {
                    // 拷贝到temp目录下
                    CopyFileToDir(patchInfo.DownloadPath, tempPath);
                    string installfile = Path.Combine(tempPath, Path.GetFileName(patchInfo.DownloadPath));

                    //wceload命令格式: wceload [ /noaskdest | /askdest ] [ /delete <number> | /noui | /nouninstall ] <cab file location>
                    // noaskdest不提示安装路径;askdest提示安装路径
                    // delete后的number可选:0为不删除;1为删除
                    // noui为不弹出任何窗体进行安装
                    // noinstall安装后的应用程序不能被卸载

                    startInfo.FileName  = "wceload";
                    startInfo.Arguments = "/noui " + installfile;
                }
                else
                {
                    startInfo.FileName = patchInfo.DownloadPath;
                }

                Process.Start(startInfo);
            }

            Directory.Delete(tempPath, true);
        }