Преглед изворни кода

Allow tiny xml to load files with unicode paths

Scott Brogden пре 4 година
родитељ
комит
4b718e185d
4 измењених фајлова са 25 додато и 31 уклоњено
  1. 3 5
      MultiLanguage.cpp
  2. 2 4
      Theme.cpp
  3. 16 18
      TinyXml/tinyxml.cpp
  4. 4 4
      TinyXml/tinyxml.h

+ 3 - 5
MultiLanguage.cpp

@@ -1,4 +1,4 @@
-// MultiLanguage.cpp: implementation of the CMultiLanguage class.
+// MultiLanguage.cpp: implementation of the CMultiLanguage class.
 //
 //////////////////////////////////////////////////////////////////////
 
@@ -354,10 +354,8 @@ bool CMultiLanguage::LoadLanguageFile(CString csFile)
 		return false;
 	}
 
-	CStringA csPathA = CTextConvert::UnicodeToAnsi(csPath);
-
-	TiXmlDocument doc(csPathA);
-	if(!doc.LoadFile())
+	TiXmlDocument doc;
+	if(!doc.LoadFile(csPath.GetBuffer()))
 	{
 		m_csLastError.Format(_T("Error loading file %s - reason = %s, Line: %d, column: %d"), csFile, CTextConvert::AnsiToUnicode(doc.ErrorDesc()), doc.ErrorRow(), doc.ErrorCol());
 		Log(m_csLastError);

+ 2 - 4
Theme.cpp

@@ -119,10 +119,8 @@ bool CTheme::Load(CString csTheme, bool bHeaderOnly, bool bCheckLastWriteTime)
 
 	Log(StrF(_T("Loading Theme %s"), csPath));
 
-	CStringA csPathA = CTextConvert::UnicodeToAnsi(csPath);
-
-	TiXmlDocument doc(csPathA);
-	if(!doc.LoadFile())
+	TiXmlDocument doc;
+	if(!doc.LoadFile(csPath.GetBuffer()))
 	{
 		m_csLastError.Format(_T("Error loading Theme %s - reason = %s"), csPath, doc.ErrorDesc());
 		ASSERT(!m_csLastError);

+ 16 - 18
TinyXml/tinyxml.cpp

@@ -31,16 +31,16 @@ distribution.
 
 #include "tinyxml.h"
 
-FILE* TiXmlFOpen( const char* filename, const char* mode );
+FILE* TiXmlFOpen(wchar_t* filename, wchar_t* mode );
 
 bool TiXmlBase::condenseWhiteSpace = true;
 
 // Microsoft compiler security
-FILE* TiXmlFOpen( const char* filename, const char* mode )
+FILE* TiXmlFOpen(wchar_t* filename, wchar_t* mode )
 {
 	#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
 		FILE* fp = 0;
-		errno_t err = fopen_s( &fp, filename, mode );
+		errno_t err = _wfopen_s( &fp, filename, mode );
 		if ( !err && fp )
 			return fp;
 		return 0;
@@ -951,24 +951,22 @@ TiXmlDocument& TiXmlDocument::operator=( const TiXmlDocument& copy )
 }
 
 
-bool TiXmlDocument::LoadFile( TiXmlEncoding encoding )
-{
-	return LoadFile( Value(), encoding );
-}
+//bool TiXmlDocument::LoadFile( TiXmlEncoding encoding )
+//{
+//	return false;
+//	//return LoadFile( Value(), encoding );
+//}
 
 
-bool TiXmlDocument::SaveFile() const
-{
-	return SaveFile( Value() );
-}
+//bool TiXmlDocument::SaveFile() const
+//{
+//	return SaveFile( Value() );
+//}
 
-bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding )
+bool TiXmlDocument::LoadFile(wchar_t* _filename, TiXmlEncoding encoding )
 {
-	TIXML_STRING filename( _filename );
-	value = filename;
-
 	// reading in binary mode so that tinyxml can normalize the EOL
-	FILE* file = TiXmlFOpen( value.c_str (), "rb" );	
+	FILE* file = TiXmlFOpen( _filename, L"rb" );	
 
 	if ( file )
 	{
@@ -1081,10 +1079,10 @@ bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding )
 }
 
 
-bool TiXmlDocument::SaveFile( const char * filename ) const
+bool TiXmlDocument::SaveFile(wchar_t* filename ) const
 {
 	// The old c stuff lives on...
-	FILE* fp = TiXmlFOpen( filename, "w" );
+	FILE* fp = TiXmlFOpen( filename, L"w" );
 	if ( fp )
 	{
 		bool result = SaveFile( fp );

+ 4 - 4
TinyXml/tinyxml.h

@@ -1412,13 +1412,13 @@ public:
 		Returns true if successful. Will delete any existing
 		document data before loading.
 	*/
-	bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
+	//bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
 	/// Save a file using the current document value. Returns true if successful.
-	bool SaveFile() const;
+	//bool SaveFile() const;
 	/// Load a file using the given filename. Returns true if successful.
-	bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
+	bool LoadFile(wchar_t* filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
 	/// Save a file using the given filename. Returns true if successful.
-	bool SaveFile( const char * filename ) const;
+	bool SaveFile(wchar_t* filename ) const;
 	/** Load a file using the given FILE*. Returns true if successful. Note that this method
 		doesn't stream - the entire object pointed at by the FILE*
 		will be interpreted as an XML file. TinyXML doesn't stream in XML from the current