Temporary fix for #5263 until tinyxml2 handle folders better. When https://github.com/leethomason/tinyxml2/issues/147 is fixed this should be reverted.
This commit is contained in:
parent
a3a8edc00d
commit
ef3d3f2d40
|
@ -26,6 +26,21 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
static tinyxml2::XMLError LoadFile(tinyxml2::XMLDocument &doc, const std::string &path)
|
||||||
|
{
|
||||||
|
FILE *f = fopen(path.c_str(),"rb");
|
||||||
|
if (!f)
|
||||||
|
return tinyxml2::XML_ERROR_FILE_NOT_FOUND;
|
||||||
|
|
||||||
|
// is file ok? if "path" is a folder then reading from it will cause ferror() to return a non-zero value
|
||||||
|
fgetc(f);
|
||||||
|
int errorcode = ferror(f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
// if file is ok, try to load it
|
||||||
|
return (errorcode == 0) ? doc.LoadFile(path.c_str()) : tinyxml2::XML_ERROR_FILE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
Library::Library() : allocid(0)
|
Library::Library() : allocid(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -47,13 +62,13 @@ bool Library::load(const char exename[], const char path[])
|
||||||
|
|
||||||
// open file..
|
// open file..
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
tinyxml2::XMLError error = doc.LoadFile(path);
|
tinyxml2::XMLError error = LoadFile(doc,path);
|
||||||
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
|
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
|
||||||
// failed to open file.. is there no extension?
|
// failed to open file.. is there no extension?
|
||||||
std::string fullfilename(path);
|
std::string fullfilename(path);
|
||||||
if (Path::getFilenameExtension(fullfilename) == "") {
|
if (Path::getFilenameExtension(fullfilename) == "") {
|
||||||
fullfilename += ".cfg";
|
fullfilename += ".cfg";
|
||||||
error = doc.LoadFile(fullfilename.c_str());
|
error = LoadFile(doc,fullfilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
|
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
|
||||||
|
@ -65,7 +80,7 @@ bool Library::load(const char exename[], const char path[])
|
||||||
#endif
|
#endif
|
||||||
const char *sep = (!cfgfolder.empty() && cfgfolder[cfgfolder.size()-1U]=='/' ? "" : "/");
|
const char *sep = (!cfgfolder.empty() && cfgfolder[cfgfolder.size()-1U]=='/' ? "" : "/");
|
||||||
const std::string filename(cfgfolder + sep + fullfilename);
|
const std::string filename(cfgfolder + sep + fullfilename);
|
||||||
error = doc.LoadFile(filename.c_str());
|
error = LoadFile(doc,filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue