From 4e5dc02c9f81bd59233f91ff0a7da41f916300b0 Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 12 Aug 2021 14:25:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E7=94=9F?= =?UTF-8?q?=E6=88=90c++=E4=BB=A3=E7=A0=81=E4=BD=BF=E7=94=A8utf-bom?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E4=BB=A5=E9=81=BF=E5=85=8Dvs?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E6=97=B6=E4=BA=A7=E7=94=9F"Warnning=20C4819"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataSources/Excel/ExcelDataSource.cs | 2 +- src/Luban.Job.Cfg/Source/JobController.cs | 10 +++++----- .../Source/Utils/CacheFileUtil.cs | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) 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;