[BUG_FIXED] Fix nativeLang loading problem if Notepad++ location path contains Unicode characters.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@376 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
56e1ac8939
commit
6e4a80da18
@ -687,26 +687,9 @@ bool NppParameters::load()
|
|||||||
PathAppend(nativeLangPath, TEXT("nativeLang.xml"));
|
PathAppend(nativeLangPath, TEXT("nativeLang.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
_pXmlNativeLangDocA = new TiXmlDocumentA();
|
||||||
_pXmlNativeLangDoc = new TiXmlDocument(nativeLangPath);
|
|
||||||
loadOkay = _pXmlNativeLangDoc->LoadFile();
|
|
||||||
if (!loadOkay)
|
|
||||||
{
|
|
||||||
delete _pXmlNativeLangDoc;
|
|
||||||
_pXmlNativeLangDoc = NULL;
|
|
||||||
isAllLaoded = false;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef UNICODE
|
loadOkay = _pXmlNativeLangDocA->LoadUnicodeFilePath(nativeLangPath);
|
||||||
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
|
|
||||||
const char * nativeLangPathA = wmc->wchar2char(nativeLangPath, CP_ANSI_LATIN_1);
|
|
||||||
_pXmlNativeLangDocA = new TiXmlDocumentA(nativeLangPathA);
|
|
||||||
#else
|
|
||||||
_pXmlNativeLangDocA = new TiXmlDocumentA(nativeLangPath);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
loadOkay = _pXmlNativeLangDocA->LoadFile();
|
|
||||||
if (!loadOkay)
|
if (!loadOkay)
|
||||||
{
|
{
|
||||||
delete _pXmlNativeLangDocA;
|
delete _pXmlNativeLangDocA;
|
||||||
|
@ -755,6 +755,64 @@ bool TiXmlDocumentA::LoadFile( const char* filename )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TiXmlDocumentA::LoadUnicodeFilePath( const TCHAR* filename )
|
||||||
|
{
|
||||||
|
|
||||||
|
// Delete the existing data:
|
||||||
|
Clear();
|
||||||
|
location.Clear();
|
||||||
|
|
||||||
|
// There was a really terrifying little bug here. The code:
|
||||||
|
// value = filename
|
||||||
|
// in the STL case, cause the assignment method of the std::generic_string to
|
||||||
|
// be called. What is strange, is that the std::generic_string had the same
|
||||||
|
// address as it's c_str() method, and so bad things happen. Looks
|
||||||
|
// like a bug in the Microsoft STL implementation.
|
||||||
|
// See STL_STRING_BUG above.
|
||||||
|
// Fixed with the StringToBuffer class.
|
||||||
|
|
||||||
|
FILE* file = generic_fopen(filename, TEXT("r"));
|
||||||
|
|
||||||
|
if ( file )
|
||||||
|
{
|
||||||
|
// Get the file size, so we can pre-allocate the generic_string. HUGE speed impact.
|
||||||
|
long length = 0;
|
||||||
|
fseek( file, 0, SEEK_END );
|
||||||
|
length = ftell( file );
|
||||||
|
fseek( file, 0, SEEK_SET );
|
||||||
|
|
||||||
|
// Strange case, but good to handle up front.
|
||||||
|
if ( length == 0 )
|
||||||
|
{
|
||||||
|
fclose( file );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have a file, assume it is all one big XML file, and read it in.
|
||||||
|
// The document parser may decide the document ends sooner than the entire file, however.
|
||||||
|
TIXMLA_STRING data;
|
||||||
|
data.reserve( length );
|
||||||
|
|
||||||
|
const int BUF_SIZE = 2048;
|
||||||
|
char buf[BUF_SIZE];
|
||||||
|
|
||||||
|
while( fgets( buf, BUF_SIZE, file ) )
|
||||||
|
{
|
||||||
|
data += buf;
|
||||||
|
}
|
||||||
|
fclose( file );
|
||||||
|
|
||||||
|
Parse( data.c_str(), 0 );
|
||||||
|
|
||||||
|
if ( Error() )
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
SetError( TIXMLA_ERROR_OPENING_FILE, 0, 0 );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool TiXmlDocumentA::SaveFile( const char * filename ) const
|
bool TiXmlDocumentA::SaveFile( const char * filename ) const
|
||||||
{
|
{
|
||||||
// The old c stuff lives on...
|
// The old c stuff lives on...
|
||||||
|
@ -36,6 +36,8 @@ distribution.
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include "Common.h"
|
||||||
|
|
||||||
// Help out windows:
|
// Help out windows:
|
||||||
#if defined( _DEBUG ) && !defined( DEBUG )
|
#if defined( _DEBUG ) && !defined( DEBUG )
|
||||||
@ -1012,6 +1014,8 @@ public:
|
|||||||
/// Save a file using the given filename. Returns true if successful.
|
/// Save a file using the given filename. Returns true if successful.
|
||||||
bool SaveFile( const char * filename ) const;
|
bool SaveFile( const char * filename ) const;
|
||||||
|
|
||||||
|
bool LoadUnicodeFilePath(const TCHAR* filename);
|
||||||
|
|
||||||
#ifdef TIXMLA_USE_STL
|
#ifdef TIXMLA_USE_STL
|
||||||
bool LoadFile( const std::string& filename ) ///< STL std::string version.
|
bool LoadFile( const std::string& filename ) ///< STL std::string version.
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user