Let TinyXML2 handle fopen/fclose. Added testlibrary.cpp to VS10 solution
This commit is contained in:
parent
e0244d343d
commit
bd752cabcf
|
@ -43,29 +43,24 @@ bool Library::load(const char exename[], const char path[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// open file..
|
// open file..
|
||||||
FILE *fp = fopen(path, "rb");
|
tinyxml2::XMLDocument doc;
|
||||||
if (fp == NULL) {
|
tinyxml2::XMLError error = doc.LoadFile(path);
|
||||||
|
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";
|
||||||
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..
|
// Try to locate the library configuration in the installation folder..
|
||||||
const std::string installfolder = Path::fromNativeSeparators(Path::getPathFromFilename(exename));
|
const std::string installfolder = Path::fromNativeSeparators(Path::getPathFromFilename(exename));
|
||||||
const std::string filename = installfolder + "cfg/" + fullfilename;
|
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);
|
return (error != tinyxml2::XML_NO_ERROR) && load(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
<ClCompile Include="testinternal.cpp" />
|
<ClCompile Include="testinternal.cpp" />
|
||||||
<ClCompile Include="testio.cpp" />
|
<ClCompile Include="testio.cpp" />
|
||||||
<ClCompile Include="testleakautovar.cpp" />
|
<ClCompile Include="testleakautovar.cpp" />
|
||||||
|
<ClCompile Include="testlibrary.cpp" />
|
||||||
<ClCompile Include="testmathlib.cpp" />
|
<ClCompile Include="testmathlib.cpp" />
|
||||||
<ClCompile Include="testmemleak.cpp" />
|
<ClCompile Include="testmemleak.cpp" />
|
||||||
<ClCompile Include="testnonreentrantfunctions.cpp" />
|
<ClCompile Include="testnonreentrantfunctions.cpp" />
|
||||||
|
|
|
@ -175,6 +175,9 @@
|
||||||
<ClCompile Include="testassert.cpp">
|
<ClCompile Include="testassert.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="testlibrary.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="options.h">
|
<ClInclude Include="options.h">
|
||||||
|
|
Loading…
Reference in New Issue