Implement initial Unity-style asset library cache

This commit is contained in:
2026-04-02 03:03:36 +08:00
parent 619856ab22
commit 4c167bec0e
29 changed files with 4818 additions and 73 deletions

View File

@@ -121,6 +121,27 @@ fs::path MakeCaseOnlyRenameTempPath(const fs::path& sourcePath) {
}
}
fs::path GetMetaSidecarPath(const fs::path& assetPath) {
return fs::path(assetPath.wstring() + L".meta");
}
bool RenamePathCaseAware(const fs::path& sourcePath, const fs::path& destPath);
void MoveMetaSidecarIfPresent(const fs::path& sourcePath, const fs::path& destPath) {
const fs::path sourceMetaPath = GetMetaSidecarPath(sourcePath);
if (!fs::exists(sourceMetaPath)) {
return;
}
const fs::path destMetaPath = GetMetaSidecarPath(destPath);
RenamePathCaseAware(sourceMetaPath, destMetaPath);
}
void RemoveMetaSidecarIfPresent(const fs::path& assetPath) {
std::error_code ec;
fs::remove_all(GetMetaSidecarPath(assetPath), ec);
}
bool RenamePathCaseAware(const fs::path& sourcePath, const fs::path& destPath) {
if (MakePathKey(sourcePath) != MakePathKey(destPath)) {
if (fs::exists(destPath)) {
@@ -383,6 +404,7 @@ bool ProjectManager::DeleteItem(const std::string& fullPath) {
}
fs::remove_all(itemPath);
RemoveMetaSidecarIfPresent(itemPath);
if (m_selectedItemPath == fullPath) {
ClearSelection();
}
@@ -422,6 +444,7 @@ bool ProjectManager::MoveItem(const std::string& sourceFullPath, const std::stri
}
fs::rename(sourcePath, destPath);
MoveMetaSidecarIfPresent(sourcePath, destPath);
RefreshCurrentFolder();
return true;
} catch (...) {
@@ -458,6 +481,7 @@ bool ProjectManager::RenameItem(const std::string& sourceFullPath, const std::st
if (!RenamePathCaseAware(sourcePath, destPath)) {
return false;
}
MoveMetaSidecarIfPresent(sourcePath, destPath);
if (!m_selectedItemPath.empty() &&
MakePathKey(Utf8PathToWstring(m_selectedItemPath)) == MakePathKey(sourcePath))
@@ -501,6 +525,13 @@ AssetItemPtr ProjectManager::ScanDirectory(const std::wstring& path) {
try {
for (const auto& entry : fs::directory_iterator(path)) {
std::wstring nameW = entry.path().filename().wstring();
if (!entry.is_directory()) {
std::wstring lowerName = nameW;
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::towlower);
if (lowerName.size() >= 5 && lowerName.substr(lowerName.size() - 5) == L".meta") {
continue;
}
}
bool isFolder = entry.is_directory();
items.push_back(CreateAssetItem(entry.path().wstring(), nameW, isFolder));
}