Improved support for large files

This commit is contained in:
Zane U. Ji 2013-10-29 18:52:22 +08:00
parent d9a84f61d2
commit 9eee9ccdf9
3 changed files with 82 additions and 69 deletions

View File

@ -34,6 +34,7 @@ void *ValidationThread::Entry()
if ( TestDestroy() ) if ( TestDestroy() )
{ {
myBuffer.clear();
return NULL; return NULL;
} }
@ -43,6 +44,8 @@ void *ValidationThread::Entry()
mySystem, mySystem,
this ); this );
myBuffer.clear();
if ( TestDestroy() ) if ( TestDestroy() )
{ {
return NULL; return NULL;

View File

@ -62,6 +62,7 @@
#include <wx/dir.h> #include <wx/dir.h>
#include "xmlschemagenerator.h" #include "xmlschemagenerator.h"
#include "threadreaper.h" #include "threadreaper.h"
#include <wx/wupdlock.h>
#define ngettext wxGetTranslation #define ngettext wxGetTranslation
@ -2926,30 +2927,32 @@ void MyFrame::newDocument ( const std::string& s, const wxString& path, bool can
wxString auxPath = getAuxPath ( path ); wxString auxPath = getAuxPath ( path );
Freeze(); {
doc = ( s.empty() ) ? wxWindowUpdateLocker noupdate (this);
new XmlDoc (
mainBook, doc = ( s.empty() ) ?
properties, new XmlDoc (
&protectTags, mainBook,
visibilityState, properties,
FILE_TYPE_XML, &protectTags,
wxID_ANY, visibilityState,
NULL, 0 // new: NULL pointer leads to default document FILE_TYPE_XML,
) wxID_ANY,
: new XmlDoc ( NULL, 0 // new: NULL pointer leads to default document
mainBook, )
properties, : new XmlDoc (
&protectTags, mainBook,
visibilityState, properties,
FILE_TYPE_XML, &protectTags,
wxID_ANY, visibilityState,
s.c_str(), // modified FILE_TYPE_XML,
s.size(), // new wxID_ANY,
path, s.c_str(), // modified
auxPath ); s.size(), // new
mainBook->AddPage ( ( wxWindow * ) doc, documentLabel ); path,
Thaw(); auxPath );
mainBook->AddPage ( ( wxWindow * ) doc, documentLabel );
}
mainBook->Layout(); mainBook->Layout();
@ -3061,25 +3064,21 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
bool fileEmpty = false; bool fileEmpty = false;
statusProgress ( _T ( "Opening file..." ) ); statusProgress ( _T ( "Opening file..." ) );
//wxMemoryMappedFile *memorymap = NULL; BinaryFile binaryfile ( fileName );
BinaryFile *binaryfile = NULL; if ( !binaryfile.getData() )
binaryfile = new BinaryFile ( fileName );
if ( !binaryfile->getData() )
{ {
wxString message; wxString message;
message.Printf ( _ ( "Cannot open %s" ), fileName.c_str() ); message.Printf ( _ ( "Cannot open %s" ), fileName.c_str() );
messagePane ( message, CONST_STOP ); messagePane ( message, CONST_STOP );
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
delete binaryfile;
return false; return false;
} }
/* /*
memorymap = new wxMemoryMappedFile( //wxMemoryMappedFile memorymap (
fileName, fileName,
true, // readOnly true, // readOnly
true // fread true // fread
); );
*/ */
/* /*
@ -3093,8 +3092,8 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
if ( !fileEmpty ) if ( !fileEmpty )
{ {
docBuffer = ( char * ) binaryfile->getData();//memorymap->GetStream(); docBuffer = ( char * ) binaryfile.getData();//memorymap->GetStream();
docBufferLen = binaryfile->getDataLen();//memorymap->GetMapSize(); docBufferLen = binaryfile.getDataLen();//memorymap->GetMapSize();
} }
else else
{ {
@ -3112,7 +3111,11 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
size_t finalBufferLen; size_t finalBufferLen;
std::string encoding; std::string encoding;
if ( docBufferLen >= 4 && // UTF-32 BE if ( largeFile )
{
encoding = "UTF-8";
}
else if ( docBufferLen >= 4 && // UTF-32 BE
( unsigned char ) docBuffer[0] == 0x00 && ( unsigned char ) docBuffer[0] == 0x00 &&
( unsigned char ) docBuffer[1] == 0x00 && ( unsigned char ) docBuffer[1] == 0x00 &&
( unsigned char ) docBuffer[2] == 0xFE && ( unsigned char ) docBuffer[2] == 0xFE &&
@ -3192,7 +3195,6 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
fileName.c_str(), fileName.c_str(),
wideEncoding.c_str() ); wideEncoding.c_str() );
messagePane ( message, CONST_STOP ); messagePane ( message, CONST_STOP );
delete binaryfile;//memorymap;
return false; return false;
}; };
@ -3216,7 +3218,16 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
size_t iconvBufferLeft, docBufferLeft; size_t iconvBufferLeft, docBufferLeft;
iconvBufferLen = iconvBufferLeft = docBufferLen * iconvLenMultiplier + 1; iconvBufferLen = iconvBufferLeft = docBufferLen * iconvLenMultiplier + 1;
docBufferLeft = docBufferLen; docBufferLeft = docBufferLen;
iconvBuffer.extend ( iconvBufferLen ); if ( ( ( ( size_t ) -1 ) - 1 ) / iconvLenMultiplier < docBufferLen
|| !iconvBuffer.extend ( iconvBufferLen ) )
{
wxString message;
message.Printf ( _ ( "Cannot open %s: out of memory" ),
fileName.c_str() );
messagePane ( message, CONST_STOP );
statusProgress ( wxEmptyString );
return false;
}
finalBuffer = buffer = iconvBuffer.data(); // buffer will be incremented by iconv finalBuffer = buffer = iconvBuffer.data(); // buffer will be incremented by iconv
nconv = reinterpret_cast < universal_iconv & > ( iconv ) ( nconv = reinterpret_cast < universal_iconv & > ( iconv ) (
cd, cd,
@ -3236,41 +3247,42 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
fileName.c_str(), fileName.c_str(),
wideEncoding.c_str() ); wideEncoding.c_str() );
messagePane ( message, CONST_STOP ); messagePane ( message, CONST_STOP );
delete binaryfile; //delete memorymap;
return false; return false;
} }
finalBufferLen = iconvBufferLen - iconvBufferLeft; finalBufferLen = iconvBufferLen - iconvBufferLeft;
} }
statusProgress ( _ ( "Creating document view..." ) ); statusProgress ( _ ( "Creating document view..." ) );
Freeze(); {
doc = new XmlDoc ( wxWindowUpdateLocker noupdate ( this );
mainBook,
( largeFile ) ? largeFileProperties: properties, doc = new XmlDoc (
&protectTags, mainBook,
visibilityState, ( largeFile ) ? largeFileProperties: properties,
( !binaryfile->getDataLen() ) ? FILE_TYPE_XML : type, &protectTags,
wxID_ANY, visibilityState,
finalBuffer, ( !binaryfile.getDataLen() ) ? FILE_TYPE_XML : type,
finalBufferLen, wxID_ANY,
fileName, finalBuffer,
auxPath ); finalBufferLen,
fileName,
auxPath );
#ifdef __WXMSW__ #ifdef __WXMSW__
doc->SetUndoCollection ( false ); doc->SetUndoCollection ( false );
doc->SetUndoCollection ( true ); doc->SetUndoCollection ( true );
#endif #endif
doc->setFullFileName ( fileName ); doc->setFullFileName ( fileName );
doc->setShortFileName ( name ); doc->setShortFileName ( name );
doc->setDirectory ( directory ); doc->setDirectory ( directory );
openFileSet.insert ( fileName ); openFileSet.insert ( fileName );
history.AddFileToHistory ( fileName ); history.AddFileToHistory ( fileName );
updateFileMenu(); updateFileMenu();
wxFileName ofn ( fileName ); wxFileName ofn ( fileName );
doc->setLastModified ( ofn.GetModificationTime() ); doc->setLastModified ( ofn.GetModificationTime() );
mainBook->AddPage ( ( wxWindow * ) doc, name, _T ( "" ) ); mainBook->AddPage ( ( wxWindow * ) doc, name, _T ( "" ) );
Thaw(); }
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
mainBook->Layout(); mainBook->Layout();
@ -3279,9 +3291,8 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
doc->setLastModified ( fn.GetModificationTime() ); doc->setLastModified ( fn.GetModificationTime() );
doc->SetFocus(); doc->SetFocus();
if ( type != FILE_TYPE_XML || !binaryfile->getDataLen() ) if ( type != FILE_TYPE_XML || !binaryfile.getDataLen() )
{ {
delete binaryfile;//memorymap;
return true; return true;
} }
@ -3346,7 +3357,6 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
{ {
closePane(); closePane();
} }
delete binaryfile; //delete memorymap;
return true; return true;
} }

View File

@ -76,6 +76,7 @@ XmlCtrl::XmlCtrl (
currentMaxLine = 1; currentMaxLine = 1;
applyProperties ( propertiesParameter ); applyProperties ( propertiesParameter );
applyVisibilityState ( visibilityState );
SetTabWidth ( 2 ); SetTabWidth ( 2 );
SetWrapStartIndent ( 2 ); SetWrapStartIndent ( 2 );
@ -118,7 +119,6 @@ XmlCtrl::XmlCtrl (
SetUndoCollection ( true ); SetUndoCollection ( true );
AutoCompSetSeparator ( '<' ); AutoCompSetSeparator ( '<' );
applyVisibilityState ( visibilityState );
lineBackgroundState = BACKGROUND_STATE_NORMAL; lineBackgroundState = BACKGROUND_STATE_NORMAL;
for ( int i = 0; i < wxSTC_INDIC_MAX; ++i ) for ( int i = 0; i < wxSTC_INDIC_MAX; ++i )