32 QFile fileSource( mSource );
33 if ( !fileSource.exists() )
35 mErrorString = tr(
"Source file '%1' does not exist" ).arg( mSource );
39 if ( QFileInfo( mDestination ).isDir() )
41 mDestination = QDir( mDestination ).absoluteFilePath( QFileInfo( fileSource ).fileName() );
44 QFile fileDestination( mDestination );
45 if ( fileDestination.exists() )
47 mErrorString = tr(
"Destination file '%1' already exist" ).arg( mDestination );
51 const QDir destinationDir = QFileInfo( mDestination ).absoluteDir();
52 if ( !destinationDir.exists() )
54 mErrorString = tr(
"Destination directory '%1' does not exist" ).arg( destinationDir.absolutePath() );
58 if ( !fileSource.open( QIODevice::ReadOnly ) )
60 mErrorString = tr(
"Could not open '%1' for reading" ).arg( mSource );
63 if ( !fileDestination.open( QIODevice::WriteOnly ) )
65 mErrorString = tr(
"Could not open '%1' for writing" ).arg( mDestination );
69 const int size = fileSource.size();
70 const int chunkSize = std::clamp( size / 100, 1024, 1024 * 1024 );
73 std::vector<char> data( chunkSize );
76 const int len = fileSource.read( data.data(), chunkSize );
79 mErrorString = tr(
"Fail reading from '%1'" ).arg( mSource );
87 if ( fileDestination.write( data.data(), len ) != len )
89 mErrorString = tr(
"Fail writing to '%1'" ).arg( mDestination );
94 setProgress(
static_cast<double>( bytesRead ) / size );
100 fileDestination.close();