@@ -84,9 +84,26 @@ void Variable::setValue(const Value& val)
8484 if (boost::get<std::string>(&val))
8585 {
8686 auto stringPath = toString ();
87- if (SCIRun::Core::replaceSubstring (stringPath, AlgorithmParameterHelper::dataDir ().string (), AlgorithmParameterHelper::dataDirPlaceholder ()))
88- value_ = stringPath;
89- return ;
87+ {
88+ // TODO #787
89+ // loop through all paths in path list, checking if file in each dir; if one found replace and return
90+ if (SCIRun::Core::replaceSubstring (stringPath, AlgorithmParameterHelper::dataDir ().string (), AlgorithmParameterHelper::dataDirPlaceholder ()))
91+ {
92+ value_ = stringPath;
93+ return ;
94+ }
95+
96+ for (const auto & path : AlgorithmParameterHelper::dataPath ())
97+ {
98+ if (SCIRun::Core::replaceSubstring (stringPath, path.string (), AlgorithmParameterHelper::dataDirPlaceholder ()))
99+ {
100+ value_ = stringPath;
101+ return ;
102+ }
103+ }
104+
105+ return ;
106+ }
90107 }
91108 }
92109
@@ -142,7 +159,18 @@ boost::filesystem::path AlgorithmParameter::toFilename() const
142159 {
143160 // TODO #787
144161 // loop through all paths in path list, checking if file exists each time. return first one that exists.
145- return AlgorithmParameterHelper::dataDir () / stringPath;
162+ auto initialPath = AlgorithmParameterHelper::dataDir () / stringPath;
163+ if (boost::filesystem::exists (initialPath))
164+ return initialPath;
165+
166+ for (const auto & path : AlgorithmParameterHelper::dataPath ())
167+ {
168+ auto nextPath = path / stringPath;
169+ if (boost::filesystem::exists (nextPath))
170+ return nextPath;
171+ }
172+ // nothing found, let module deal with it.
173+ return initialPath;
146174 }
147175
148176 boost::filesystem::path p (stringPath);
@@ -197,7 +225,18 @@ std::string AlgorithmParameterHelper::dataDirPlaceholder()
197225 return dataDirPlaceholder_;
198226}
199227
228+ void AlgorithmParameterHelper::setDataPath (const std::vector<boost::filesystem::path>& paths)
229+ {
230+ paths_ = paths;
231+ }
232+
233+ std::vector<boost::filesystem::path> AlgorithmParameterHelper::dataPath ()
234+ {
235+ return paths_;
236+ }
237+
200238boost::filesystem::path AlgorithmParameterHelper::dataDir_;
239+ std::vector<boost::filesystem::path> AlgorithmParameterHelper::paths_;
201240std::string AlgorithmParameterHelper::dataDirPlaceholder_;
202241Mutex AlgorithmParameterHelper::lock_ (" fsbug" );
203242
0 commit comments