private string Download(string file, AppUpdateInfo info, ProgressDelegate.ProgressHandler progress = null, object sender = null) { if (info != null) { switch (info.DownloadMode) { case 0: //http 下载 { if (HttpTool.Download(info.HttpUrl, file, progress, sender)) { return(file); } } break; case 1: //ftp 下载 { FtpTool ftp = new FtpTool(info.FtpIp, info.FtpAccount, info.FtpPassword); if (ftp.Download(info.FtpFile, file, progress, sender)) { return(file); } } break; } } return(null); }
/// <summary> /// 下载要更新的文件 /// </summary> /// <param name="vm"></param> /// <returns></returns> private bool UpdateDownload(VersionModel vm) { FileCodeTool fcode = new FileCodeTool(); var downFile = vm.FileList.Where(x => x.IsClean == false).ToList(); if (vm != null && ListTool.HasElements(downFile)) { for (int i = 0; i < downFile.Count(); i++) { VersionFile file = downFile[i]; string serverFile = DirTool.Combine(vm.ServerPath, file.ServerFile); string tempFile = DirTool.Combine(R.Paths.Temp, DownTemp, file.ServerFile); //下载到目标位置(带文件名) string localFile = DirTool.IsDriver(file.LocalFile) ? file.LocalFile : DirTool.Combine(R.Paths.ProjectRoot, file.LocalFile); //旧文件位置 if (fcode.GetMD5(localFile) != file.FileMD5) { UIUpdateDetail("正在下载:" + Path.GetFileName(file.ServerFile)); R.Log.v(string.Format("{0} 文件有更新,正在下载文件", Path.GetFileName(file.ServerFile))); FtpTool ftp = new FtpTool(R.Settings.FTP.Address, R.Settings.FTP.Account, R.Settings.FTP.Password); if (!ftp.Download(serverFile, tempFile)) { if (!ftp.Download(serverFile, tempFile)) { if (!ftp.Download(serverFile, tempFile)) { R.Log.w(string.Format("{0} 文件下载失败", Path.GetFileName(file.ServerFile))); return(false); } } } } else { UIUpdateDetail("文件已存在:" + Path.GetFileName(file.ServerFile)); R.Log.v(string.Format("{0} 文件不需要更新,已跳过该文件", Path.GetFileName(file.ServerFile))); } UIProgress(i + 1, downFile.Count()); } return(true); } return(false); }