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; }