/// <summary> /// 更新 /// </summary> /// <param name="info">新版本信息</param> /// <param name="tempPath">文件下载位置</param> /// <param name="dictionary">文件相对位置字典</param> /// <param name="downProgress">下载进度回调</param> /// <param name="downSender">下载进度事件数据</param> /// <param name="releaseProgress">释放进度回调</param> /// <param name="releaseSender">释放进度事件数据</param> /// <returns> /// -10000;//没有新版本 /// -20000;//文件下载失败 /// -30000;//文件释放失败 /// </returns> public int Update(AppUpdateInfo info, string tempPath, Dictionary <string, string> dictionary, ProgressDelegate.ProgressHandler downProgress = null, object downSender = null, ProgressDelegate.ProgressHandler releaseProgress = null, object releaseSender = null) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //请求最新版本信息 if (info != null) { string file = DirTool.Combine(tempPath, GuidTool.Short() + "-" + info.Version); //准备更新(下载) string downfile = Download(file, info, downProgress, downSender); if (!string.IsNullOrWhiteSpace(downfile) && File.Exists(downfile)) { //格式化释放文件目录(相对路径转换为绝对路径) string releasepath = AppDirTool.Get(info.ReleasePath, dictionary); //释放文件,释放完成后删除临时文件 int unpackCode = FilePackageTool.Unpack(downfile, releasepath, releaseProgress, releaseSender); File.Delete(file); if (unpackCode > 0) { stopwatch.Stop(); return((int)stopwatch.Elapsed.TotalSeconds); } else { return(-30000 + unpackCode);//文件释放失败 } } else { return(-20000);//文件下载失败 } } else { return(-10000);//没有新版本 } }
private void BTUnpack_Click(object sender, EventArgs e) { FilePackageTool.Unpack(TBFrom.Text, TBTo.Text, UIProgress); }