Function initOutFileStream

Synopsis

#include <include/bitarchivecreator.hpp>

CMyComPtr< IOutStream > initOutFileStream(const wstring &out_archive, CMyComPtr< IOutArchive > &new_arc, unique_ptr< BitInputArchive > &old_arc) const

Description

No description yet.

Source

Lines 228-260 in src/bitarchivecreator.cpp. Line 193 in include/bitarchivecreator.hpp.

CMyComPtr< IOutStream > BitArchiveCreator::initOutFileStream( const wstring& out_archive,
                                                              CMyComPtr< IOutArchive >& new_arc,
                                                              unique_ptr< BitInputArchive >& old_arc ) const {
    CMyComPtr< IOutStream > out_file_stream;
    if ( mVolumeSize > 0 ) {
        out_file_stream = new CMultiVolOutStream( mVolumeSize, out_archive );
    } else {
        auto* out_file_stream_spec = new COutFileStream();
        //NOTE: if any exception occurs in the following ifs, the file stream obj is released thanks to the CMyComPtr
        out_file_stream = out_file_stream_spec;
        if ( !out_file_stream_spec->Create( out_archive.c_str(), false ) ) {
            DWORD last_error = GetLastError();
            if ( last_error != ERROR_FILE_EXISTS ) { //unknown error
                throw BitException( L"Cannot create output archive file '" + out_archive + L"'", last_error );
            }
            if ( !mUpdateMode ) { //output archive file already exists and no update mode set
                throw BitException( L"Cannot update existing archive file '" + out_archive + L"'", ERROR_FILE_EXISTS );
            }
            if ( !mFormat.hasFeature( FormatFeatures::MULTIPLE_FILES ) ) {
                //update mode is set but format does not support adding more files
                throw BitException( "Format does not support updating existing archive files", E_INVALIDARG );
            }
            if ( !out_file_stream_spec->Create( ( out_archive + L".tmp" ).c_str(), false ) ) {
                //could not create temporary file
                throw BitException( L"Cannot create temp archive file for updating '" + out_archive + L"'", GetLastError() );
            }
            old_arc = MAKE_UNIQUE( BitInputArchive, *this, out_archive );
            old_arc->initUpdatableArchive( &new_arc );
            setArchiveProperties( new_arc );
        }
    }
    return out_file_stream;
}





Add Discussion as Guest

Log in