- // file should be opened and we must be in it's beginning
- wxASSERT( m_file.IsOpened() &&
- (m_file.GetKind() != wxFILE_KIND_DISK || m_file.Tell() == 0) );
-
- static const size_t BUF_SIZE = 1024;
-#if wxUSE_UNICODE
- static const size_t NUL_SIZE = 4;
-#else
- static const size_t NUL_SIZE = 1;
-#endif
-
- char buf[BUF_SIZE + NUL_SIZE];
- wxChar chLast = '\0';
- wxString str;
+ // file should be opened
+ wxASSERT_MSG( m_file.IsOpened(), _T("can't read closed file") );
+
+ // read the entire file in memory: this is not the most efficient thing to
+ // do it but there is no good way to avoid it in Unicode build because if
+ // we read the file block by block we can't convert each block to Unicode
+ // separately (the last multibyte char in the block might be only partially
+ // read and so the conversion would fail) and, as the file contents is kept
+ // in memory by wxTextFile anyhow, it shouldn't be a big problem to read
+ // the file entirely
+ size_t bufSize = 0;
+
+ // number of bytes to (try to) read from disk at once
+ static const size_t BLOCK_SIZE = 4096;
+
+ wxCharBuffer buf;
+
+ // first determine if the file is seekable or not and so whether we can
+ // determine its length in advance
+ wxFileOffset fileLength;
+ {
+ wxLogNull logNull;
+ fileLength = m_file.Length();
+ }