@@ -87,12 +87,15 @@ Library::Error Library::load(const char exename[], const char path[], bool debug
8787 return Error ();
8888 }
8989
90+ const bool is_abs_path = Path::isAbsolute (path);
91+
9092 std::string absolute_path;
9193 // open file..
9294 tinyxml2::XMLDocument doc;
9395 if (debug)
9496 std::cout << " looking for library '" + std::string (path) + " '" << std::endl;
9597 tinyxml2::XMLError error = doc.LoadFile (path);
98+ // TODO: do not ignore read errors
9699 if (error == tinyxml2::XML_ERROR_FILE_READ_ERROR && Path::getFilenameExtension (path).empty ())
97100 {
98101 // Reading file failed, try again...
@@ -110,27 +113,31 @@ Library::Error Library::load(const char exename[], const char path[], bool debug
110113 absolute_path = Path::getAbsoluteFilePath (fullfilename);
111114 }
112115
113- std::list<std::string> cfgfolders;
114- #ifdef FILESDIR
115- cfgfolders.emplace_back (FILESDIR " /cfg" );
116- #endif
117- if (exename) {
118- const std::string exepath (Path::fromNativeSeparators (Path::getPathFromFilename (Path::getCurrentExecutablePath (exename))));
119- cfgfolders.push_back (exepath + " cfg" );
120- cfgfolders.push_back (exepath + " ../cfg" );
121- cfgfolders.push_back (exepath);
122- }
116+ // only perform further lookups when the given path was not absolute
117+ if (!is_abs_path && error == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
118+ {
119+ std::list<std::string> cfgfolders;
120+ #ifdef FILESDIR
121+ cfgfolders.emplace_back (FILESDIR " /cfg" );
122+ #endif
123+ if (exename) {
124+ const std::string exepath (Path::fromNativeSeparators (Path::getPathFromFilename (Path::getCurrentExecutablePath (exename))));
125+ cfgfolders.push_back (exepath + " cfg" );
126+ cfgfolders.push_back (exepath + " ../cfg" );
127+ cfgfolders.push_back (exepath);
128+ }
123129
124- while (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND && !cfgfolders.empty ()) {
125- const std::string cfgfolder (cfgfolders.back ());
126- cfgfolders.pop_back ();
127- const char *sep = (!cfgfolder.empty () && endsWith (cfgfolder,' /' ) ? " " : " /" );
128- const std::string filename (cfgfolder + sep + fullfilename);
129- if (debug)
130- std::cout << " looking for library '" + std::string (filename) + " '" << std::endl;
131- error = doc.LoadFile (filename.c_str ());
132- if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)
133- absolute_path = Path::getAbsoluteFilePath (filename);
130+ while (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND && !cfgfolders.empty ()) {
131+ const std::string cfgfolder (cfgfolders.back ());
132+ cfgfolders.pop_back ();
133+ const char *sep = (!cfgfolder.empty () && endsWith (cfgfolder,' /' ) ? " " : " /" );
134+ const std::string filename (cfgfolder + sep + fullfilename);
135+ if (debug)
136+ std::cout << " looking for library '" + std::string (filename) + " '" << std::endl;
137+ error = doc.LoadFile (filename.c_str ());
138+ if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)
139+ absolute_path = Path::getAbsoluteFilePath (filename);
140+ }
134141 }
135142 } else
136143 absolute_path = Path::getAbsoluteFilePath (path);
0 commit comments