1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/*=========================================================================
Program: ParaView
Module: vtkLoadStateOptions.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkLoadStateOptions.h"
#include "vtkObjectFactory.h"
#include <vtksys/SystemTools.hxx>
using namespace vtksys;
#include <sstream>
vtkStandardNewMacro(vtkLoadStateOptions);
//----------------------------------------------------------------------------
vtkLoadStateOptions::vtkLoadStateOptions()
{
}
//----------------------------------------------------------------------------
vtkLoadStateOptions::~vtkLoadStateOptions()
{
}
//----------------------------------------------------------------------------
void vtkLoadStateOptions::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
std::string vtkLoadStateOptions::LocateFileInDirectory(const std::string& filepath)
{
std::string result = "";
std::string modifiedDataDirectory = this->DataDirectory;
std::vector<std::string> directoryPathComponents;
// Replace any environment variable defined locations
if (modifiedDataDirectory.compare(0, 1, "$") == 0)
{
SystemTools::SplitPath(modifiedDataDirectory, directoryPathComponents);
std::string variablePath;
if (SystemTools::GetEnv(directoryPathComponents[1].erase(0, 1), variablePath))
{
directoryPathComponents.erase(
directoryPathComponents.begin(), directoryPathComponents.begin() + 2);
std::vector<std::string> variablePathComponents;
SystemTools::SplitPath(variablePath, variablePathComponents);
directoryPathComponents.insert(directoryPathComponents.begin(),
variablePathComponents.begin(), variablePathComponents.end());
}
else
{
vtkErrorMacro("Environment variable " << directoryPathComponents[1] << " is not set.");
return result;
}
}
else
{
SystemTools::SplitPath(
SystemTools::CollapseFullPath(modifiedDataDirectory), directoryPathComponents);
}
std::vector<std::string> pathComponents;
SystemTools::SplitPath(SystemTools::GetParentDirectory(filepath), pathComponents);
size_t insertIndex = directoryPathComponents.size();
while (pathComponents.size() >= 1)
{
std::string searchPath = SystemTools::JoinPath(directoryPathComponents);
if (SystemTools::LocateFileInDir(filepath.c_str(), searchPath.c_str(), result))
{
return result;
}
directoryPathComponents.insert(
directoryPathComponents.begin() + insertIndex, pathComponents.back());
pathComponents.pop_back();
}
std::stringstream str;
str << "Cannot find '" << SystemTools::GetFilenameName(filepath) << " in '"
<< this->DataDirectory.c_str() << "'. Using '" << filepath << "'.\n\n";
vtkOutputWindowDisplayDebugText(str.str().c_str());
return result;
}
|