Let TinyXML2 handle fopen/fclose. Added testlibrary.cpp to VS10 solution

This commit is contained in:
PKEuS 2013-10-27 17:32:38 +01:00
parent e0244d343d
commit bd752cabcf
3 changed files with 10 additions and 11 deletions

View File

@ -43,29 +43,24 @@ bool Library::load(const char exename[], const char path[])
}
// open file..
FILE *fp = fopen(path, "rb");
if (fp == NULL) {
tinyxml2::XMLDocument doc;
tinyxml2::XMLError error = doc.LoadFile(path);
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
// failed to open file.. is there no extension?
std::string fullfilename(path);
if (Path::getFilenameExtension(fullfilename) == "") {
fullfilename += ".cfg";
fp = fopen(fullfilename.c_str(), "rb");
error = doc.LoadFile(fullfilename.c_str());
}
if (fp==NULL) {
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
// Try to locate the library configuration in the installation folder..
const std::string installfolder = Path::fromNativeSeparators(Path::getPathFromFilename(exename));
const std::string filename = installfolder + "cfg/" + fullfilename;
fp = fopen(filename.c_str(), "rb");
error = doc.LoadFile(filename.c_str());
}
if (fp == NULL)
return false;
}
tinyxml2::XMLDocument doc;
const tinyxml2::XMLError error = doc.LoadFile(fp);
fclose(fp);
return (error != tinyxml2::XML_NO_ERROR) && load(doc);
}

View File

@ -50,6 +50,7 @@
<ClCompile Include="testinternal.cpp" />
<ClCompile Include="testio.cpp" />
<ClCompile Include="testleakautovar.cpp" />
<ClCompile Include="testlibrary.cpp" />
<ClCompile Include="testmathlib.cpp" />
<ClCompile Include="testmemleak.cpp" />
<ClCompile Include="testnonreentrantfunctions.cpp" />

View File

@ -175,6 +175,9 @@
<ClCompile Include="testassert.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="testlibrary.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="options.h">