@@ -155,27 +155,19 @@ bool Platform::set(const std::string& platformstr, std::string& errstr, const st
155155 errstr = " unrecognized platform: '" + platformstr + " ' (no lookup)." ;
156156 return false ;
157157 }
158- else {
159- bool found = false ;
160- for (const std::string& path : paths) {
161- if (debug)
162- std::cout << " looking for platform '" + platformstr + " ' relative to '" + path + " '" << std::endl;
163- if (loadFromFile (path.c_str (), platformstr, debug)) {
164- found = true ;
165- break ;
166- }
167- }
168- if (!found) {
169- errstr = " unrecognized platform: '" + platformstr + " '." ;
170- return false ;
171- }
158+ else if (!loadFromFile (paths, platformstr, debug)) {
159+ errstr = " unrecognized platform: '" + platformstr + " '." ;
160+ return false ;
172161 }
173162
174163 return true ;
175164}
176165
177- bool Platform::loadFromFile (const char exename[] , const std::string &filename, bool debug)
166+ bool Platform::loadFromFile (const std::vector<std::string>& paths , const std::string &filename, bool debug)
178167{
168+ if (debug)
169+ std::cout << " looking for platform '" + filename + " '" << std::endl;
170+
179171 const bool is_abs_path = Path::isAbsolute (filename);
180172
181173 std::string fullfilename (filename);
@@ -185,20 +177,33 @@ bool Platform::loadFromFile(const char exename[], const std::string &filename, b
185177 fullfilename += " .xml" ;
186178
187179 // TODO: use native separators
188- std::vector<std::string> filenames{
189- fullfilename,
190- };
191- if (!is_abs_path) {
192- filenames.push_back (" platforms/" + fullfilename);
193- if (exename && (std::string::npos != Path::fromNativeSeparators (exename).find (' /' ))) {
194- filenames.push_back (Path::getPathFromFilename (Path::fromNativeSeparators (exename)) + fullfilename);
195- filenames.push_back (Path::getPathFromFilename (Path::fromNativeSeparators (exename)) + " platforms/" + fullfilename);
180+ std::vector<std::string> filenames;
181+ if (is_abs_path)
182+ {
183+ filenames.push_back (fullfilename);
184+ }
185+ else {
186+ // TODO: drop duplicated paths
187+ for (const std::string& path : paths)
188+ {
189+ if (path.empty ())
190+ continue ; // TODO: error out instead?
191+
192+ std::string ppath = Path::fromNativeSeparators (path);
193+ if (ppath.back () != ' /' )
194+ ppath += ' /' ;
195+ // TODO: look in platforms first?
196+ filenames.push_back (ppath + fullfilename);
197+ filenames.push_back (ppath + " platforms/" + fullfilename);
196198 }
197199#ifdef FILESDIR
198200 std::string filesdir = FILESDIR;
199- if (!filesdir.empty () && filesdir[filesdir.size ()-1 ] != ' /' )
200- filesdir += ' /' ;
201- filenames.push_back (filesdir + (" platforms/" + fullfilename));
201+ if (!filesdir.empty ()) {
202+ if (filesdir.back () != ' /' )
203+ filesdir += ' /' ;
204+ // TODO: look in filesdir?
205+ filenames.push_back (filesdir + " platforms/" + fullfilename);
206+ }
202207#endif
203208 }
204209
0 commit comments