summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/SharedCacheView.cpp
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-14 02:52:47 -0400
committerMason Reed <mason@vector35.com>2025-04-14 03:20:51 -0400
commitecdb87a7b737c3d432775b748f9cff686230f28d (patch)
tree66ec4ccd8f96bc6efb435e262c6d7d1c38ea880b /view/sharedcache/core/SharedCacheView.cpp
parent09a617a7a86207eaf09ccd5ebc72e734275baa66 (diff)
[SharedCache] Allow project databases to be stored in a separate folder
However the primary file will need to be selected each time you open, for that to be resolved we need to use project file UUID's or the cache entry UUID's themselves to traverse all project files
Diffstat (limited to 'view/sharedcache/core/SharedCacheView.cpp')
-rw-r--r--view/sharedcache/core/SharedCacheView.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/view/sharedcache/core/SharedCacheView.cpp b/view/sharedcache/core/SharedCacheView.cpp
index 253ecd26..fb80d132 100644
--- a/view/sharedcache/core/SharedCacheView.cpp
+++ b/view/sharedcache/core/SharedCacheView.cpp
@@ -811,6 +811,19 @@ bool SharedCacheView::InitController()
}
std::string primaryFileDir = std::filesystem::path(*primaryFilePath).parent_path().string();
+ // Get the primary project file from the current files project.
+ // This is required to allow selecting a primary file in a different directory. Otherwise, we search the current database directory.
+ Ref<ProjectFile> primaryProjectFile = nullptr;
+ auto currentProjectFile = GetFile()->GetProjectFile();
+ if (currentProjectFile)
+ primaryProjectFile = currentProjectFile->GetProject()->GetFileByPathOnDisk(*primaryFilePath);
+
+ if (!IsSameFolderForFile(primaryProjectFile, currentProjectFile))
+ {
+ // TODO: Remove this restriction using stored cache UUID's and a fast project file search.
+ m_logger->LogWarn("Because the primary file is in a different project folder you will need to select it on every open, consider moving the database file into the same folder.");
+ }
+
// OK, we have the primary shared cache file, now let's add the entries.
auto sharedCacheBuilder = SharedCacheBuilder(this);
sharedCacheBuilder.SetPrimaryFileName(m_primaryFileName);
@@ -827,8 +840,8 @@ bool SharedCacheView::InitController()
// After this we should have all the mappings available as well.
auto startTime = std::chrono::high_resolution_clock::now();
sharedCacheBuilder.AddDirectory(primaryFileDir);
- if (auto projectFile = GetFile()->GetProjectFile())
- sharedCacheBuilder.AddProjectFolder(projectFile->GetFolder());
+ if (primaryProjectFile)
+ sharedCacheBuilder.AddProjectFolder(primaryProjectFile->GetFolder());
auto totalEntries = sharedCacheBuilder.GetCache().GetEntries().size();
auto endTime = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = endTime - startTime;