From 7f7b162b6f0ef7157a265bf81952281306989014 Mon Sep 17 00:00:00 2001 From: Lee Thomason Date: Sat, 24 Mar 2012 12:49:03 -0700 Subject: [PATCH] Add warning for the working directory. Verify win64 fix. --- tinyxml2.cpp | 11 ++++++++--- tinyxml2.h | 7 ++++--- xmltest.cpp | 23 +++++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 8ee8ca2..5e5b93d 100644 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1408,9 +1408,14 @@ void XMLDocument::SaveFile( const char* filename ) #if defined(_MSC_VER) #pragma warning ( pop ) #endif - XMLPrinter stream( fp ); - Print( &stream ); - fclose( fp ); + if ( fp ) { + XMLPrinter stream( fp ); + Print( &stream ); + fclose( fp ); + } + else { + SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 ); + } } diff --git a/tinyxml2.h b/tinyxml2.h index 38168f2..6f3828c 100644 --- a/tinyxml2.h +++ b/tinyxml2.h @@ -93,9 +93,9 @@ distribution. #define TIXML_SSCANF sscanf #endif -static const int TIXML2_MAJOR_VERSION = 0; -static const int TIXML2_MINOR_VERSION = 9; -static const int TIXML2_PATCH_VERSION = 1; +static const int TIXML2_MAJOR_VERSION = 0; +static const int TIXML2_MINOR_VERSION = 9; +static const int TIXML2_PATCH_VERSION = 1; namespace tinyxml2 { @@ -736,6 +736,7 @@ enum { XML_WRONG_ATTRIBUTE_TYPE, XML_ERROR_FILE_NOT_FOUND, + XML_ERROR_FILE_COULD_NOT_BE_OPENED, XML_ERROR_ELEMENT_MISMATCH, XML_ERROR_PARSING_ELEMENT, XML_ERROR_PARSING_ATTRIBUTE, diff --git a/xmltest.cpp b/xmltest.cpp index 8fc3cfb..93b5599 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -77,6 +77,29 @@ int main( int /*argc*/, const char ** /*argv*/ ) _CrtMemCheckpoint( &startMemState ); #endif + #if defined(_MSC_VER) + #pragma warning ( push ) + #pragma warning ( disable : 4996 ) // Fail to see a compelling reason why this should be deprecated. + #endif + + FILE* fp = fopen( "dream.xml", "r" ); + if ( !fp ) { + printf( "Error opening test file 'dream.xml'.\n" + "Is your working directory the same as where \n" + "the xmltest.cpp and dream.xml file are?\n\n" + #if defined( _MSC_VER ) + "In windows Visual Studio you may need to set\n" + "Properties->Debugging->Working Directory to '..'\n" + #endif + ); + exit( 1 ); + } + fclose( fp ); + + #if defined(_MSC_VER) + #pragma warning ( pop ) + #endif + /* ------ Example 1: Load and parse an XML file. ---- */ { XMLDocument doc;