Skip to content

Commit

Permalink
Merge branch 'focus-creative-games:main' into csv
Browse files Browse the repository at this point in the history
  • Loading branch information
absences authored Jan 8, 2025
2 parents a2ced36 + 4d037dc commit dfab151
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Luban.Core/DataLoader/DataLoaderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>();
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)));
Expand Down
2 changes: 1 addition & 1 deletion src/Luban.Core/GlobalConfigLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
14 changes: 10 additions & 4 deletions src/Luban.Core/Utils/FileUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> GetFileOrDirectory(string fileOrDirectory)
public static List<string> GetFileOrDirectory(string baseDir, string fileOrDirectory)
{
var files = new List<string>();
if (Directory.Exists(fileOrDirectory))
{
foreach (var file in Directory.GetFiles(fileOrDirectory, "*", SearchOption.AllDirectories))
{
if (IsIgnoreFile(file))
if (IsIgnoreFile(baseDir, file))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Luban.Schema.Builtin/DefaultTableImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public List<RawTable> LoadImportTables()
var tables = new List<RawTable>();
foreach (string file in Directory.GetFiles(dataDir, "*", SearchOption.AllDirectories))
{
if (FileUtil.IsIgnoreFile(file))
if (FileUtil.IsIgnoreFile(dataDir, file))
{
continue;
}
Expand Down

0 comments on commit dfab151

Please sign in to comment.