Replace wxFile usage with wxFFile

Buffered libc wxFFile is better thinking about syscall wxFile going wrong.
This commit is contained in:
Marek Roszko 2020-12-12 13:11:51 -05:00
parent dab254580a
commit d67cf2f9af
10 changed files with 30 additions and 22 deletions

View File

@ -27,6 +27,7 @@
#include <gal/color4d.h>
#include <wx/clipbrd.h>
#include <kicad_string.h>
#include <wx/ffile.h>
WX_HTML_REPORT_PANEL::WX_HTML_REPORT_PANEL( wxWindow* parent,
wxWindowID id,
@ -335,7 +336,7 @@ void WX_HTML_REPORT_PANEL::onBtnSaveToFile( wxCommandEvent& event )
if( fn.GetExt().IsEmpty() )
fn.SetExt( "txt" );
wxFile f( fn.GetFullPath(), wxFile::write );
wxFFile f( fn.GetFullPath(), "wb" );
if( !f.IsOpened() )
{

View File

@ -335,7 +335,7 @@ void ReadHotKeyConfig( wxString fileName, std::map<std::string, int>& aHotKeys )
if( !wxFile::Exists( fileName ) )
return;
wxFile file( fileName, wxFile::OpenMode::read );
wxFFile file( fileName, "rb" );
if( !file.IsOpened() ) // There is a problem to open file
return;
@ -418,15 +418,13 @@ int ReadLegacyHotkeyConfigFile( const wxString& aFilename, std::map<std::string,
if( !wxFile::Exists( fn.GetFullPath() ) )
return 0;
wxFile cfgfile( fn.GetFullPath() );
wxFFile cfgfile( fn.GetFullPath(), "rb" );
if( !cfgfile.IsOpened() ) // There is a problem to open file
return 0;
// get length
cfgfile.SeekEnd();
wxFileOffset size = cfgfile.Tell();
cfgfile.Seek( 0 );
wxFileOffset size = cfgfile.Length();
// read data
std::vector<char> buffer( size );

View File

@ -36,6 +36,7 @@
#include <page_layout/ws_draw_item.h>
#include <page_layout/ws_painter.h>
#include <page_layout/page_layout_reader_lexer.h>
#include <wx/ffile.h>
#include <wx/file.h>
#include <wx/mstream.h>
@ -837,7 +838,7 @@ void WS_DATA_MODEL::SetPageLayout( const wxString& aFullFileName, bool Append )
}
}
wxFile wksFile( fullFileName );
wxFFile wksFile( fullFileName, "rb" );
if( ! wksFile.IsOpened() )
{

View File

@ -23,6 +23,7 @@
*/
#include "bom_plugins.h"
#include <wx/ffile.h>
BOM_GENERATOR_HANDLER::BOM_GENERATOR_HANDLER( const wxString& aFile )
: m_file( aFile )
@ -95,7 +96,7 @@ wxString BOM_GENERATOR_HANDLER::readHeader( const wxString& aEndSection )
if( aEndSection.IsEmpty() )
return wxEmptyString;
wxFile fdata( m_file.GetFullPath() ); // dtor will close the file
wxFFile fdata( m_file.GetFullPath(), "rb" ); // dtor will close the file
wxString data;
if( !fdata.ReadAll( &data ) )

View File

@ -43,6 +43,7 @@
#include <sexpr/sexpr_parser.h>
#include <kiface_ids.h>
#include <netlist_exporters/netlist_exporter_kicad.h>
#include <wx/ffile.h>
#include <schematic.h>
#include <connection_graph.h>
@ -377,12 +378,12 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProje
}
} );
wxFile destNetList( destFile.GetFullPath(), wxFile::write );
wxFFile destNetList( destFile.GetFullPath(), "wb" );
if( destNetList.IsOpened() )
success = destNetList.Write( sexpr->AsString( 0 ) );
// wxFile dtor will close the file
// wxFFile dtor will close the file
}
catch( ... )
{

View File

@ -57,6 +57,7 @@
#include <widgets/infobar.h>
#include <wildcards_and_files_ext.h>
#include <page_layout/ws_data_model.h>
#include <wx/ffile.h>
#include <wx/stdpaths.h>
#include <tools/ee_inspection_tool.h>
@ -927,9 +928,9 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
BASE_SCREEN::m_PageLayoutDescrFileName = "empty.kicad_wks";
wxFileName layoutfn( Prj().GetProjectPath(), BASE_SCREEN::m_PageLayoutDescrFileName );
wxFile layoutfile;
wxFFile layoutfile;
if( layoutfile.Create( layoutfn.GetFullPath() ) )
if( layoutfile.Open( layoutfn.GetFullPath(), "wb" ) )
{
layoutfile.Write( WS_DATA_MODEL::EmptyLayout() );
layoutfile.Close();

View File

@ -45,6 +45,7 @@
#include <tool/tool_manager.h>
#include <tools/ee_actions.h>
#include <eeschema_settings.h>
#include <wx/ffile.h>
SIM_PLOT_TYPE operator|( SIM_PLOT_TYPE aFirst, SIM_PLOT_TYPE aSecond )
{
@ -1099,7 +1100,7 @@ void SIM_PLOT_FRAME::menuSaveCsv( wxCommandEvent& event )
if( saveDlg.ShowModal() == wxID_CANCEL )
return;
wxFile out( saveDlg.GetPath(), wxFile::write );
wxFFile out( saveDlg.GetPath(), "wb" );
bool timeWritten = false;
for( const auto& t : CurrentPlot()->GetTraces() )

View File

@ -35,6 +35,7 @@
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <wildcards_and_files_ext.h>
#include <wx/ffile.h>
using json = nlohmann::json;
@ -207,12 +208,12 @@ void IFACE::SaveFileAs( const wxString& aProjectBasePath, const wxString& aProje
}
}
wxFile destJobFile( destFile.GetFullPath(), wxFile::write );
wxFFile destJobFile( destFile.GetFullPath(), "wb" );
if( destJobFile.IsOpened() )
success = destJobFile.Write( js.dump( 0 ) );
// wxFile dtor will close the file
// wxFFile dtor will close the file
}
catch( ... )
{

View File

@ -49,6 +49,8 @@
#include <tools/kicad_manager_control.h>
#include <wildcards_and_files_ext.h>
#include <widgets/app_progress_dialog.h>
#include <wx/ffile.h>
#ifdef __WXMAC__
#include <MacTypes.h>
@ -474,11 +476,11 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName,
if( !wxFileName::FileExists( srcFileName )
|| !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
{
wxFile file( destFileName.GetFullPath(), wxFile::write );
wxFFile file( destFileName.GetFullPath(), "wb" );
if( file.IsOpened() )
file.Write( wxT( "{\n}\n") );
// wxFile dtor will close the file
// wxFFile dtor will close the file
}
}
}
@ -494,7 +496,7 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName,
// If a <project>.kicad_sch file does not exist, create a "stub" file ( minimal schematic file )
if( !fn.FileExists() )
{
wxFile file( fn.GetFullPath(), wxFile::write );
wxFFile file( fn.GetFullPath(), "wb" );
if( file.IsOpened() )
file.Write( wxT( "(kicad_sch (version 20200310) (host eeschema \"unknown\")\n"
@ -502,7 +504,7 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName,
" (symbol_instances)\n)\n" ) );
// wxFile dtor will close the file
// wxFFile dtor will close the file
}
// If a <project>.kicad_pcb or <project>.brd file does not exist,
@ -513,12 +515,12 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName,
if( !fn.FileExists() && !leg_fn.FileExists() )
{
wxFile file( fn.GetFullPath(), wxFile::write );
wxFFile file( fn.GetFullPath(), "wb" );
if( file.IsOpened() )
file.Write( wxT( "(kicad_pcb (version 4) (host kicad \"dummy file\") )\n" ) );
// wxFile dtor will close the file
// wxFFile dtor will close the file
}
}

View File

@ -26,6 +26,7 @@
#include <fstream>
#include <streambuf>
#include <wx/file.h>
#include <wx/ffile.h>
#include <macros.h>
@ -62,7 +63,7 @@ namespace SEXPR
// the filename is not always a UTF7 string, so do not use ifstream
// that do not work with unicode chars.
wxString fname( FROM_UTF8( aFileName.c_str() ) );
wxFile file( fname );
wxFFile file( fname, "rb" );
size_t length = file.Length();
if( length <= 0 )