FbImportBook::FbImportBook(FbImportThread & owner, wxInputStream & in, const wxString & filename) : m_parser(NULL) , m_database(*owner.GetDatabase()) , m_filename(owner.GetRelative(filename)) , m_filepath(owner.GetAbsolute(filename)) , m_filetype(Ext(m_filename)) , m_message(filename) , m_filesize(in.GetLength()) , m_archive(0) , m_ok(false) { wxLogMessage(_("Import file %s"), m_filename.c_str()); m_ok = in.IsOk(); if (!m_ok) return; if (m_filetype == wxT("fb2")) { m_parser = new FbImportReaderFB2(in, true); m_md5sum = m_parser->GetMd5(); } else if (m_filetype == wxT("epub")) { m_md5sum = CalcMd5(in); in.SeekI(0); wxString rootfile = FbRootReaderEPUB(in).GetRoot(); in.SeekI(0); m_parser = new FbDataReaderEPUB(in, rootfile); } else { m_md5sum = CalcMd5(in); } }
bool wxCurlFTP::Put(wxInputStream& buffer, const wxString& szRemoteFile /*= wxEmptyString*/) { curl_off_t iSize = 0; if(m_pCURL && buffer.IsOk()) { SetCurlHandleToDefaults(szRemoteFile); iSize = buffer.GetSize(); if(iSize == (~(ssize_t)0)) return false; SetOpt(CURLOPT_UPLOAD, TRUE); SetStreamReadFunction(buffer); SetOpt(CURLOPT_INFILESIZE_LARGE, iSize); if(Perform()) { return ((m_iResponseCode > 199) && (m_iResponseCode < 300)); } } return false; }
size_t wxChmInputStream::OnSysRead(void *buffer, size_t bufsize) { if ( m_pos >= m_size ) { m_lasterror = wxSTREAM_EOF; return 0; } m_lasterror = wxSTREAM_NO_ERROR; // If the rest to read from the stream is less // than the buffer size, then only read the rest if ( m_pos + bufsize > m_size ) bufsize = m_size - m_pos; if (m_contentStream->SeekI(m_pos) == wxInvalidOffset) { m_lasterror = wxSTREAM_EOF; return 0; } size_t read = m_contentStream->Read(buffer, bufsize).LastRead(); m_pos += read; if (m_contentStream->SeekI(m_pos) == wxInvalidOffset) { m_lasterror = wxSTREAM_READ_ERROR; return 0; } if (read != bufsize) m_lasterror = m_contentStream->GetLastError(); return read; }
bool wxCurlHTTP::Put(wxInputStream& buffer, const wxString& szRemoteFile /*= wxEmptyString*/) { curl_off_t iSize = 0; if(m_pCURL && buffer.IsOk()) { SetCurlHandleToDefaults(szRemoteFile); iSize = buffer.GetSize(); if(iSize == (~(size_t)0)) // wxCurlHTTP does not know how to upload unknown length streams. return false; SetOpt(CURLOPT_UPLOAD, TRUE); SetOpt(CURLOPT_PUT, TRUE); SetStreamReadFunction(buffer); SetOpt(CURLOPT_INFILESIZE_LARGE, (curl_off_t)iSize); SetStringWriteFunction(m_szResponseBody); if(Perform()) { return IsResponseOk(); } } return false; }
wxFileOffset wxChmInputStream::OnSysSeek(wxFileOffset seek, wxSeekMode mode) { wxString mode_str = wxEmptyString; if ( !m_contentStream || m_contentStream->Eof() ) { m_lasterror = wxSTREAM_EOF; return 0; } m_lasterror = wxSTREAM_NO_ERROR; wxFileOffset nextpos; switch ( mode ) { case wxFromCurrent: nextpos = seek + m_pos; break; case wxFromStart: nextpos = seek; break; case wxFromEnd: nextpos = m_size - 1 + seek; break; default: nextpos = m_pos; break; /* just to fool compiler, never happens */ } m_pos=nextpos; // Set current position on stream m_contentStream->SeekI(m_pos); return m_pos; }
void MyPipeFrame::DoGetFromStream(wxTextCtrl *text, wxInputStream& in) { while ( in.CanRead() ) { char buffer[4096]; buffer[in.Read(buffer, WXSIZEOF(buffer) - 1).LastRead()] = '\0'; text->AppendText(buffer); } }
/** @brief Read an int from an input stream * * @param in wxInputStream& * @param out_Int int& * @return bool * */ static bool ReadInt( wxInputStream& in, int& out_Int ) { int val = 0; if (!in.CanRead()) return false; in.Read(&val, sizeof(val)); out_Int = val; return true; }
/** @brief Read a long long from an input stream * * @param in wxInputStream& * @param out_LongLong long long& * @return bool * */ static bool ReadLongLong( wxInputStream& in, long long& out_LongLong ) { long long val = 0; if (!in.CanRead()) return false; in.Read(&val, sizeof(val)); out_LongLong = val; return true; }
bool HexView::Load(wxInputStream& iStr) { wxFileOffset strSize = iStr.SeekI(0, wxFromEnd); iStr.SeekI(0); unsigned char* data = new unsigned char[strSize]; iStr.Read(data, strSize); Load(data, strSize); delete [] data; return true; }
wxString IACFile::ReadToken(wxInputStream &file) { // 0 = read chars until digit // 1 = read digits until no digit // 2 = token found wxString token = wxEmptyString; int mode = 0; while (file.IsOk() && mode != 2) { int c = file.GetC(); if (c != wxEOF && c <= 128) { if (c == '\n' && m_tokensI > 0) { m_newlineTokens.push_back(m_tokensI + 1); } m_RawData.Append((char)c); switch (mode) { case 0: if (isdigit(c)) { token.Append((char)c); mode = 1; } break; case 1: if (isdigit(c) || c == '/') { token.Append((char)c); } else { if (token.Len() == 5) { // token found!! mode = 2; } else { token.Empty(); } } break; /* this is dead code case 2: mode = 0; break; */ } // case } } // while if (mode != 2) { token.Empty(); } return token; }
/** @brief Read a tokendatabase from disk * * @param tokenDatabase The tokendatabase to read into * @param in The wxInputStream to read from * @return true if the operation succeeded, false otherwise * */ bool ClTokenDatabase::ReadIn( ClTokenDatabase& tokenDatabase, wxInputStream& in ) { in.SeekI(4); // Magic number int version = 0; if (!ReadInt(in, version)) return false; int i = 0; if (version != 0x01) { return false; } tokenDatabase.Clear(); int read_count = 0; wxMutexLocker(tokenDatabase.m_Mutex); while (in.CanRead()) { int packetType = 0; if (!ReadInt(in, packetType)) return false; switch (packetType) { case ClTokenPacketType_filenames: if (!ClFilenameDatabase::ReadIn(tokenDatabase.m_FileDB, in)) return false; break; case ClTokenPacketType_tokens: int packetCount = 0; if (!ReadInt(in, packetCount)) return false; for (i = 0; i < packetCount; ++i) { ClAbstractToken token; if (!ClAbstractToken::ReadIn(token, in)) return false; if (token.fileId != -1) { //ClTokenId tokId = tokenDatabase.InsertToken(token); //fprintf( stdout, " '%s' / '%s' / fId=%d location=%d:%d hash=%d dbEntryId=%d\n", (const char*)token.identifier.mb_str(), (const char*)token.displayName.mbc_str(), token.fileId, token.location.line, token.location.column, token.tokenHash, tokId ); read_count++; } } break; } } return true; }
bool wxChmInputStream::Eof() const { return (m_content==NULL || m_contentStream==NULL || m_contentStream->Eof() || m_pos>m_size); }
bool IACFile::Read(wxInputStream &stream) { bool isok = false; // true if minimum one token was read from file Invalidate(); wxString token; m_tokensI = 0; if (stream.IsOk()) { for (;;) { token = ReadToken(stream); if (!token.IsEmpty()) { m_tokens.Add(token); m_tokensI++; isok = true; } else { break; } } } m_tokensI = 0; // for (std::vector<size_t>::iterator it = m_newlineTokens.begin(); it != m_newlineTokens.end(); ++it) // { // wxMessageBox( wxString::Format( _T("ID: %i :"), *it ) + m_tokens[*it] ); // } if (isok) { // decode tokens if some were found isok = Decode(); } m_isok = isok; return isok; }
FbImportZip::FbImportZip(FbImportThread & owner, wxInputStream &in, const wxString &filename): m_owner(owner), m_database(*owner.GetDatabase()), m_conv(wxT("cp866")), m_zip(in, m_conv), m_filename(owner.GetRelative(filename)), m_filepath(owner.GetAbsolute(filename)), m_filesize(in.GetLength()), m_ok(m_zip.IsOk()) { if (!m_ok) { wxLogError(_("Zip read error %s"), filename.c_str()); return; } wxLogMessage(_("Import zip %s"), filename.c_str()); while (wxZipEntry * entry = m_zip.GetNextEntry()) { if (entry->GetSize()) { wxString filename = entry->GetInternalName(); if (Ext(filename) == wxT("fbd")) { wxString infoname = filename.BeforeLast(wxT('.')); wxZipEntry*& current = m_map[infoname]; delete current; current = entry; } else { m_list.Add(entry); } } if (m_owner.IsClosed()) break; } }
bool wxPNMHandler::DoCanRead( wxInputStream& stream ) { Skip_Comment(stream); if ( stream.GetC() == 'P' ) { switch (stream.GetC()) { case '3': case '6': return true; } } return false; }
void Database::loadIpCounts(wxInputStream &file) { double totallinecount = 0; wxTextInputStream str(file); str >> totallinecount; int c = 0; while(!file.Eof()) { wxString line = str.ReadLine(); if (line.IsEmpty()) break; std::wistringstream stream(line.c_str().AsWChar()); std::wstring memaddr; stream >> memaddr; double count; stream >> count; std::wstring srcfile; int linenum; ::readQuote(stream, srcfile); stream >> linenum; LineInfo& lineinfo = (fileinfo[srcfile])[linenum]; lineinfo.count += count; lineinfo.percentage += 100.0f * ((float)count / (float)totallinecount); } }
bool wxSVGHandler::DoCanRead(wxInputStream& stream) { unsigned char hdr[5]; if (!stream.Read(hdr, WXSIZEOF(hdr))) // it's ok to modify the stream position here return false; return hdr[0] == '<' && hdr[1] == '?' && hdr[2] == 'x' && hdr[3] == 'm' && hdr[4] == 'l'; // <?xml }
wxString ReadStream(wxInputStream& stream) { wxTextInputStream txt(stream); wxString str, line; while (!stream.Eof()) str += txt.ReadLine() + wxT('\n'); return str; }
wxFileOffset wxBackingFileImpl::GetLength() const { if (m_parenterror != wxSTREAM_EOF) { wxLogNull nolog; return m_stream->GetLength(); } return m_filelen + m_buflen; }
bool wxJPEGHandler::DoCanRead( wxInputStream& stream ) { unsigned char hdr[2]; if ( !stream.Read(hdr, WXSIZEOF(hdr)) ) return false; return hdr[0] == 0xFF && hdr[1] == 0xD8; }
bool wxTarHeaderBlock::Read(wxInputStream& in) { bool ok = true; for (int id = 0; id < TAR_NUMFIELDS && ok; id++) ok = in.Read(Get(id), Len(id)).LastRead() == Len(id); return ok; }
bool wxJPEGHandler::DoCanRead( wxInputStream& stream ) { unsigned char hdr[2]; if ( !stream.Read(hdr, WXSIZEOF(hdr)) ) // it's ok to modify the stream position here return false; return hdr[0] == 0xFF && hdr[1] == 0xD8; }
void ApprExpansionDatabase::doRead(wxInputStream& in) { wxTextInputStream tin(in); while (!in.Eof()) { String l = tin.ReadLine(); if (l.size() < 3) continue; order.push_back(l.substr(0,2)); expansions[l.substr(0,2)] = l.substr(3); } }
bool wxPNGHandler::DoCanRead( wxInputStream& stream ) { unsigned char hdr[4]; if ( !stream.Read(hdr, WXSIZEOF(hdr)) ) return false; return memcmp(hdr, "\211PNG", WXSIZEOF(hdr)) == 0; }
bool wxPNGHandler::DoCanRead( wxInputStream& stream ) { unsigned char hdr[4]; if ( !stream.Read(hdr, WXSIZEOF(hdr)) ) // it's ok to modify the stream position here return false; return memcmp(hdr, "\211PNG", WXSIZEOF(hdr)) == 0; }
bool MainWindow::ReadOutput(wxInputStream& s) { // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state s.Reset(); wxTextInputStream tis(s, " ", wxConvUTF8); while (true) { wxString line = tis.ReadLine(); if ( !line.empty() ) { this->text->AppendText(line); } this->text->AppendText(wxTextFile::GetEOL()); if (s.Eof()) { break; } } return true; }
bool wxPNMHandler::DoCanRead( wxInputStream& stream ) { Skip_Comment(stream); // it's ok to modify the stream position here if ( stream.GetC() == 'P' ) { switch ( stream.GetC() ) { case '2': // ASCII Grey case '3': // ASCII RGB case '5': // RAW Grey case '6': // RAW RGB return true; } } return false; }
void Skip_Comment(wxInputStream &stream) { wxTextInputStream text_stream(stream); if (stream.Peek()==wxT('#')) { text_stream.ReadLine(); Skip_Comment(stream); } }
size_t wxChmInputStream::OnSysRead(void *buffer, size_t bufsize) { if ( m_pos >= m_size ) { m_lasterror = wxSTREAM_EOF; return 0; } m_lasterror = wxSTREAM_NO_ERROR; // If the rest to read from the stream is less // than the buffer size, than only read the rest if ( m_pos + bufsize > m_size ) bufsize = m_size - m_pos; m_contentStream->SeekI(m_pos); m_contentStream->Read(buffer, bufsize); m_pos +=bufsize; m_contentStream->SeekI(m_pos); return bufsize; }
/** @brief Read a string from an input stream * * @param in wxInputStream& * @param out_String wxString& * @return bool * */ static bool ReadString( wxInputStream& in, wxString& out_String ) { int len; if (!ReadInt(in, len)) return false; if (len == 0) { out_String = out_String.Truncate(0); return true; } if (!in.CanRead()) return false; char buffer[len + 1]; in.Read( buffer, len ); buffer[len] = '\0'; out_String = wxString::FromUTF8(buffer); return true; }