From 82885918275e50cf65dfef67ad537a92545e3be1 Mon Sep 17 00:00:00 2001 From: walon Date: Mon, 11 Oct 2021 23:05:16 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=87=8D=E6=9E=84=E3=80=91=E4=B8=BA?= =?UTF-8?q?=E4=B8=8ELubanAssistant=E5=85=B1=E4=BA=AB=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=80=8C=E7=95=A5=E5=BE=AE=E8=B0=83=E6=95=B4=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B.net5=E4=B8=8E.net=204.7=20=E4=B9=8B=E9=97=B4=E4=B8=8D?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Common/Source/Utils/FileUtil.cs | 56 +++++++++++++++++++ .../Source/Cache/FileRecordCacheManager.cs | 2 +- .../Source/DataCreators/ExcelDataCreator.cs | 1 + .../DataCreators/ExcelNamedRowDataCreator.cs | 6 +- .../Source/DataCreators/JsonDataCreator.cs | 1 + .../Source/DataCreators/LuaDataCreator.cs | 1 + .../Source/DataCreators/XmlDataCreator.cs | 1 + .../DataSources/Excel/ExcelDataSource.cs | 14 +---- .../Source/DataSources/Excel/Sheet.cs | 1 + src/Luban.Job.Cfg/Source/Datas/Record.cs | 3 +- src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs | 17 +++++- .../Source/Defs/CfgDefTypeBase.cs | 19 ------- src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs | 9 +-- src/Luban.Job.Cfg/Source/Defs/DefBean.cs | 2 + src/Luban.Job.Cfg/Source/Defs/DefTable.cs | 1 + .../Source/Generate/CodeRenderBase.cs | 2 +- .../TypeVisitors/DeepCompareTypeDefine.cs | 2 + .../Source/TypeVisitors/RefTypeVisitor.cs | 1 + .../Source/Utils/DataLoaderUtil.cs | 14 ++--- src/Luban.Job.Cfg/Source/Utils/DataUtil.cs | 2 +- .../Source/Validators/RefValidator.cs | 16 ++++++ .../Source/Defs/CommonDefLoader.cs | 4 +- .../Source/Defs/DefAssemblyBase.cs | 14 ++++- src/Luban.Job.Common/Source/Defs/DefEnum.cs | 9 +-- .../Source/Defs/DefTypeBase.cs | 2 +- src/Luban.Job.Common/Source/Utils/DefUtil.cs | 8 +++ .../Source/Utils/RenderFileUtil.cs | 28 ---------- .../Source/CacheManager.cs | 2 +- 28 files changed, 148 insertions(+), 90 deletions(-) diff --git a/src/Luban.Common/Source/Utils/FileUtil.cs b/src/Luban.Common/Source/Utils/FileUtil.cs index e9cc611..3e26a39 100644 --- a/src/Luban.Common/Source/Utils/FileUtil.cs +++ b/src/Luban.Common/Source/Utils/FileUtil.cs @@ -23,13 +23,21 @@ namespace Luban.Common.Utils public static string GetFileName(string path) { int index = path.Replace('\\', '/').LastIndexOf('/'); +#if !LUBAN_ASSISTANT return index >= 0 ? path[(index + 1)..] : path; +#else + return index >= 0 ? path.Substring(index + 1, path.Length - index - 1) : path; +#endif } public static string GetParent(string path) { int index = path.Replace('\\', '/').LastIndexOf('/'); +#if !LUBAN_ASSISTANT return index >= 0 ? path[..index] : "."; +#else + return index >= 0 ? path.Substring(0, index) : "."; +#endif } public static string GetFileNameWithoutExt(string file) @@ -62,7 +70,11 @@ namespace Luban.Common.Utils } var f = new FileInfo(file); string fname = f.Name; +#if !LUBAN_ASSISTANT return !fname.StartsWith('.') && !fname.StartsWith('_') && !fname.StartsWith('~'); +#else + return !fname.StartsWith(".") && !fname.StartsWith("_") && !fname.StartsWith("~"); +#endif } [ThreadStatic] @@ -100,6 +112,45 @@ namespace Luban.Common.Utils return Standardize(Path.Combine(parent, sub)); } + public static bool IsExcelFile(string fullName) + { + return fullName.EndsWith(".csv", StringComparison.Ordinal) + || fullName.EndsWith(".xls", StringComparison.Ordinal) + || fullName.EndsWith(".xlsx", StringComparison.Ordinal); + } + + public static (string, string) SplitFileAndSheetName(string url) + { + int sheetSepIndex = url.IndexOf('@'); + if (sheetSepIndex < 0) + { + return (url, null); + } + else + { + int lastPathSep = url.LastIndexOf('/', sheetSepIndex); +#if !LUBAN_ASSISTANT + if (lastPathSep >= 0) + { + return (url[0..(lastPathSep + 1)] + url[(sheetSepIndex + 1)..], url[(lastPathSep + 1)..sheetSepIndex]); + } + else + { + return (url[(sheetSepIndex + 1)..], url[(lastPathSep + 1)..sheetSepIndex]); + } +#else + if (lastPathSep >= 0) + { + return (url.Substring(0, lastPathSep + 1) + url.Substring(sheetSepIndex + 1), url.Substring(lastPathSep + 1, sheetSepIndex - lastPathSep - 1)); + } + else + { + return (url.Substring(sheetSepIndex + 1), url.Substring(lastPathSep + 1, sheetSepIndex - lastPathSep - 1)); + } +#endif + } + } + public static async Task SaveFileAsync(string relateDir, string filePath, byte[] content) { // 调用此接口时,已保证 文件必然是改变的,不用再检查对比文件 @@ -131,7 +182,12 @@ namespace Luban.Common.Utils s_logger.Info("[new] {file}", outputPath); } + +#if !LUBAN_ASSISTANT await File.WriteAllBytesAsync(outputPath, content); +#else + await Task.Run(() => File.WriteAllBytes(outputPath, content)); +#endif } public static async Task ReadAllBytesAsync(string file) diff --git a/src/Luban.Job.Cfg/Source/Cache/FileRecordCacheManager.cs b/src/Luban.Job.Cfg/Source/Cache/FileRecordCacheManager.cs index 59c2ca3..c90b373 100644 --- a/src/Luban.Job.Cfg/Source/Cache/FileRecordCacheManager.cs +++ b/src/Luban.Job.Cfg/Source/Cache/FileRecordCacheManager.cs @@ -113,7 +113,7 @@ namespace Luban.Job.Cfg.Cache cacheList.Sort((a, b) => a.Value.LastAccessTime - b.Value.LastAccessTime); for (int i = 0; i < CACHE_FILE_HIGH_WATER_MARK - CACHE_FILE_LOW_WATER_MARK; i++) { - _caches.Remove(cacheList[i].Key, out _); + _caches.TryRemove(cacheList[i].Key, out _); } s_logger.Info("ShrinkCaches. after shrink, cache file num:{}", _caches.Count); } diff --git a/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs index 2916473..7868a46 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using Luban.Common.Utils; using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.DataSources.Excel; diff --git a/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs index ea4c8b1..c28ad0c 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs @@ -317,11 +317,11 @@ namespace Luban.Job.Cfg.DataCreators public DType Accept(TMap type, Sheet.NamedRow x, bool multirow, bool nullable) { var map = new Dictionary(); - foreach (var (key, keyTitle) in x.Titles) + foreach (var e in x.Titles) { - if (TryCreateColumnStream(x, keyTitle, out var stream)) + if (TryCreateColumnStream(x, e.Value, out var stream)) { - var keyData = type.KeyType.Apply(StringDataCreator.Ins, key); + var keyData = type.KeyType.Apply(StringDataCreator.Ins, e.Key); var valueData = type.ValueType.Apply(ExcelDataCreator.Ins, null, stream, DefAssembly.LocalAssebmly); map.Add(keyData, valueData); } diff --git a/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs index a65293a..c687a9f 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/JsonDataCreator.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using Luban.Common.Utils; using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.Defs; diff --git a/src/Luban.Job.Cfg/Source/DataCreators/LuaDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/LuaDataCreator.cs index 4edfeda..8c40f79 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/LuaDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/LuaDataCreator.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using Luban.Common.Utils; using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.Defs; diff --git a/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs index 9e45c6e..6db20e8 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/XmlDataCreator.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using Luban.Common.Utils; using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.Defs; diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs index 6d38dda..4c34a28 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelDataSource.cs @@ -18,19 +18,7 @@ namespace Luban.Job.Cfg.DataSources.Excel private System.Text.Encoding DetectCsvEncoding(Stream fs) { - Ude.CharsetDetector cdet = new Ude.CharsetDetector(); - cdet.Feed(fs); - cdet.DataEnd(); - fs.Seek(0, SeekOrigin.Begin); - if (cdet.Charset != null) - { - s_logger.Debug("Charset: {}, confidence: {}", cdet.Charset, cdet.Confidence); - return System.Text.Encoding.GetEncoding(cdet.Charset) ?? System.Text.Encoding.Default; - } - else - { - return System.Text.Encoding.Default; - } + return System.Text.Encoding.Default; } public override void Load(string rawUrl, string sheetName, Stream stream) diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs index c2567bd..907e82e 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using ExcelDataReader; using Luban.Job.Cfg.DataCreators; using Luban.Job.Cfg.Datas; diff --git a/src/Luban.Job.Cfg/Source/Datas/Record.cs b/src/Luban.Job.Cfg/Source/Datas/Record.cs index ef4b84f..1b8209f 100644 --- a/src/Luban.Job.Cfg/Source/Datas/Record.cs +++ b/src/Luban.Job.Cfg/Source/Datas/Record.cs @@ -1,5 +1,4 @@ -using Luban.Job.Cfg.Utils; -using System.Collections.Generic; +using System.Collections.Generic; namespace Luban.Job.Cfg.Datas { diff --git a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs index f35962d..59c12c3 100644 --- a/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs +++ b/src/Luban.Job.Cfg/Source/Defs/CfgDefLoader.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using Luban.Common.Utils; using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.DataSources.Excel; @@ -36,7 +37,7 @@ namespace Luban.Job.Cfg.Defs private readonly List _defaultGroups = new List(); - public CfgDefLoader(RemoteAgent agent) : base(agent) + public CfgDefLoader(IAgent agent) : base(agent) { RegisterRootDefineHandler("importexcel", AddImportExcel); RegisterRootDefineHandler("patch", AddPatch); @@ -139,14 +140,22 @@ namespace Luban.Job.Cfg.Defs { if (!string.IsNullOrWhiteSpace(attr)) { +#if !LUBAN_ASSISTANT foreach (var validatorStr in attr.Split('#', StringSplitOptions.RemoveEmptyEntries)) +#else + foreach (var validatorStr in attr.Split('#')) +#endif { var sepIndex = validatorStr.IndexOf(':'); - if (sepIndex < 0) + if (sepIndex <= 0) { throw new Exception($"定义文件:{defineFile} key:'{key}' attr:'{attr}' 不是合法的 validator 定义 (key1:value1#key2:value2 ...)"); } +#if !LUBAN_ASSISTANT result.Add(new Validator() { Type = validatorStr[..sepIndex], Rule = validatorStr[(sepIndex + 1)..] }); +#else + result.Add(new Validator() { Type = validatorStr.Substring(0, sepIndex), Rule = validatorStr.Substring(sepIndex + 1, validatorStr.Length - sepIndex - 1) }); +#endif } } } @@ -356,7 +365,11 @@ namespace Luban.Job.Cfg.Defs for (int i = 1; i < attrs.Length; i++) { +#if !LUBAN_ASSISTANT var pair = attrs[i].Split('=', 2); +#else + var pair = attrs[i].Split(new char[] { '=' }, 2); +#endif if (pair.Length != 2) { throw new Exception($"table:'{table.Name}' file:{file.OriginFile} title:'{f.Name}' attr:'{attrs[i]}' is invalid!"); diff --git a/src/Luban.Job.Cfg/Source/Defs/CfgDefTypeBase.cs b/src/Luban.Job.Cfg/Source/Defs/CfgDefTypeBase.cs index e555275..9b3144e 100644 --- a/src/Luban.Job.Cfg/Source/Defs/CfgDefTypeBase.cs +++ b/src/Luban.Job.Cfg/Source/Defs/CfgDefTypeBase.cs @@ -7,24 +7,5 @@ namespace Luban.Job.Cfg.Defs public abstract class CfgDefTypeBase : DefTypeBase { public DefAssembly Assembly => (DefAssembly)AssemblyBase; - - public virtual string UeBpName => "U" + Name; - - public virtual string UeBpFullName => TypeUtil.MakeCppJoinedFullName("U" + Namespace, Name); - - public string UeBpHeaderFileName => "bp_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(FullName); - - public string UeBpHeaderFileNameWithoutSuffix => "bp_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePathWithoutSuffix(FullName); - - public string EditorUeFullName => TypeUtil.MakeCppFullName(Namespace, Name); - - public string UeFname => "F" + Name; - - public string UeFfullName => TypeUtil.MakeCppFullName(Namespace, UeFname); - - public string UeHeaderFileName => RenderFileUtil.GetUeCppDefTypeHeaderFilePath(FullName); - - public string UeEditorHeaderFileName => "editor_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(FullName); - } } diff --git a/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs b/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs index 9e73521..6a09292 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefAssembly.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.l10n; using Luban.Job.Cfg.RawDefs; @@ -43,7 +44,7 @@ namespace Luban.Job.Cfg.Defs public TimeZoneInfo TimeZone { get; } - public DefAssembly(string patchName, TimeZoneInfo timezone, List excludeTags, RemoteAgent agent) + public DefAssembly(string patchName, TimeZoneInfo timezone, List excludeTags, IAgent agent) { this._patchName = patchName; this.TimeZone = timezone; @@ -153,11 +154,11 @@ namespace Luban.Job.Cfg.Defs throw new Exception($"service:'{targetService.Name}' ref:'{refType}' 重复引用"); } } - foreach ((var fullTypeName, var type) in this.Types) + foreach (var e in this.Types) { - if (!refTypes.ContainsKey(fullTypeName) && (type is DefEnum)) + if (!refTypes.ContainsKey(e.Key) && (e.Value is DefEnum)) { - refTypes.Add(fullTypeName, type); + refTypes.Add(e.Key, e.Value); } } diff --git a/src/Luban.Job.Cfg/Source/Defs/DefBean.cs b/src/Luban.Job.Cfg/Source/Defs/DefBean.cs index c631c65..0b11af2 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefBean.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefBean.cs @@ -31,6 +31,7 @@ namespace Luban.Job.Cfg.Defs return DeepCompareTypeDefine.Ins.Compare(this, b, new Dictionary(), new HashSet()); } +#if !LUBAN_ASSISTANT public string GoBinImport { get @@ -129,6 +130,7 @@ namespace Luban.Job.Cfg.Defs throw new NotImplementedException(); } } +#endif public DefBean(CfgBean b) : base(b) { diff --git a/src/Luban.Job.Cfg/Source/Defs/DefTable.cs b/src/Luban.Job.Cfg/Source/Defs/DefTable.cs index bcdfcf2..52c364b 100644 --- a/src/Luban.Job.Cfg/Source/Defs/DefTable.cs +++ b/src/Luban.Job.Cfg/Source/Defs/DefTable.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using Luban.Job.Cfg.RawDefs; using Luban.Job.Common.Types; using Luban.Job.Common.Utils; diff --git a/src/Luban.Job.Cfg/Source/Generate/CodeRenderBase.cs b/src/Luban.Job.Cfg/Source/Generate/CodeRenderBase.cs index fe44a44..a877ed5 100644 --- a/src/Luban.Job.Cfg/Source/Generate/CodeRenderBase.cs +++ b/src/Luban.Job.Cfg/Source/Generate/CodeRenderBase.cs @@ -73,7 +73,7 @@ namespace Luban.Job.Cfg.Generate postContent?.Invoke(fileContent); var file = outputFile; - var md5 = CacheFileUtil.GenMd5AndAddCache(file, string.Join('\n', fileContent)); + var md5 = CacheFileUtil.GenMd5AndAddCache(file, string.Join("\n", fileContent)); ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 }); })); } diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/DeepCompareTypeDefine.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/DeepCompareTypeDefine.cs index 561ea8d..1e6802c 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/DeepCompareTypeDefine.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/DeepCompareTypeDefine.cs @@ -104,7 +104,9 @@ namespace Luban.Job.Cfg.TypeVisitors || f1.NeedExport != f2.NeedExport || f1.Index != f2.Index || f1.Sep != f2.Sep +#if !LUBAN_ASSISTANT || f1.ResourceTag != f2.ResourceTag +#endif || f1.IsMultiRow != f2.IsMultiRow || f1.CType.IsNullable != f2.CType.IsNullable || f1.CType.GetType() != f2.CType.GetType() diff --git a/src/Luban.Job.Cfg/Source/TypeVisitors/RefTypeVisitor.cs b/src/Luban.Job.Cfg/Source/TypeVisitors/RefTypeVisitor.cs index 54f3c94..15684dc 100644 --- a/src/Luban.Job.Cfg/Source/TypeVisitors/RefTypeVisitor.cs +++ b/src/Luban.Job.Cfg/Source/TypeVisitors/RefTypeVisitor.cs @@ -1,3 +1,4 @@ +using Bright.Collections; using Luban.Job.Cfg.Defs; using Luban.Job.Common.Defs; using Luban.Job.Common.Types; diff --git a/src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs b/src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs index f7660a9..e7be19b 100644 --- a/src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs +++ b/src/Luban.Job.Cfg/Source/Utils/DataLoaderUtil.cs @@ -32,12 +32,12 @@ namespace Luban.Job.Cfg.Utils public string SheetName { get; set; } } - public static async Task> CollectInputFilesAsync(RemoteAgent agent, IEnumerable files, string dataDir) + public static async Task> CollectInputFilesAsync(IAgent agent, IEnumerable files, string dataDir) { var collectTasks = new List>>(); foreach (var file in files) { - (var actualFile, var sheetName) = RenderFileUtil.SplitFileAndSheetName(FileUtil.Standardize(file)); + (var actualFile, var sheetName) = FileUtil.SplitFileAndSheetName(FileUtil.Standardize(file)); var actualFullPath = FileUtil.Combine(dataDir, actualFile); var originFullPath = FileUtil.Combine(dataDir, file); //s_logger.Info("== get input file:{file} actualFile:{actual}", file, actualFile); @@ -71,7 +71,7 @@ namespace Luban.Job.Cfg.Utils // return CollectInputFilesAsync(agent, table.InputFiles, dataDir) //} - public static async Task GenerateLoadRecordFromFileTasksAsync(RemoteAgent agent, DefTable table, string dataDir, List inputFiles2, List>> tasks) + public static async Task GenerateLoadRecordFromFileTasksAsync(IAgent agent, DefTable table, string dataDir, List inputFiles2, List>> tasks) { var inputFileInfos = await CollectInputFilesAsync(agent, inputFiles2, dataDir); @@ -93,7 +93,7 @@ namespace Luban.Job.Cfg.Utils file.OriginFile, file.SheetName, await agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5), - RenderFileUtil.IsExcelFile(file.ActualFile)); + FileUtil.IsExcelFile(file.ActualFile)); FileRecordCacheManager.Ins.AddCacheLoadedRecords(table, file.MD5, file.SheetName, res); @@ -102,7 +102,7 @@ namespace Luban.Job.Cfg.Utils } } - public static async Task LoadTableAsync(RemoteAgent agent, DefTable table, string dataDir, string patchName, string patchDataDir) + public static async Task LoadTableAsync(IAgent agent, DefTable table, string dataDir, string patchName, string patchDataDir) { var mainLoadTasks = new List>>(); var mainGenerateTask = GenerateLoadRecordFromFileTasksAsync(agent, table, dataDir, table.InputFiles, mainLoadTasks); @@ -145,7 +145,7 @@ namespace Luban.Job.Cfg.Utils s_logger.Trace("table:{name} record num:{num}", table.FullName, mainRecords.Count); } - public static async Task LoadCfgDataAsync(RemoteAgent agent, DefAssembly ass, string dataDir, string patchName, string patchDataDir) + public static async Task LoadCfgDataAsync(IAgent agent, DefAssembly ass, string dataDir, string patchName, string patchDataDir) { var ctx = agent; List exportTables = ass.Types.Values.Where(t => t is DefTable ct && ct.NeedExport).Select(t => (DefTable)t).ToList(); @@ -200,7 +200,7 @@ namespace Luban.Job.Cfg.Utils } } - public static async Task LoadTextTablesAsync(RemoteAgent agent, DefAssembly ass, string baseDir, string textTableFiles) + public static async Task LoadTextTablesAsync(IAgent agent, DefAssembly ass, string baseDir, string textTableFiles) { var tasks = new List>(); var files = textTableFiles.Split(','); diff --git a/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs b/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs index 9d983d3..ba59da2 100644 --- a/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs +++ b/src/Luban.Job.Cfg/Source/Utils/DataUtil.cs @@ -58,7 +58,7 @@ namespace Luban.Job.Cfg.Utils }; public static DDateTime CreateDateTime(string x) { - DateTime dateTime = DateTime.ParseExact(x, dateTimeFormats, System.Globalization.CultureInfo.InvariantCulture); + DateTime dateTime = DateTime.ParseExact(x, dateTimeFormats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None); return new DDateTime(dateTime); } diff --git a/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs b/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs index 2ae7f78..2ad05bb 100644 --- a/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs +++ b/src/Luban.Job.Cfg/Source/Validators/RefValidator.cs @@ -16,7 +16,11 @@ namespace Luban.Job.Cfg.Validators public static string GetActualTableName(string table) { +#if !LUBAN_ASSISTANT return table.EndsWith("?") ? table[0..^1] : table; +#else + return table.EndsWith("?") ? table.Substring(0, table.Length - 1) : table; +#endif } public RefValidator(List tables) @@ -40,7 +44,11 @@ namespace Luban.Job.Cfg.Validators if (table.EndsWith("?")) { zeroAble = true; +#if !LUBAN_ASSISTANT actualTable = table[0..^1]; +#else + actualTable = table.Substring(0, table.Length - 1); +#endif } else { @@ -64,7 +72,11 @@ namespace Luban.Job.Cfg.Validators string actualTable; if (table.EndsWith("?")) { +#if !LUBAN_ASSISTANT actualTable = table[0..^1]; +#else + actualTable = table.Substring(0, table.Length - 1); +#endif } else { @@ -85,7 +97,11 @@ namespace Luban.Job.Cfg.Validators foreach (var table in Tables) { +#if !LUBAN_ASSISTANT string actualTable = table.EndsWith("?") ? table[0..^1] : table; +#else + string actualTable = table.EndsWith("?") ? table.Substring(0, table.Length - 1) : table; +#endif var ct = def.Assembly.GetCfgTable(actualTable); if (ct == null) { diff --git a/src/Luban.Job.Common/Source/Defs/CommonDefLoader.cs b/src/Luban.Job.Common/Source/Defs/CommonDefLoader.cs index 9003c17..f3d9877 100644 --- a/src/Luban.Job.Common/Source/Defs/CommonDefLoader.cs +++ b/src/Luban.Job.Common/Source/Defs/CommonDefLoader.cs @@ -32,7 +32,7 @@ namespace Luban.Job.Common.Defs { private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger(); - protected RemoteAgent Agent { get; } + protected IAgent Agent { get; } public string RootDir { get; private set; } @@ -50,7 +50,7 @@ namespace Luban.Job.Common.Defs protected readonly List _enums = new List(); protected readonly List _beans = new List(); - protected CommonDefLoader(RemoteAgent agent) + protected CommonDefLoader(IAgent agent) { Agent = agent; diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index e3e42f1..8cd0e18 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -32,7 +32,7 @@ namespace Luban.Job.Common.Defs public Dictionary Types { get; } = new Dictionary(); - public RemoteAgent Agent { get; protected set; } + public IAgent Agent { get; protected set; } public string TopModule { get; protected set; } @@ -117,7 +117,11 @@ namespace Luban.Job.Common.Defs public TType CreateType(string module, string type) { +#if LUBAN_ASSISTANT + int sepIndex = type.IndexOf(','); +#else int sepIndex = type.IndexOf(',', System.StringComparison.Ordinal); +#endif if (sepIndex > 0) { string containerType = type.Substring(0, sepIndex).Trim(); @@ -134,14 +138,22 @@ namespace Luban.Job.Common.Defs bool nullable; var (type, tags) = DefUtil.ParseType(rawType); +#if !LUBAN_ASSISTANT if (type.EndsWith('?')) +#else + if (type.EndsWith("?")) +#endif { if (!SupportNullable) { throw new Exception($"not support nullable type:'{module}.{type}'"); } nullable = true; +#if !LUBAN_ASSISTANT type = type[0..^1]; +#else + type = type.Substring(0, type.Length - 1); +#endif } else { diff --git a/src/Luban.Job.Common/Source/Defs/DefEnum.cs b/src/Luban.Job.Common/Source/Defs/DefEnum.cs index e19a7c8..c6a6378 100644 --- a/src/Luban.Job.Common/Source/Defs/DefEnum.cs +++ b/src/Luban.Job.Common/Source/Defs/DefEnum.cs @@ -3,6 +3,7 @@ using Luban.Job.Common.Utils; using System; using System.Collections.Generic; using System.Linq; +using Bright.Collections; namespace Luban.Job.Common.Defs { @@ -11,19 +12,19 @@ namespace Luban.Job.Common.Defs { public class Item { - public string Name { get; init; } + public string Name { get; set; } public string Value { get; set; } - public string Alias { get; init; } + public string Alias { get; set; } public string AliasOrName => string.IsNullOrWhiteSpace(Alias) ? Name : Alias; public int IntValue { get; set; } - public string Comment { get; init; } + public string Comment { get; set; } - public Dictionary Tags { get; init; } + public Dictionary Tags { get; set; } public bool HasTag(string attrName) { diff --git a/src/Luban.Job.Common/Source/Defs/DefTypeBase.cs b/src/Luban.Job.Common/Source/Defs/DefTypeBase.cs index 7f7dbe2..51d7bcf 100644 --- a/src/Luban.Job.Common/Source/Defs/DefTypeBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefTypeBase.cs @@ -12,7 +12,7 @@ namespace Luban.Job.Common.Defs public string TopModule => AssemblyBase.TopModule; - public RemoteAgent Agent => AssemblyBase.Agent; + public IAgent Agent => AssemblyBase.Agent; public string Name { get; set; } diff --git a/src/Luban.Job.Common/Source/Utils/DefUtil.cs b/src/Luban.Job.Common/Source/Utils/DefUtil.cs index 7f91fa9..fce18d4 100644 --- a/src/Luban.Job.Common/Source/Utils/DefUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/DefUtil.cs @@ -21,7 +21,11 @@ namespace Luban.Job.Common.Utils int sepIndex = pair.IndexOfAny(s_attrKeyValueSep); if (sepIndex >= 0) { +#if !LUBAN_ASSISTANT am.Add(pair[..sepIndex].Trim(), pair[(sepIndex + 1)..].Trim()); +#else + am.Add(pair.Substring(0, sepIndex).Trim(), pair.Substring(sepIndex + 1).Trim()); +#endif } else { @@ -40,7 +44,11 @@ namespace Luban.Job.Common.Utils } else { +#if !LUBAN_ASSISTANT return (s[..sepIndex], ParseAttrs(s[(sepIndex + 1)..])); +#else + return (s.Substring(0, sepIndex), ParseAttrs(s.Substring(sepIndex + 1))); +#endif } } diff --git a/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs b/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs index 1d52e36..10faf07 100644 --- a/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/RenderFileUtil.cs @@ -59,34 +59,6 @@ namespace Luban.Job.Common.Utils return fullName + ".bin"; } - public static bool IsExcelFile(string fullName) - { - return fullName.EndsWith(".csv", StringComparison.Ordinal) - || fullName.EndsWith(".xls", StringComparison.Ordinal) - || fullName.EndsWith(".xlsx", StringComparison.Ordinal); - } - - public static (string, string) SplitFileAndSheetName(string url) - { - int sheetSepIndex = url.IndexOf('@'); - if (sheetSepIndex < 0) - { - return (url, null); - } - else - { - int lastPathSep = url.LastIndexOf('/', sheetSepIndex); - if (lastPathSep >= 0) - { - return (url[0..(lastPathSep + 1)] + url[(sheetSepIndex + 1)..], url[(lastPathSep + 1)..sheetSepIndex]); - } - else - { - return (url[(sheetSepIndex + 1)..], url[(lastPathSep + 1)..sheetSepIndex]); - } - } - } - private readonly static Dictionary s_name2Lans = new() { { "cs", ELanguage.CS }, diff --git a/src/Luban.Server.Common/Source/CacheManager.cs b/src/Luban.Server.Common/Source/CacheManager.cs index f02b380..fb313f7 100644 --- a/src/Luban.Server.Common/Source/CacheManager.cs +++ b/src/Luban.Server.Common/Source/CacheManager.cs @@ -126,7 +126,7 @@ namespace Luban.Server.Common break; } - _caches.Remove(c.MD5, out var _); + _caches.Remove(c.MD5); TotalBytes -= c.Content.Length; s_logger.Info("remove cache. file:{file} md5:{md5} size:{size}, total bytes:{bytes} after remove.", c.FileName, c.MD5, c.Content.Length, TotalBytes); }