private static List <VersionItem> BuildLocalDownloadfiles(VersionItem[] remoteDownloadfiles, string baseUrl) { List <VersionItem> localDownloadfiles = new List <VersionItem>(); ProgressActor progress = new ProgressActor(); progress.Show(); try { // 创建下载目录 string localPatchPath = BuildPatchPath(); // 下载文件 VersionItem localDownloadfile = null; foreach (VersionItem remoteDownloadfile in remoteDownloadfiles) { localDownloadfile = DownloadPatch(remoteDownloadfile, baseUrl, localPatchPath, progress); if (localDownloadfile != null) { localDownloadfiles.Add(localDownloadfile); } } return(localDownloadfiles); } finally { progress.Hide(); } }
static void Main(string[] args) { if (args == null || args.Length < 3) { return; } // 第一个参数是PDAClient.exe进程ID Process pdaclientProcess = GetProcess(int.Parse(args[0])); // 第二个是版本号信息 string version = args[1]; // 第三个才是补丁信息 List <PatchInfo> patchInfos = ParsePatchInfos(args[2]); if (patchInfos == null || patchInfos.Count == 0) { return; } // 杀掉PDAClient.exe进程 if (pdaclientProcess != null) { pdaclientProcess.Kill(); } ProgressActor progress = new ProgressActor(); progress.Show(); try { progress.Init(patchInfos.Count + 2); // 拷贝文件更新 int index = 0; foreach (PatchInfo patchInfo in patchInfos) { if (string.IsNullOrEmpty(patchInfo.DownloadPath)) { continue; } progress.ProgressHint = "正在安装:" + Path.GetFileName(patchInfo.DownloadPath); progress.SetProgress(index++); FileUpdate.DoUpdate(patchInfo, PathHelper.GetTempPath(), PathHelper.GetCurrentPath()); } progress.ProgressHint = "正在更新版本信息"; progress.SetProgress(index++); // 更新版本信息 VersionUpdate.DoUpdate(version); progress.ProgressHint = "正在启动PDAClient进程"; progress.SetProgress(index++); // 重新启动PDAClient.exe Process.Start(PathHelper.GetPDAClientPath(), ""); } finally { progress.Hide(); } }
public void Reset(Condition condition) { _failed = false; _efficiencyCalculator.UseConditionMultylier(_lookupService.GetConditionMultiplier(condition)); _durability = a => { }; _progress = (a, b, c) => { }; _quality = (a, b, c) => { }; _craftPoints = a => { }; _chance = a => { }; _conditionChance = (a, b) => { }; _levelActor = (a, c, d) => { }; _reclaimChanceActor = (a) => { }; }
public void ForProgress(ProgressActor action) { _progress += action; }
/// <summary> /// 下载补丁文件 /// </summary> /// <param name="versionItem"></param> /// <param name="baseUrl"></param> /// <param name="path"></param> /// <param name="progress"></param> /// <returns></returns> private static VersionItem DownloadPatch(VersionItem versionItem, string baseUrl, string path, ProgressActor progress) { if (versionItem == null) { return(null); } if (string.IsNullOrEmpty(versionItem.DownloadFile)) { return(null); } string url = versionItem.DownloadFile; if (!url.ToLower().Trim().StartsWith("http://")) { url = Path.Combine(baseUrl, url); } // 获取文件名 String fileName = url.Substring(url.LastIndexOf("/") + 1); // 获取文件下载路径 String refer = url.Substring(0, url.LastIndexOf("/") + 1); VersionItem localDownloadfile = new VersionItem(); localDownloadfile.InstallStyle = versionItem.InstallStyle; localDownloadfile.DownloadFile = Path.Combine(path, fileName); localDownloadfile.Version = versionItem.Version; // 开始下载 progress.Init(100); progress.ProgressHint = "正在下载:" + url; HttpWebRequest req = HttpWebRequest.Create(url) as HttpWebRequest; req.AllowAutoRedirect = true; req.Referer = refer; req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"; HttpWebResponse res = req.GetResponse() as HttpWebResponse; Stream stream = res.GetResponseStream(); byte[] buffer = new byte[32 * 1024]; FileStream fs = File.Create(localDownloadfile.DownloadFile); int index = 0; try { int bytesProcessed = 0, bytesRead = 0; do { bytesRead = stream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, bytesRead); bytesProcessed += bytesRead; progress.SetProgress(index++); }while (bytesRead > 0); fs.Flush(); progress.SetProgress(100); } finally { fs.Close(); stream.Close(); res.Close(); } return(localDownloadfile); }