private bool DownLoadZip(VersionInfo info) { AutoUpdateEvent(this, new AutoUpdateEventArgs("准备更新" + "...", (long)(info.TotalFileSize * 1.1), 1, ProgressBarStateEnum.Continue)); tempFold = LocalFilesOperation.CreateNewVersionFold(Path.GetTempPath(), DateTime.Now); string tempFilename = Path.Combine(tempFold, "update.zip"); HttpHelper.DonwloadSizeAction += DownloasSizeCallback; HttpHelper.Download(info.HttpGetInfo.updateUrl, tempFilename); //AutoUpdateEvent(this, new AutoUpdateEventArgs("解压缩中...", (long)(info.TotalFileSize * 1.25), (long)(info.TotalFileSize * 1.25), ProgressBarStateEnum.Continue)); if (!ZipFileOperation.UnZipFile(tempFilename, tempFold)) { AutoUpdateEvent(this, new AutoUpdateEventArgs(string.Format("文件下载异常,更新失败"), 0, 0, ProgressBarStateEnum.UnEnable)); return(false); } AutoUpdateEvent(this, new AutoUpdateEventArgs("文件下载完成", 0, 0, ProgressBarStateEnum.UnEnable)); return(true); }
/// <summary> /// 将要更新的文件保存在临时文件夹中 /// </summary> /// <param name="tempFolder"></param> /// <param name="fileInfo"></param> public bool SaveUpdateFile(string tempFolder, VersionFileInfo fileInfo) { string tempFileName = LocalFilesOperation.PathCombine(tempFolder, fileInfo.FileName); HttpHelper.Download(fileInfo.DownloadUrl, tempFileName); //压缩包 if (fileInfo.FileName.EndsWith(".zip")) { string err; if (!ZipFileOperation.UnZipFile(tempFileName, tempFolder, out err)) { return(false); } //string versionFilePath = LocalFilesOperation.PathCombine(tempFolder, "VersionInfo.txt"); //if (!File.Exists(versionFilePath)) // return false; //using (FileStream fs = new FileStream(versionFilePath, FileMode.Open, FileAccess.Read)) //{ // using (StreamReader sr = new StreamReader(fs)) // { // VersionInfos.TotalFileSize = long.Parse(sr.ReadLine()); // VersionInfos.UpdateFileList.Clear(); // List<string> infoList = new List<string>(); // while (!sr.EndOfStream) // { // infoList.Add(sr.ReadLine()); // } // foreach (string item in infoList) // { // string[] paramList = item.Split(new char[] { ',' }); // VersionInfos.UpdateFileList.Add(new VersionFileInfo() { FileName = paramList[0], RelativePath = paramList[1], FileOperateType = (OperateType)Enum.Parse(typeof(OperateType), paramList[2]), FileSize = long.Parse(paramList[3]) }); // } // } //} } else if (fileInfo.FileName.EndsWith(".exe")) { fileInfo.FileOperateType = OperateType.Run; } return(true); }
public bool SaveUpdateFile(string tempFolder, VersionFileInfo fileInfo) { string tempFileName = LocalFilesOperation.PathCombine(tempFolder, fileInfo.FileName); File.Copy(@"E:\" + fileInfo.FileName, tempFileName, true); string err; if (!ZipFileOperation.UnZipFile(tempFileName, tempFolder, out err)) { return(false); } string versionFilePath = LocalFilesOperation.PathCombine(tempFolder, "VersionInfo.txt"); if (!File.Exists(versionFilePath)) { return(false); } using (FileStream fs = new FileStream(versionFilePath, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader(fs)) { VersionInfos.TotalFileSize = long.Parse(sr.ReadLine()); VersionInfos.UpdateFileList.Clear(); List <string> infoList = new List <string>(); while (!sr.EndOfStream) { infoList.Add(sr.ReadLine()); } foreach (string item in infoList) { string[] paramList = item.Split(new char[] { ',' }); VersionInfos.UpdateFileList.Add(new VersionFileInfo() { FileName = paramList[0], RelativePath = paramList[1], FileOperateType = (OperateType)Enum.Parse(typeof(OperateType), paramList[2]), FileSize = long.Parse(paramList[3]) }); } } } return(false); }