more std iostream + Unicode fixes; copy streams in blocks of 4Kb, not char by char
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19065 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2171,77 +2171,99 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu)
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if wxUSE_STD_IOSTREAM
|
#if wxUSE_STD_IOSTREAM
|
||||||
|
|
||||||
bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream)
|
bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream)
|
||||||
{
|
{
|
||||||
FILE *fd1;
|
wxFFile file(filename, _T("rb"));
|
||||||
int ch;
|
if ( !file.IsOpened() )
|
||||||
|
|
||||||
if ((fd1 = wxFopen (filename.fn_str(), _T("rb"))) == NULL)
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
while ((ch = getc (fd1)) != EOF)
|
char buf[4096];
|
||||||
stream << (unsigned char)ch;
|
|
||||||
|
size_t nRead;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
nRead = file.Read(buf, WXSIZEOF(buf));
|
||||||
|
if ( file.Error() )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
stream.write(buf, nRead);
|
||||||
|
if ( !stream )
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
while ( !file.Eof() );
|
||||||
|
|
||||||
fclose (fd1);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename)
|
bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename)
|
||||||
{
|
{
|
||||||
FILE *fd1;
|
wxFFile file(filename, _T("wb"));
|
||||||
int ch;
|
if ( !file.IsOpened() )
|
||||||
|
|
||||||
if ((fd1 = wxFopen (filename.fn_str(), _T("wb"))) == NULL)
|
|
||||||
{
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
while (!stream.eof())
|
char buf[4096];
|
||||||
|
do
|
||||||
{
|
{
|
||||||
ch = stream.get();
|
stream.read(buf, WXSIZEOF(buf));
|
||||||
if (!stream.eof())
|
if ( !stream.bad() ) // fail may be set on EOF, don't use operator!()
|
||||||
putc (ch, fd1);
|
{
|
||||||
|
if ( !file.Write(buf, stream.gcount()) )
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fclose (fd1);
|
while ( !stream.eof() );
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
#else // !wxUSE_STD_IOSTREAM
|
||||||
|
|
||||||
bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream)
|
bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream)
|
||||||
{
|
{
|
||||||
FILE *fd1;
|
wxFFile file(filename, _T("rb"));
|
||||||
int ch;
|
if ( !file.IsOpened() )
|
||||||
|
|
||||||
if ((fd1 = wxFopen (filename, wxT("rb"))) == NULL)
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
while ((ch = getc (fd1)) != EOF)
|
char buf[4096];
|
||||||
stream.PutC((char) ch);
|
|
||||||
|
size_t nRead;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
nRead = file.Read(buf, WXSIZEOF(buf));
|
||||||
|
if ( file.Error() )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
stream.Write(buf, nRead);
|
||||||
|
if ( !stream )
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
while ( !file.Eof() );
|
||||||
|
|
||||||
fclose (fd1);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename)
|
bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename)
|
||||||
{
|
{
|
||||||
FILE *fd1;
|
wxFFile file(filename, _T("wb"));
|
||||||
char ch;
|
if ( !file.IsOpened() )
|
||||||
|
|
||||||
if ((fd1 = wxFopen (filename, wxT("wb"))) == NULL)
|
|
||||||
{
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
int len = stream.GetSize();
|
char buf[4096];
|
||||||
// TODO: is this the correct test for EOF?
|
do
|
||||||
while (stream.TellI() < (len - 1))
|
|
||||||
{
|
{
|
||||||
ch = stream.GetC();
|
stream.Read(buf, WXSIZEOF(buf));
|
||||||
putc (ch, fd1);
|
|
||||||
|
const size_t nRead = stream.LastRead();
|
||||||
|
if ( !nRead || !file.Write(buf, nRead) )
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
fclose (fd1);
|
while ( !stream.Eof() );
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
|
||||||
|
|
||||||
#endif // wxUSE_DOC_VIEW_ARCHITECTURE
|
#endif // wxUSE_DOC_VIEW_ARCHITECTURE
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user