/// <summary> /// 收集不同的文件 /// </summary> void CollectDifferentFiles() { string packRootDirectory = Path.GetFullPath(string.Format("{0}_to_{1}", tbOldVersionName.Text.Trim(), tbNewVersionName.Text)); string tempLogRootDirectory = packRootDirectory + "_Log"; string tempRisePakRootDirectory = packRootDirectory + "_RisePak"; mLogFilePath = Path.Combine(tempLogRootDirectory, "log.log"); CMDTool.DeleteDirectory(packRootDirectory); CMDTool.DeleteDirectory(tempRisePakRootDirectory); CMDTool.DeleteDirectory(tempLogRootDirectory); Directory.CreateDirectory(tempLogRootDirectory); AppendLog(lbOldVersionName.Text + tbOldVersionDirectory.Text); AppendLog(lbNewVersionName.Text + tbNewVersionDirectory.Text); AppendLog("更新包目录:{0}", packRootDirectory); AppendLog("开始收集差异文件"); List <WaitChunkPak> waitPaks = new List <WaitChunkPak>(); List <WaitCopyFile> copyFiles = new List <WaitCopyFile>(); List <WaitChunkFile> waitChunkFiles = new List <WaitChunkFile>(); CompareFile(tbOldVersionDirectory.Text, tbNewVersionDirectory.Text, packRootDirectory, waitPaks, copyFiles); AppendLog("完成收集差异文件"); float p = 0; int c = 0; string bat = string.Empty; string batFile = string.Empty; #region 制差异文件 if (copyFiles != null && copyFiles.Count > 0) { AppendLog("开始复制差异文件=>文件数:{0}", copyFiles.Count); p = 0; c = copyFiles.Count; for (int i = 0; i < copyFiles.Count; i++) { if (!Directory.Exists(copyFiles[i].directory)) { Directory.CreateDirectory(copyFiles[i].directory); } File.Copy(copyFiles[i].source, copyFiles[i].target); p = i / c; AppendLog(false, p, "复制文件【{0}】到【{1}】", copyFiles[i].source, copyFiles[i].target); } AppendLog(1, "完成复制差异文件"); } #endregion #region 比对Pak文件 if (waitPaks != null && waitPaks.Count > 0) { AppendLog(0, "开始比对Pak文件"); WaitChunkPak pak; p = 0; c = waitPaks.Count; string tn = string.Empty; for (int i = 0; i < waitPaks.Count; i++) { pak = waitPaks[i]; p = i / c; AppendLog(p, "比对包=>{0}", pak.newPak); tn = Path.GetFileName(pak.newPak); string tempRCP = Path.Combine(tempRisePakRootDirectory, tn + "_RiseCompressPak"); string tempOldPak = Path.Combine(tempRisePakRootDirectory, tn + "_TempOldPak"); string tempNewPak = Path.Combine(tempRisePakRootDirectory, tn + "_TempNewPak"); string tempChunkFile = Path.Combine(tempRCP, "chunk.txt"); CMDTool.DeleteDirectory(tempRCP); CMDTool.DeleteDirectory(tempOldPak); CMDTool.DeleteDirectory(tempNewPak); #region 解压Pak包 AppendLog(p, string.Format("解压旧Pak包=>{0}", pak.oldPak)); bat = Resx.ResPakBat.Pak_Extract .Replace("$platform$", platform.ToString()) .Replace("$engineDir$", lbOldEngineDir.Text) .Replace("$projectDir$", tbOldProjectDir.Text) .Replace("$unrealPakExe$", tbOldUnrealPakExe.Text) .Replace("$extractPak$", pak.oldPak) .Replace("$extractPath$", tempOldPak); AppendLog(p, string.Format("执行Bat=>{0}", bat)); batFile = Path.Combine(tempLogRootDirectory, Path.GetFileName(pak.oldPak) + "_Old.log"); File.WriteAllText(batFile, bat); CMDTool.ExecuteCmd(bat); AppendLog(p, string.Format("解压新Pak包=>{0}", pak.newPak)); bat = Resx.ResPakBat.Pak_Extract .Replace("$platform$", platform.ToString()) .Replace("$engineDir$", lbNewEngineDir.Text) .Replace("$projectDir$", tbNewProjectDir.Text) .Replace("$unrealPakExe$", tbNewUnrealPakExe.Text) .Replace("$extractPak$", pak.newPak) .Replace("$extractPath$", tempNewPak); AppendLog(p, string.Format("执行Bat=>{0}", bat)); batFile = Path.Combine(tempLogRootDirectory, Path.GetFileName(pak.newPak) + "_New.log"); File.WriteAllText(batFile, bat); CMDTool.ExecuteCmd(bat); #endregion #region 比对Pak包 List <WaitChunkPak> tempWaitPaks = new List <WaitChunkPak>(); List <WaitCopyFile> tempCopyFiles = new List <WaitCopyFile>(); CompareFile(tempOldPak, tempNewPak, tempRCP, tempWaitPaks, tempCopyFiles); float pp = 0; float tt = 0; string pakLog = Path.Combine(tempLogRootDirectory, Path.GetFileName(pak.newPak) + ".log"); string tempTxt = string.Empty; string tempExt = string.Empty; float ct = 0.1f; //比对要复制的文件 if (tempCopyFiles != null && tempCopyFiles.Count > 0) { AppendLog("生成Pak.log文件"); tt = tempCopyFiles.Count; for (int k = 0; k < tempCopyFiles.Count; k++) { pp = k / tt; tempTxt = string.Format("\"{0}\" \"../../../{1}\" -compress", tempCopyFiles[k].target, tempCopyFiles[k].relative); AppendLog(pp, tempTxt); File.AppendAllText(pakLog, tempTxt); File.AppendAllText(pakLog, Environment.NewLine); if (!Directory.Exists(tempCopyFiles[k].directory)) { Directory.CreateDirectory(tempCopyFiles[k].directory); } File.Copy(tempCopyFiles[k].source, tempCopyFiles[k].target); //waitChunkFiles tempExt = Path.GetExtension(tempCopyFiles[k].relative).ToLower(); if (tempExt == ".exe" || tempExt == ".bin" || pp >= ct) { waitChunkFiles.Add(new WaitChunkFile() { path = tempCopyFiles[k].relative, md5 = MD5Tool.GetFileMd5Chunk(tempCopyFiles[k].target) }); ct += 0.1f; } } } //加入chunk校验文件 tempTxt = string.Format("\"{0}\" \"../../../{1}\" -compress", tempChunkFile, Path.GetFileName(tempChunkFile)); File.AppendAllText(pakLog, tempTxt); File.AppendAllText(pakLog, Environment.NewLine); foreach (WaitChunkFile f in waitChunkFiles) { File.AppendAllText(tempChunkFile, string.Format("{0}={1}", f.path, f.md5)); File.AppendAllText(tempChunkFile, Environment.NewLine); } #endregion #region 生成pak包 TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); string pakFilePath = Path.Combine(pak.pakDirectory, Convert.ToInt64(ts.TotalSeconds).ToString() + "_p.pak"); AppendLog("生成Pak包=>{0}", pakFilePath); batFile = Path.Combine(tempLogRootDirectory, Path.GetFileName(pakFilePath) + "_Create.log"); bat = Resx.ResPakBat.Pak_Create .Replace("$platform$", platform.ToString()) .Replace("$engineDir$", lbNewEngineDir.Text) .Replace("$projectDir$", tbNewProjectDir.Text) .Replace("$unrealPakExe$", tbNewUnrealPakExe.Text) .Replace("$createPakFile$", pakFilePath) .Replace("$createFileName$", pakLog); File.WriteAllText(batFile, bat); AppendLog(bat); CMDTool.ExecuteCmd(bat); #endregion } AppendLog("完成比对Pak文件"); } #endregion #region 压缩差异包 string zipPath = packRootDirectory + ".zip"; AppendLog("压缩差异包=>{0}", zipPath); FastZip zip = new FastZip(); zip.CreateZip(zipPath, packRootDirectory, true, null); #endregion AppendLog(1, "【生成更新包完成】"); AppendLog(1, "【更新包文件】=>【{0}】", zipPath); }