Skip to content

Commit

Permalink
perf: 游戏资源服务只读取需要处理的文件格式
Browse files Browse the repository at this point in the history
  • Loading branch information
textGamex committed Dec 2, 2024
1 parent 2fd1c87 commit c1abb85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 5 additions & 6 deletions Moder.Core/Services/GameResources/Base/ResourcesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ protected ResourcesService(string folderOrFileRelativePath, WatcherFilter filter

var isFolderPath = pathType == PathType.Folder;
var filePaths = isFolderPath
? gameResourcesPathService.GetAllFilePriorModByRelativePathForFolder(_folderOrFileRelativePath)
? gameResourcesPathService.GetAllFilePriorModByRelativePathForFolder(
_folderOrFileRelativePath,
filter.Name
)
: [gameResourcesPathService.GetFilePathPriorModByRelativePath(folderOrFileRelativePath)];

// Resources 必须在使用 ParseFileAndAddToResources 之前初始化
Expand All @@ -55,11 +58,7 @@ protected ResourcesService(string folderOrFileRelativePath, WatcherFilter filter
this,
filter.Name
);
Log.Info(
"初始化资源成功: {FolderRelativePath}, 共 {Count} 个文件",
_folderOrFileRelativePath,
filePaths.Count
);
Log.Info("初始化资源成功: {FolderRelativePath}, 共 {Count} 个文件", _folderOrFileRelativePath, filePaths.Count);
LogItemsSum();
}

Expand Down
14 changes: 9 additions & 5 deletions Moder.Core/Services/GameResources/GameResourcesPathService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ params string[] folderRelativePaths
/// 获得所有应该加载的文件绝对路径, Mod优先, 遵循 replace_path 指令
/// </summary>
/// <param name="folderRelativePath"></param>
/// <param name="filter"></param>
/// <returns></returns>
/// <exception cref="DirectoryNotFoundException"></exception>
public IReadOnlyCollection<string> GetAllFilePriorModByRelativePathForFolder(string folderRelativePath)
public IReadOnlyCollection<string> GetAllFilePriorModByRelativePathForFolder(
string folderRelativePath,
string filter = "*.*"
)
{
Log.Info("正在获取文件夹 {Path} 下的文件", folderRelativePath);
var modFolder = Path.Combine(_settingService.ModRootFolderPath, folderRelativePath);
Expand All @@ -43,7 +47,7 @@ public IReadOnlyCollection<string> GetAllFilePriorModByRelativePathForFolder(str

if (!Directory.Exists(modFolder))
{
return Directory.GetFiles(gameFolder);
return Directory.GetFiles(gameFolder, filter);
}

if (_descriptor.ReplacePaths.Contains(folderRelativePath))
Expand All @@ -53,11 +57,11 @@ public IReadOnlyCollection<string> GetAllFilePriorModByRelativePathForFolder(str
gameFolder.ToFilePath(),
modFolder.ToFilePath()
);
return Directory.GetFiles(modFolder);
return Directory.GetFiles(modFolder, filter);
}

var gameFilesPath = Directory.GetFiles(gameFolder);
var modFilesPath = Directory.GetFiles(modFolder);
var gameFilesPath = Directory.GetFiles(gameFolder, filter);
var modFilesPath = Directory.GetFiles(modFolder, filter);
return RemoveFileOfEqualName(gameFilesPath, modFilesPath);
}

Expand Down

0 comments on commit c1abb85

Please sign in to comment.