@@ -170,27 +170,19 @@ bool Platform::set(const std::string& platformstr, std::string& errstr, const st
170170 errstr = " unrecognized platform: '" + platformstr + " ' (no lookup)." ;
171171 return false ;
172172 }
173- else {
174- bool found = false ;
175- for (const std::string& path : paths) {
176- if (debug)
177- std::cout << " looking for platform '" + platformstr + " ' relative to '" + path + " '" << std::endl;
178- if (loadFromFile (path.c_str (), platformstr, debug)) {
179- found = true ;
180- break ;
181- }
182- }
183- if (!found) {
184- errstr = " unrecognized platform: '" + platformstr + " '." ;
185- return false ;
186- }
173+ else if (!loadFromFile (paths, platformstr, debug)) {
174+ errstr = " unrecognized platform: '" + platformstr + " '." ;
175+ return false ;
187176 }
188177
189178 return true ;
190179}
191180
192- bool Platform::loadFromFile (const char exename[] , const std::string &filename, bool debug)
181+ bool Platform::loadFromFile (const std::vector<std::string>& paths , const std::string &filename, bool debug)
193182{
183+ if (debug)
184+ std::cout << " looking for platform '" + filename + " '" << std::endl;
185+
194186 const bool is_abs_path = Path::isAbsolute (filename);
195187
196188 std::string fullfilename (filename);
@@ -200,20 +192,33 @@ bool Platform::loadFromFile(const char exename[], const std::string &filename, b
200192 fullfilename += " .xml" ;
201193
202194 // TODO: use native separators
203- std::vector<std::string> filenames{
204- fullfilename,
205- };
206- if (!is_abs_path) {
207- filenames.push_back (" platforms/" + fullfilename);
208- if (exename && (std::string::npos != Path::fromNativeSeparators (exename).find (' /' ))) {
209- filenames.push_back (Path::getPathFromFilename (Path::fromNativeSeparators (exename)) + fullfilename);
210- filenames.push_back (Path::getPathFromFilename (Path::fromNativeSeparators (exename)) + " platforms/" + fullfilename);
195+ std::vector<std::string> filenames;
196+ if (is_abs_path)
197+ {
198+ filenames.push_back (fullfilename);
199+ }
200+ else {
201+ // TODO: drop duplicated paths
202+ for (const std::string& path : paths)
203+ {
204+ if (path.empty ())
205+ continue ; // TODO: error out instead?
206+
207+ std::string ppath = Path::fromNativeSeparators (path);
208+ if (ppath.back () != ' /' )
209+ ppath += ' /' ;
210+ // TODO: look in platforms first?
211+ filenames.push_back (ppath + fullfilename);
212+ filenames.push_back (ppath + " platforms/" + fullfilename);
211213 }
212214#ifdef FILESDIR
213215 std::string filesdir = FILESDIR;
214- if (!filesdir.empty () && filesdir[filesdir.size ()-1 ] != ' /' )
215- filesdir += ' /' ;
216- filenames.push_back (filesdir + (" platforms/" + fullfilename));
216+ if (!filesdir.empty ()) {
217+ if (filesdir.back () != ' /' )
218+ filesdir += ' /' ;
219+ // TODO: look in filesdir?
220+ filenames.push_back (filesdir + " platforms/" + fullfilename);
221+ }
217222#endif
218223 }
219224
0 commit comments