Function openArchiveStream

Synopsis

#include <include/bitinputarchive.hpp>

IInArchive * openArchiveStream(const BitArchiveHandler &handler, const wstring &name, IInStream *in_stream)

Description

No description yet.

Source

Lines 52-96 in src/bitinputarchive.cpp. Line 79 in include/bitinputarchive.hpp.

IInArchive* BitInputArchive::openArchiveStream( const BitArchiveHandler& handler,
                                                const wstring& name,
                                                IInStream* in_stream ) {
#ifdef BIT7Z_AUTO_FORMAT
    bool detected_by_signature = false;
    if ( *mDetectedFormat == BitFormat::Auto ) {
        // Detecting format of the input file
        mDetectedFormat = &( BitFormat::detectFormatFromSig( in_stream ) );
        detected_by_signature = true;
    }
    GUID format_GUID = mDetectedFormat->guid();
#else
    GUID format_GUID = handler.format().guid();
#endif
    // NOTE: CMyComPtr is still needed: if an error occurs and an exception is thrown,
    // the IInArchive object is deleted automatically!
    CMyComPtr< IInArchive > in_archive = initArchiveObject( handler.library(), &format_GUID );

    // Creating open callback for the file
    CMyComPtr< IArchiveOpenCallback > open_callback = new OpenCallback( handler, name );

    // Trying to open the file with the detected format
    HRESULT res = in_archive->Open( in_stream, nullptr, open_callback );

#ifdef BIT7Z_AUTO_FORMAT
    if ( res != S_OK && handler.format() == BitFormat::Auto && !detected_by_signature ) {
        /* User wanted auto detection of format, an extension was detected but opening failed, so we try a more
         * precise detection by checking the signature.
         * NOTE: If user specified explicitly a format (i.e. not BitFormat::Auto), this check is not performed
         *       and an exception is thrown (next if)!
         * NOTE 2: If signature detection was already performed (detected_by_signature == false), it detected a
         *         a wrong format, no further check can be done and an exception must be thrown (next if)! */
        mDetectedFormat = &( BitFormat::detectFormatFromSig( in_stream ) );
        format_GUID = mDetectedFormat->guid();
        in_archive = initArchiveObject( handler.library(), &format_GUID );
        res = in_archive->Open( in_stream, nullptr, open_callback );
    }
#endif

    if ( res != S_OK ) {
        throw BitException( L"Cannot open archive '" + name + L"'", ERROR_OPEN_FAILED );
    }

    return in_archive.Detach();
}





Add Discussion as Guest

Log in