void UpdateResTxt() { var currentDirectory = System.Environment.CurrentDirectory; //当前程序的目录 var parentDirPath = string.Empty; var parentDir = new DirectoryInfo(currentDirectory).Parent; if (parentDir != null) { parentDirPath = Path.Combine(parentDir.FullName, "youlong_online\\"); //上一级目录+文件夹名 } else { Console.WriteLine("ERROR:请把此程序放在 data/../xx/getFile.exe "); } if (isFixedPath) { parentDirPath = @"e:\ylgame_trunk\youlong_product_vn\youlong_online\"; } var targetPath = parentDirPath + dataFolderName; Console.WriteLine("获取文件的路径:{0}", targetPath); var dllFullPath = parentDirPath + dllPath; Console.WriteLine("Assembly-CSharp.dll的路径:{0}", targetPath); if (File.Exists(resFileName)) { FileInfo resFileInfo = new FileInfo(resFileName); //Console.Write("创建时间:" + resFileInfo.CreationTime + "写入文件的时间" + resFileInfo.LastWriteTime + "访问的时间" + resFileInfo.LastAccessTime); resLastFileName = string.Concat(resFileInfo.LastWriteTime.ToString("yyyyMMdd_hhmmss_ffff"), ".txt"); resFileInfo.MoveTo(resLastFileName); File.Delete(resFileName); Console.WriteLine("重命名旧的文件:{0}->{1}", resFileName, resLastFileName); } Console.WriteLine(); Console.WriteLine("正在生成文件列表文件:{0},请稍候......", resFileName); Int64 fileLine = 0; string overflowMsg = string.Empty; using (StreamWriter streamWriter = File.CreateText(resFileName)) { //特殊处理dll文件 var writeDllPath = dllFullPath.Replace(parentDirPath, ""); //writeDllPath = writeDllPath.Replace(dllDir, ""); writeDllPath = writeDllPath.Insert(0, dataFolderName); //在路径前添加 writeDllPath = writeDllPath.Replace(@"\", "/"); var writeDllStr = string.Concat(writeDllPath, "&", HashHelper.GetSHA1(dllFullPath)); if (!string.IsNullOrEmpty(writeDllStr)) { streamWriter.WriteLine(writeDllStr); Console.WriteLine(writeDllStr); if (fileLine < Int64.MaxValue) { fileLine += 1; } else { overflowMsg = "文件行数太多啦,未统计。"; } } var fileInfos = FileHelper.GetAllFiles(targetPath); var fileMax = fileInfos.Count; for (int fileIdx = 0; fileIdx < fileMax; fileIdx++) { var fileInfo = fileInfos[fileIdx]; if (fileInfo.Extension != ".meta") { var filePath = fileInfo.FullName.Replace(parentDirPath, ""); filePath = filePath.Replace(@"\", "/"); var writeStr = string.Concat(filePath, "&", HashHelper.GetSHA1(fileInfo.FullName)); if (!string.IsNullOrEmpty(writeStr)) { streamWriter.WriteLine(writeStr); Console.WriteLine(writeStr); if (fileLine < Int64.MaxValue) { fileLine += 1; } else { overflowMsg = "文件行数太多啦,未统计。"; } } } } } Console.WriteLine("{0}生成成功,共{1}行", resFileName, fileLine); Console.WriteLine(); if (!string.IsNullOrEmpty(overflowMsg)) { Console.WriteLine(overflowMsg); } }
void UpdateResList() { var targetPath = Path.Combine(System.Environment.CurrentDirectory, "data\\");//当前程序的目录/data if (isDebug) { targetPath = @"e:\ylgame_trunk\youlong_product_vn\youlong_online\data\"; } if (string.IsNullOrEmpty(targetPath)) { Console.WriteLine("ERROR:请把此程序放在 product/online/xx.exe "); } Console.WriteLine("获取文件的路径:{0}", targetPath); if (File.Exists(resFileName)) { FileInfo resFileInfo = new FileInfo(resFileName); //NOTE 如果存在老的res_last,就用res替换掉res_last if (File.Exists(resFileNameLast)) { File.Delete(resFileNameLast); } resFileInfo.MoveTo(resFileNameLast); File.Delete(resFileName); } Console.WriteLine(); Console.WriteLine("正在生成文件列表文件:{0},请稍候......", resFileName); Int64 fileLine = 0, adjustLine = 0; string overflowMsg = string.Empty; using (StreamWriter streamWriter = File.CreateText(resFileName)) { var fileInfos = FileHelper.GetAllFiles(targetPath); var fileMax = fileInfos.Count; for (int fileIdx = 0; fileIdx < fileMax; fileIdx++) { //if (fileLine >= 4) break;//测试情境 var fileInfo = fileInfos[fileIdx]; if (fileInfo == null) { continue; } if (fileInfo.Extension != ".meta") { if (fileInfo.Name.Contains("setting_client.ab")) { continue; } /* * NOTE 获取data目录下的所有文件,去掉path,只保留文件名 */ //var filePath = fileInfo.FullName.Replace(targetPath, ""); var filePath = fileInfo.Name; //bug 有的机器上,替换之后前面还会留着一个\,强制把它干掉 if (filePath.StartsWith("\\")) { filePath = filePath.Substring(1); } if (filePath.Contains("\\")) { filePath = filePath.Replace("\\", ""); } var lastHash = ""; long lastVersion = 0; GetLastResInfo(filePath, ref lastHash, ref lastVersion); var curHash = HashHelper.GetSHA1(fileInfo.FullName); var curVersion = lastVersion; if (curHash != lastHash) { curVersion = lastVersion + 1; if (adjustLine < Int64.MaxValue) { adjustLine += 1; } } var writeStr = string.Concat(filePath, "&", curHash, "&", curVersion, "|"); if (!string.IsNullOrEmpty(writeStr)) { streamWriter.WriteLine(writeStr); Console.WriteLine(writeStr); if (fileLine < Int64.MaxValue) { fileLine += 1; } else { overflowMsg = "文件行数太多啦,未统计。"; } } } } } Console.WriteLine(); Console.WriteLine("{0}生成成功,共{1}行,其中{2}行受到影响", resFileName, fileLine, adjustLine); if (!string.IsNullOrEmpty(overflowMsg)) { Console.WriteLine(overflowMsg); } }