From bd752cabcfd479c6038e0115c5e58d466548b647 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 27 Oct 2013 17:32:38 +0100 Subject: [PATCH] Let TinyXML2 handle fopen/fclose. Added testlibrary.cpp to VS10 solution --- lib/library.cpp | 17 ++++++----------- test/testrunner.vcxproj | 1 + test/testrunner.vcxproj.filters | 3 +++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index 321d82aed..d3830c812 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -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); } diff --git a/test/testrunner.vcxproj b/test/testrunner.vcxproj index 7d0129584..5bec52eac 100644 --- a/test/testrunner.vcxproj +++ b/test/testrunner.vcxproj @@ -50,6 +50,7 @@ + diff --git a/test/testrunner.vcxproj.filters b/test/testrunner.vcxproj.filters index 7b0dd0123..84bcb129d 100644 --- a/test/testrunner.vcxproj.filters +++ b/test/testrunner.vcxproj.filters @@ -175,6 +175,9 @@ Source Files + + Source Files +