diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs index f53656e..1e70c6f 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs @@ -26,7 +26,7 @@ namespace Luban.Job.Cfg.DataSources.Excel fs.Seek(0, SeekOrigin.Begin); if (cdet.Charset != null) { - Console.WriteLine("Charset: {0}, confidence: {1}", cdet.Charset, cdet.Confidence); + s_logger.Debug("Charset: {}, confidence: {}", cdet.Charset, cdet.Confidence); return System.Text.Encoding.GetEncoding(cdet.Charset) ?? System.Text.Encoding.Default; } else diff --git a/src/Luban.Job.Cfg/Source/JobController.cs b/src/Luban.Job.Cfg/Source/JobController.cs index 36c7adc..cf0964e 100644 --- a/src/Luban.Job.Cfg/Source/JobController.cs +++ b/src/Luban.Job.Cfg/Source/JobController.cs @@ -680,7 +680,7 @@ namespace {ctx.TopModule} var content = FileHeaderUtil.ConcatAutoGenerationHeader(string.Join('\n', headerFileContent), ELanguage.CPP); var file = "gen_types.h"; - var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); + var md5 = CacheFileUtil.GenMd5AndAddCache(file, content, true); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); })); @@ -698,7 +698,7 @@ namespace {ctx.TopModule} render.RenderStub(ctx.TopModule, beanTypes.GetRange(startIndex, Math.Min(TYPE_PER_STUB_FILE, beanTypes.Count - startIndex))), ELanguage.CPP); var file = $"gen_stub_{index}.cpp"; - var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); + var md5 = CacheFileUtil.GenMd5AndAddCache(file, content, true); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); })); } @@ -716,7 +716,7 @@ namespace {ctx.TopModule} { var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), ELanguage.CPP); var file = "editor_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(c.FullName); - var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); + var md5 = CacheFileUtil.GenMd5AndAddCache(file, content, true); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); })); } @@ -733,7 +733,7 @@ namespace {ctx.TopModule} render.RenderStub(renderTypes.GetRange(startIndex, Math.Min(TYPE_PER_STUB_FILE, renderTypes.Count - startIndex))), ELanguage.CPP); var file = $"stub_{index}.cpp"; - var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); + var md5 = CacheFileUtil.GenMd5AndAddCache(file, content, true); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); })); } @@ -768,7 +768,7 @@ namespace {ctx.TopModule} { var content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), ELanguage.CPP); var file = "bp_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(c.FullName); - var md5 = CacheFileUtil.GenMd5AndAddCache(file, content); + var md5 = CacheFileUtil.GenMd5AndAddCache(file, content, true); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); })); } diff --git a/src/Luban.Job.Common/Source/Utils/CacheFileUtil.cs b/src/Luban.Job.Common/Source/Utils/CacheFileUtil.cs index b602ffc..afaf6fa 100644 --- a/src/Luban.Job.Common/Source/Utils/CacheFileUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/CacheFileUtil.cs @@ -1,6 +1,7 @@ using Luban.Common.Protos; using Luban.Common.Utils; using Luban.Server.Common; +using System; using System.Threading.Tasks; namespace Luban.Job.Common.Utils @@ -35,10 +36,22 @@ namespace Luban.Job.Common.Utils } } - public static string GenMd5AndAddCache(string fileName, string content) + public static string GenMd5AndAddCache(string fileName, string content, bool withUtf8Bom = false) { content = content.Replace("\r\n", "\n"); - var bytes = System.Text.Encoding.UTF8.GetBytes(content); + byte[] bytes; + if (!withUtf8Bom) + { + bytes = System.Text.Encoding.UTF8.GetBytes(content); + } + else + { + bytes = new byte[System.Text.Encoding.UTF8.GetByteCount(content) + 3 /* bom header */]; + bytes[0] = 0xef; + bytes[1] = 0xbb; + bytes[2] = 0xbf; + System.Text.Encoding.UTF8.GetBytes(content, bytes.AsSpan(3)); + } var md5 = FileUtil.CalcMD5(bytes); CacheManager.Ins.AddCache(fileName, md5, bytes); return md5;