【优化】生成c++代码使用utf-bom格式,以避免vs编译时产生"Warnning C4819"
parent
f68f82da4c
commit
4e5dc02c9f
|
|
@ -26,7 +26,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
||||||
fs.Seek(0, SeekOrigin.Begin);
|
fs.Seek(0, SeekOrigin.Begin);
|
||||||
if (cdet.Charset != null)
|
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;
|
return System.Text.Encoding.GetEncoding(cdet.Charset) ?? System.Text.Encoding.Default;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -680,7 +680,7 @@ namespace {ctx.TopModule}
|
||||||
|
|
||||||
var content = FileHeaderUtil.ConcatAutoGenerationHeader(string.Join('\n', headerFileContent), ELanguage.CPP);
|
var content = FileHeaderUtil.ConcatAutoGenerationHeader(string.Join('\n', headerFileContent), ELanguage.CPP);
|
||||||
var file = "gen_types.h";
|
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 });
|
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))),
|
render.RenderStub(ctx.TopModule, beanTypes.GetRange(startIndex, Math.Min(TYPE_PER_STUB_FILE, beanTypes.Count - startIndex))),
|
||||||
ELanguage.CPP);
|
ELanguage.CPP);
|
||||||
var file = $"gen_stub_{index}.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 });
|
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 content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), ELanguage.CPP);
|
||||||
var file = "editor_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(c.FullName);
|
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 });
|
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))),
|
render.RenderStub(renderTypes.GetRange(startIndex, Math.Min(TYPE_PER_STUB_FILE, renderTypes.Count - startIndex))),
|
||||||
ELanguage.CPP);
|
ELanguage.CPP);
|
||||||
var file = $"stub_{index}.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 });
|
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 content = FileHeaderUtil.ConcatAutoGenerationHeader(render.RenderAny(c), ELanguage.CPP);
|
||||||
var file = "bp_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(c.FullName);
|
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 });
|
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Luban.Common.Protos;
|
using Luban.Common.Protos;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
using Luban.Server.Common;
|
using Luban.Server.Common;
|
||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Luban.Job.Common.Utils
|
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");
|
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);
|
var md5 = FileUtil.CalcMD5(bytes);
|
||||||
CacheManager.Ins.AddCache(fileName, md5, bytes);
|
CacheManager.Ins.AddCache(fileName, md5, bytes);
|
||||||
return md5;
|
return md5;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue