External file references: Fixed the relocation in the advanced cases

p4#: 21253
This commit is contained in:
Jacob Støren 2013-04-12 09:43:40 +02:00
parent e5f9b41c0f
commit 432106c9c5

View File

@ -387,17 +387,21 @@ QString RimCase::relocateFile(const QString& fileName, const QString& newProjec
} }
} }
QFileInfo gridFileInfo(fileName); // Then find the possible move of a directory structure where projects and files referenced are moved in "paralell"
QFileInfo oldProjPathInfo(oldProjectPath);
QFileInfo newProjPathInfo(newProjectPath);
QString gridFilePath = gridFileInfo.canonicalPath(); QFileInfo gridFileInfo(QDir::fromNativeSeparators(fileName));
QString gridFilePath = gridFileInfo.path();
QString gridFileNameWoPath = gridFileInfo.fileName();
QStringList gridPathElements = gridFilePath.split("/", QString::KeepEmptyParts); QStringList gridPathElements = gridFilePath.split("/", QString::KeepEmptyParts);
QString oldProjPath = oldProjPathInfo.canonicalPath();
QString oldProjPath = QDir::fromNativeSeparators(oldProjectPath);
QStringList oldProjPathElements = oldProjPath.split("/", QString::KeepEmptyParts); QStringList oldProjPathElements = oldProjPath.split("/", QString::KeepEmptyParts);
QString newProjPath = newProjPathInfo.canonicalPath();
QString newProjPath = QDir::fromNativeSeparators(newProjectPath);
QStringList newProjPathElements = newProjPath.split("/", QString::KeepEmptyParts); QStringList newProjPathElements = newProjPath.split("/", QString::KeepEmptyParts);
// Find the possible equal start of the old project path, and the referenced file
bool pathStartsAreEqual = false; bool pathStartsAreEqual = false;
bool pathEndsDiffer = false; bool pathEndsDiffer = false;
int firstDiffIdx = 0; int firstDiffIdx = 0;
@ -419,6 +423,8 @@ QString RimCase::relocateFile(const QString& fileName, const QString& newProjec
pathEndsDiffer = true; pathEndsDiffer = true;
} }
// If the path starts are equal, try to substitute it in the referenced file, with the corresponding new project path start
if (pathStartsAreEqual) if (pathStartsAreEqual)
{ {
if (pathEndsDiffer) if (pathEndsDiffer)
@ -458,7 +464,7 @@ QString RimCase::relocateFile(const QString& fileName, const QString& newProjec
QString relocationPath = newProjecetFileStartPath + oldGridFilePathEnd; QString relocationPath = newProjecetFileStartPath + oldGridFilePathEnd;
QString relocatedFileName = relocationPath + gridFileInfo.fileName(); QString relocatedFileName = relocationPath + gridFileNameWoPath;
if (searchedPaths) searchedPaths->push_back(relocatedFileName); if (searchedPaths) searchedPaths->push_back(relocatedFileName);
@ -470,7 +476,7 @@ QString RimCase::relocateFile(const QString& fileName, const QString& newProjec
else else
{ {
// The Grid file was located in the same dir as the Project file. This is supposed to be handled above. // The Grid file was located in the same dir as the Project file. This is supposed to be handled above.
CVF_ASSERT(false); // So we did not find it
} }
} }