31 QFile fileSource( mSource );
32 if ( !fileSource.exists() )
34 mErrorString = tr(
"Source file '%1' does not exist" ).arg( mSource );
38 if ( QFileInfo( mDestination ).isDir() )
40 mDestination = QDir( mDestination ).absoluteFilePath( QFileInfo( fileSource ).fileName() );
43 QFile fileDestination( mDestination );
44 if ( fileDestination.exists() )
46 mErrorString = tr(
"Destination file '%1' already exist" ).arg( mDestination );
50 const QDir destinationDir = QFileInfo( mDestination ).absoluteDir();
51 if ( !destinationDir.exists() )
53 mErrorString = tr(
"Destination directory '%1' does not exist" ).arg( destinationDir.absolutePath() );
57 fileSource.open( QIODevice::ReadOnly );
58 fileDestination.open( QIODevice::WriteOnly );
60 const int size = fileSource.size();
61 const int chunkSize = std::clamp( size / 100, 1024, 1024 * 1024 );
64 std::vector<char> data( chunkSize );
67 const int len = fileSource.read( data.data(), chunkSize );
70 mErrorString = tr(
"Fail reading from '%1'" ).arg( mSource );
78 if ( fileDestination.write( data.data(), len ) != len )
80 mErrorString = tr(
"Fail writing to '%1'" ).arg( mDestination );
85 setProgress(
static_cast<double>( bytesRead ) / size );
91 fileDestination.close();