From f3f43af65e86b6b9b8a40b33a694efa1779616fe Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 7 Apr 2025 20:57:52 -0400 Subject: [SharedCache] Allow the user to select the original shared cache file on disk This gives the user the ability to take a database with no original file path continue processing entries with the user supplied base file. This also will set the original file path for future loads, we might want to make that optional. And the behavior with remote projects for that might be undesired. --- view/sharedcache/core/SharedCache.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'view/sharedcache/core/SharedCache.cpp') diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index bfb10d90..0b8653d7 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -553,6 +553,19 @@ bool CacheProcessor::ProcessFileCache(SharedCache& cache) std::string baseFilePath = m_view->GetFile()->GetOriginalFilename(); std::string baseFileName = BaseFileName(baseFilePath); + // If we don't have an original file path, prompt the user to select one. + if (baseFilePath.empty()) + { + if (!GetOpenFileNameInput(baseFilePath, "Please select the base shared cache file")) + { + // User did not give a file, tell them that we will try and scan the file directory. + m_logger->LogWarn("Failed to get original file path, will try and scan the file directory."); + } + // Update so next load we don't need to prompt the user. + // TODO: What happens for a remote project? This will point at what exactly? + m_view->GetFile()->SetOriginalFilename(baseFilePath); + } + // Add this file to the entries try { @@ -614,11 +627,24 @@ bool CacheProcessor::ProcessFileCache(SharedCache& cache) bool CacheProcessor::ProcessProjectCache(SharedCache& cache) { auto baseProjectFile = m_view->GetFile()->GetProjectFile(); + auto baseProjectFileFolder = baseProjectFile->GetFolder(); std::string baseFilePath = baseProjectFile->GetPathOnDisk(); std::string baseFileName = baseProjectFile->GetName(); // This will point to the path on disk for original non-bndb file. std::string originalFilePath = m_view->GetFile()->GetOriginalFilename(); + // If we don't have an original file path, prompt the user to select one. + if (originalFilePath.empty()) + { + if (!GetOpenFileNameInput(originalFilePath, "Please select the base shared cache file")) + { + // User did not give a file, tell them that we will try and scan the project directory. + m_logger->LogWarn("Failed to get original file path, will try and scan the project directory."); + } + // Update so next load we don't need to prompt the user. + m_view->GetFile()->SetOriginalFilename(originalFilePath); + } + // Remove the .bndb extension if present ("dyld_shared_cache_arm64e.bndb" => "dyld_shared_cache_arm64e) // TODO: This is a little annoying, we need to do this because the file accessor we have is separate // TODO: from the view file accessor. If we either made it so that we can parse from the BNDB file accessor, @@ -629,6 +655,12 @@ bool CacheProcessor::ProcessProjectCache(SharedCache& cache) // Search for the backing file. for (const auto& projectFile : baseProjectFile->GetProject()->GetFiles()) { + // Skip files not in the same folder. + auto projectFileFolder = projectFile->GetFolder(); + if (baseProjectFileFolder && projectFileFolder) + if (baseProjectFileFolder->GetId() != projectFileFolder->GetId()) + continue; + auto projectFilePath = projectFile->GetPathOnDisk(); auto projectFileName = projectFile->GetName(); if (projectFileName == baseFileName || projectFilePath == originalFilePath) -- cgit v1.3.1