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);
	}
}
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;
	}
}
Beispiel #3
0
wxFileOffset wxBackingFileImpl::GetLength() const
{
    if (m_parenterror != wxSTREAM_EOF) {
        wxLogNull nolog;
        return m_stream->GetLength();
    }
    return m_filelen + m_buflen;
}
Beispiel #4
0
void
wxMemoryInputStream::InitFromStream(wxInputStream& stream, wxFileOffset lenFile)
{
    if ( lenFile == wxInvalidOffset )
        lenFile = stream.GetLength();

    if ( lenFile == wxInvalidOffset )
    {
        m_i_streambuf = NULL;
        m_lasterror = wxSTREAM_EOF;
        return;
    }

    const size_t len = wx_truncate_cast(size_t, lenFile);
    wxASSERT_MSG( (wxFileOffset)len == lenFile, wxT("huge files not supported") );

    m_i_streambuf = new wxStreamBuffer(wxStreamBuffer::read);
    m_i_streambuf->SetBufferIO(len); // create buffer
    stream.Read(m_i_streambuf->GetBufferStart(), len);
    m_i_streambuf->SetIntPosition(0); // seek to start pos
    m_i_streambuf->Fixed(true);
    m_length = stream.LastRead();
}
Beispiel #5
0
bool wxSHA384::Hash(wxInputStream &input, wxSHA384Hash &hash)
{
    // Get and verify the length of the stream
    m_length = input.GetLength();
    if((m_length == wxInvalidOffset) || (m_length == 0))
        return false;

    // Initialize H[0,..,7]
    hash.H[0] = SHA384_INIT_0;
    hash.H[1] = SHA384_INIT_1;
    hash.H[2] = SHA384_INIT_2;
    hash.H[3] = SHA384_INIT_3;
    hash.H[4] = SHA384_INIT_4;
    hash.H[5] = SHA384_INIT_5;
    H6        = SHA384_INIT_6;
    H7        = SHA384_INIT_7;

    // Initialize data variables
    m_readed = 0;
    m_N = (m_length / SHA384_DATA_PAD_SPACE_1) + 1;
    for(i = 0; i < m_N; i++)
    {
        // Initialize temporary HASH value
        a = hash.H[0];
        b = hash.H[1];
        c = hash.H[2];
        d = hash.H[3];
        e = hash.H[4];
        f = hash.H[5];
        g = H6;
        h = H7;

        // First step SHA384 [0,..,15]
        size_t t;
        for(t = 0; t < 16; t++)
        {
            // Read data to W[t]
            if((input.Read(&W[t], GetWSize()).LastRead() != GetWSize()) && ((m_length - m_readed) != input.LastRead()))
                return false;
            W[t] = wxUINT64_SWAP_ON_LE(W[t].GetValue());

            // Wt = Mt(i)
            M(t, input.LastRead());
            m_readed += input.LastRead();

            ComputeTempHash(t);
        }

        // Second step SHA384 [16,..,79]
        for(; t < 80; t++)
        {
            W16_79(t);
            ComputeTempHash(t);
        }

        // Update HASH
        hash.H[0] += a;
        hash.H[1] += b;
        hash.H[2] += c;
        hash.H[3] += d;
        hash.H[4] += e;
        hash.H[5] += f;
        H6        += g;
        H7        += h;
    }
    return true;
}