Use wxFFileInputStream explicitly when loading xml documents

wxFFile (FILE, buffered) is better than wxFile (syscalls)
This commit is contained in:
Marek Roszko 2021-05-03 19:39:56 -04:00
parent 8c2f07be2a
commit c7345096f8
3 changed files with 18 additions and 11 deletions

View File

@ -31,6 +31,7 @@
#include <memory>
#include <wx/filename.h>
#include <wx/tokenzr.h>
#include <wx/wfstream.h>
#include <class_library.h>
#include <plugins/eagle/eagle_parser.h>
@ -394,13 +395,14 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchema
wxASSERT( !aFileName || aSchematic != nullptr );
LOCALE_IO toggle; // toggles on, then off, the C locale.
// Load the document
wxXmlDocument xmlDocument;
m_filename = aFileName;
m_filename = aFileName;
m_schematic = aSchematic;
if( !xmlDocument.Load( m_filename.GetFullPath() ) )
// Load the document
wxXmlDocument xmlDocument;
wxFFileInputStream stream( m_filename.GetFullPath() );
if( !stream.IsOk() || !xmlDocument.Load( stream ) )
{
THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
m_filename.GetFullPath() ) );

View File

@ -55,6 +55,7 @@ Load() TODO's
#include <wx/string.h>
#include <wx/xml/xml.h>
#include <wx/filename.h>
#include <wx/wfstream.h>
#include <convert_basic_shapes_to_polygon.h>
#include <core/arraydim.h>
@ -327,11 +328,12 @@ BOARD* EAGLE_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe,
try
{
// Load the document
wxXmlDocument xmlDocument;
wxFileName fn = aFileName;
// Load the document
wxFFileInputStream stream( fn.GetFullPath() );
wxXmlDocument xmlDocument;
if( !xmlDocument.Load( fn.GetFullPath() ) )
if( !stream.IsOk() || !xmlDocument.Load( stream ) )
{
THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
fn.GetFullPath() ) );
@ -2772,10 +2774,11 @@ void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath )
string filename = (const char*) aLibPath.char_str( wxConvFile );
// Load the document
wxXmlDocument xmlDocument;
wxFileName fn( filename );
wxFFileInputStream stream( fn.GetFullPath() );
wxXmlDocument xmlDocument;
if( !xmlDocument.Load( fn.GetFullPath() ) )
if( !stream.IsOk() || !xmlDocument.Load( stream ) )
THROW_IO_ERROR( wxString::Format( _( "Unable to read file \"%s\"" ),
fn.GetFullPath() ) );

View File

@ -33,6 +33,7 @@
#include <vector>
#include <wx/tokenzr.h>
#include <wx/wfstream.h>
#include <iostream>
#include "x3d.h"
@ -43,9 +44,10 @@
SCENEGRAPH* X3DPARSER::Load( const wxString& aFileName )
{
wxFFileInputStream stream( aFileName );
wxXmlDocument doc;
if( !doc.Load( aFileName ) )
if( !stream.IsOk() || !doc.Load( stream ) )
return NULL;
if( doc.GetRoot()->GetName() != wxT( "X3D" ) )