30 QFile fileSource( mSource );
31 if ( !fileSource.exists() )
33 mErrorString = tr(
"Source file '%1' does not exist" ).arg( mSource );
37 if ( QFileInfo( mDestination ).isDir() )
39 mDestination = QDir( mDestination ).absoluteFilePath( QFileInfo( fileSource ).fileName() );
42 QFile fileDestination( mDestination );
43 if ( fileDestination.exists() )
45 mErrorString = tr(
"Destination file '%1' already exist" ).arg( mDestination );
49 const QDir destinationDir = QFileInfo( mDestination ).absoluteDir();
50 if ( !destinationDir.exists() )
52 mErrorString = tr(
"Destination directory '%1' does not exist" ).arg( destinationDir.absolutePath() );
56 fileSource.open( QIODevice::ReadOnly );
57 fileDestination.open( QIODevice::WriteOnly );
59 const int size = fileSource.size();
60 const int chunkSize = std::clamp( size / 100, 1024, 1024 * 1024 );
63 std::vector<char> data( chunkSize );
66 const int len = fileSource.read( data.data(), chunkSize );
69 mErrorString = tr(
"Fail reading from '%1'" ).arg( mSource );
77 if ( fileDestination.write( data.data(), len ) != len )
79 mErrorString = tr(
"Fail writing to '%1'" ).arg( mDestination );
84 setProgress(
static_cast<double>( bytesRead ) / size );
90 fileDestination.close();