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 if ( !fileSource.open( QIODevice::ReadOnly ) )
59 mErrorString = tr(
"Could not open '%1' for reading" ).arg( mSource );
62 if ( !fileDestination.open( QIODevice::WriteOnly ) )
64 mErrorString = tr(
"Could not open '%1' for writing" ).arg( mDestination );
68 const int size = fileSource.size();
69 const int chunkSize = std::clamp( size / 100, 1024, 1024 * 1024 );
72 std::vector<char> data( chunkSize );
75 const int len = fileSource.read( data.data(), chunkSize );
78 mErrorString = tr(
"Fail reading from '%1'" ).arg( mSource );
86 if ( fileDestination.write( data.data(), len ) != len )
88 mErrorString = tr(
"Fail writing to '%1'" ).arg( mDestination );
93 setProgress(
static_cast<double>( bytesRead ) / size );
99 fileDestination.close();