summaryrefslogtreecommitdiff
path: root/view/sharedcache
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
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')
-rw-r--r--view/sharedcache/core/SharedCacheView.cpp17
-rw-r--r--view/sharedcache/core/Utility.cpp9
-rw-r--r--view/sharedcache/core/Utility.h1
3 files changed, 25 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;
diff --git a/view/sharedcache/core/Utility.cpp b/view/sharedcache/core/Utility.cpp
index 0cffc03e..8f49c6bf 100644
--- a/view/sharedcache/core/Utility.cpp
+++ b/view/sharedcache/core/Utility.cpp
@@ -137,6 +137,15 @@ std::string BaseFileName(const std::string& path)
return path;
}
+bool IsSameFolderForFile(Ref<ProjectFile> a, Ref<ProjectFile> b)
+{
+ if (!a && !b)
+ return true;
+ if (a && b)
+ return IsSameFolder(a->GetFolder(), b->GetFolder());
+ return false;
+}
+
bool IsSameFolder(Ref<ProjectFolder> a, Ref<ProjectFolder> b)
{
if (!a && !b)
diff --git a/view/sharedcache/core/Utility.h b/view/sharedcache/core/Utility.h
index 81c3b583..5664fd9b 100644
--- a/view/sharedcache/core/Utility.h
+++ b/view/sharedcache/core/Utility.h
@@ -40,6 +40,7 @@ void ApplySymbol(BinaryNinja::Ref<BinaryNinja::BinaryView> view, BinaryNinja::Re
// /blah/foo/bar/libObjCThing.dylib -> libObjCThing.dylib
std::string BaseFileName(const std::string& path);
+bool IsSameFolderForFile(BinaryNinja::Ref<BinaryNinja::ProjectFile> a, BinaryNinja::Ref<BinaryNinja::ProjectFile> b);
bool IsSameFolder(BinaryNinja::Ref<BinaryNinja::ProjectFolder> a, BinaryNinja::Ref<BinaryNinja::ProjectFolder> b);
// Represents a range of addresses [start, end).