diff --git a/ApplicationCode/ProjectDataModel/RimCase.cpp b/ApplicationCode/ProjectDataModel/RimCase.cpp index 5c5f99bbc5..a140847734 100644 --- a/ApplicationCode/ProjectDataModel/RimCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimCase.cpp @@ -387,17 +387,21 @@ QString RimCase::relocateFile(const QString& fileName, const QString& newProjec } } - QFileInfo gridFileInfo(fileName); - QFileInfo oldProjPathInfo(oldProjectPath); - QFileInfo newProjPathInfo(newProjectPath); + // Then find the possible move of a directory structure where projects and files referenced are moved in "paralell" - QString gridFilePath = gridFileInfo.canonicalPath(); + QFileInfo gridFileInfo(QDir::fromNativeSeparators(fileName)); + QString gridFilePath = gridFileInfo.path(); + QString gridFileNameWoPath = gridFileInfo.fileName(); QStringList gridPathElements = gridFilePath.split("/", QString::KeepEmptyParts); - QString oldProjPath = oldProjPathInfo.canonicalPath(); + + QString oldProjPath = QDir::fromNativeSeparators(oldProjectPath); QStringList oldProjPathElements = oldProjPath.split("/", QString::KeepEmptyParts); - QString newProjPath = newProjPathInfo.canonicalPath(); + + QString newProjPath = QDir::fromNativeSeparators(newProjectPath); QStringList newProjPathElements = newProjPath.split("/", QString::KeepEmptyParts); + // Find the possible equal start of the old project path, and the referenced file + bool pathStartsAreEqual = false; bool pathEndsDiffer = false; int firstDiffIdx = 0; @@ -419,6 +423,8 @@ QString RimCase::relocateFile(const QString& fileName, const QString& newProjec 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 (pathEndsDiffer) @@ -458,7 +464,7 @@ QString RimCase::relocateFile(const QString& fileName, const QString& newProjec QString relocationPath = newProjecetFileStartPath + oldGridFilePathEnd; - QString relocatedFileName = relocationPath + gridFileInfo.fileName(); + QString relocatedFileName = relocationPath + gridFileNameWoPath; if (searchedPaths) searchedPaths->push_back(relocatedFileName); @@ -470,7 +476,7 @@ QString RimCase::relocateFile(const QString& fileName, const QString& newProjec else { // 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 } }