From 4d037dc29ff2aabc25f45c7a2b242c50c9b37d92 Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 7 Jan 2025 21:16:15 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E5=BD=93=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=A0=B9=E7=9B=AE=E5=BD=95=E5=8F=8A=E4=B8=8A=E7=BA=A7?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E4=B8=AD=E4=BB=A5'.'=E4=B9=8B=E7=B1=BB?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E5=BC=80=E5=A4=B4=E6=97=B6=EF=BC=8C=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=9C=B0=E5=BF=BD=E7=95=A5=E4=BA=86=E6=89=80=E6=9C=89?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Luban.Core/DataLoader/DataLoaderManager.cs | 2 +- src/Luban.Core/GlobalConfigLoader.cs | 2 +- src/Luban.Core/Utils/FileUtil.cs | 14 ++++++++++---- .../BeanSchemaFromExcelHeaderLoader.cs | 2 +- src/Luban.Schema.Builtin/DefaultTableImporter.cs | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Luban.Core/DataLoader/DataLoaderManager.cs b/src/Luban.Core/DataLoader/DataLoaderManager.cs index e1395f42..fc738287 100644 --- a/src/Luban.Core/DataLoader/DataLoaderManager.cs +++ b/src/Luban.Core/DataLoader/DataLoaderManager.cs @@ -33,7 +33,7 @@ private void LoadTable(GenerationContext ctx, DefTable table) s_logger.Trace("load table:{} file:{}", table.FullName, inputFile); var (actualFile, subAssetName) = FileUtil.SplitFileAndSheetName(FileUtil.Standardize(inputFile)); var options = new Dictionary(); - foreach (var atomFile in FileUtil.GetFileOrDirectory(Path.Combine(inputDataDir, actualFile))) + foreach (var atomFile in FileUtil.GetFileOrDirectory(inputDataDir, Path.Combine(inputDataDir, actualFile))) { s_logger.Trace("load table:{} atomfile:{}", table.FullName, atomFile); tasks.Add(Task.Run(() => LoadTableFile(table, atomFile, subAssetName, options))); diff --git a/src/Luban.Core/GlobalConfigLoader.cs b/src/Luban.Core/GlobalConfigLoader.cs index a34c9b30..1b846a54 100644 --- a/src/Luban.Core/GlobalConfigLoader.cs +++ b/src/Luban.Core/GlobalConfigLoader.cs @@ -86,7 +86,7 @@ public LubanConfig Load(string fileName) throw new Exception($"failed to load schema file:'{fileOrDirectory}': directory or file doesn't exists!"); } } - foreach (var subFile in FileUtil.GetFileOrDirectory(fileOrDirectory)) + foreach (var subFile in FileUtil.GetFileOrDirectory(_curDir, fileOrDirectory)) { importFiles.Add(new SchemaFileInfo() { FileName = subFile, Type = schemaFile.Type }); } diff --git a/src/Luban.Core/Utils/FileUtil.cs b/src/Luban.Core/Utils/FileUtil.cs index 39ffa42c..fb55eb80 100644 --- a/src/Luban.Core/Utils/FileUtil.cs +++ b/src/Luban.Core/Utils/FileUtil.cs @@ -226,20 +226,26 @@ public static void DeleteDirectoryRecursive(string rootDir) Directory.Delete(rootDir, false); } - public static bool IsIgnoreFile(string file) + public static bool IsIgnoreFile(string baseDir, string file) { - file = Path.GetFullPath(file); + baseDir = Path.GetFullPath(baseDir.Replace('\\', '/')); + file = Path.GetFullPath(file.Replace('\\', '/')); + // if baseDir contains '.' or '_', we shouldn't ignore it. + if (file.Length > baseDir.Length && file.StartsWith(baseDir) && (file[baseDir.Length] == '\\' || file[baseDir.Length] == '/')) + { + file = file[(baseDir.Length + 1)..]; + } return file.Split('\\', '/').Any(fileName => fileName.StartsWith(".") || fileName.StartsWith("_") || fileName.StartsWith("~")); } - public static List GetFileOrDirectory(string fileOrDirectory) + public static List GetFileOrDirectory(string baseDir, string fileOrDirectory) { var files = new List(); if (Directory.Exists(fileOrDirectory)) { foreach (var file in Directory.GetFiles(fileOrDirectory, "*", SearchOption.AllDirectories)) { - if (IsIgnoreFile(file)) + if (IsIgnoreFile(baseDir, file)) { continue; } diff --git a/src/Luban.Schema.Builtin/BeanSchemaFromExcelHeaderLoader.cs b/src/Luban.Schema.Builtin/BeanSchemaFromExcelHeaderLoader.cs index 2dee30ea..798f665c 100644 --- a/src/Luban.Schema.Builtin/BeanSchemaFromExcelHeaderLoader.cs +++ b/src/Luban.Schema.Builtin/BeanSchemaFromExcelHeaderLoader.cs @@ -34,7 +34,7 @@ public static RawBean LoadTableValueTypeDefineFromFile(string fileName, string v { if (Directory.Exists(fileName)) { - var files = FileUtil.GetFileOrDirectory(fileName); + var files = FileUtil.GetFileOrDirectory(Directory.GetParent(fileName).FullName, fileName); var firstExcelFile = files.FirstOrDefault(f => FileUtil.IsExcelFile(f)); if (firstExcelFile == null) { diff --git a/src/Luban.Schema.Builtin/DefaultTableImporter.cs b/src/Luban.Schema.Builtin/DefaultTableImporter.cs index e56652a3..7e32a01e 100644 --- a/src/Luban.Schema.Builtin/DefaultTableImporter.cs +++ b/src/Luban.Schema.Builtin/DefaultTableImporter.cs @@ -29,7 +29,7 @@ public List LoadImportTables() var tables = new List(); foreach (string file in Directory.GetFiles(dataDir, "*", SearchOption.AllDirectories)) { - if (FileUtil.IsIgnoreFile(file)) + if (FileUtil.IsIgnoreFile(dataDir, file)) { continue; }