Harden drawing sheet loading slightly...
The fact it blindly assumed it would always work makes me sad :( So this is just ducktape
This commit is contained in:
parent
18ff8ea4a0
commit
cc1bfd4c18
|
@ -808,7 +808,7 @@ void DS_DATA_MODEL::SetPageLayout( const char* aPageLayout, bool Append, const w
|
|||
}
|
||||
|
||||
|
||||
void DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append )
|
||||
bool DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append )
|
||||
{
|
||||
wxString fullFileName = aFullFileName;
|
||||
|
||||
|
@ -824,7 +824,7 @@ void DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append
|
|||
wxLogMessage( wxT( "Drawing sheet file <%s> not found" ), fullFileName.GetData() );
|
||||
#endif
|
||||
SetDefaultLayout();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -834,14 +834,17 @@ void DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append
|
|||
{
|
||||
if( !Append )
|
||||
SetDefaultLayout();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t filelen = wksFile.Length();
|
||||
char * buffer = new char[filelen+10];
|
||||
std::unique_ptr<char[]> buffer = std::make_unique<char[]>(filelen+10);
|
||||
|
||||
if( wksFile.Read( buffer, filelen ) != filelen )
|
||||
wxLogMessage( _("The file \"%s\" was not fully read"), fullFileName.GetData() );
|
||||
if( wksFile.Read( buffer.get(), filelen ) != filelen )
|
||||
{
|
||||
wxLogMessage( _( "The file \"%s\" was not fully read" ), fullFileName.GetData() );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[filelen]=0;
|
||||
|
@ -849,7 +852,7 @@ void DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append
|
|||
if( ! Append )
|
||||
ClearList();
|
||||
|
||||
DRAWING_SHEET_READER_PARSER pl_parser( buffer, fullFileName );
|
||||
DRAWING_SHEET_READER_PARSER pl_parser( buffer.get(), fullFileName );
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -858,8 +861,14 @@ void DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append
|
|||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
wxLogMessage( ioe.What() );
|
||||
return false;
|
||||
}
|
||||
catch( const std::bad_alloc& )
|
||||
{
|
||||
wxLogMessage( "Memory exhaustion reading drawing sheet" );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ public:
|
|||
* default internal description.
|
||||
* @param Append if true: do not delete old layout, and load only \a aFullFileName.
|
||||
*/
|
||||
void LoadDrawingSheet( const wxString& aFullFileName = wxEmptyString, bool Append = false );
|
||||
bool LoadDrawingSheet( const wxString& aFullFileName = wxEmptyString, bool Append = false );
|
||||
|
||||
/**
|
||||
* Populate the list from a S expr description stored in a string.
|
||||
|
|
|
@ -223,7 +223,16 @@ bool PL_EDITOR_FRAME::LoadPageLayoutDescrFile( const wxString& aFullFileName )
|
|||
{
|
||||
if( wxFileExists( aFullFileName ) )
|
||||
{
|
||||
DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( aFullFileName );
|
||||
bool loaded = false;
|
||||
|
||||
loaded = DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( aFullFileName );
|
||||
|
||||
if( !loaded )
|
||||
{
|
||||
ShowInfoBarError( _( "Error reading drawing sheet" ), true );
|
||||
return false;
|
||||
}
|
||||
|
||||
SetCurrentFileName( aFullFileName );
|
||||
UpdateFileHistory( aFullFileName );
|
||||
GetScreen()->ClrModify();
|
||||
|
@ -233,9 +242,7 @@ bool PL_EDITOR_FRAME::LoadPageLayoutDescrFile( const wxString& aFullFileName )
|
|||
|
||||
if( fn.FileExists() && !fn.IsFileWritable() )
|
||||
{
|
||||
m_infoBar->RemoveAllButtons();
|
||||
m_infoBar->AddCloseButton();
|
||||
m_infoBar->ShowMessage( _( "Layout file is read only." ), wxICON_WARNING );
|
||||
ShowInfoBarWarning( _( "Layout file is read only." ), true );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue