Pergunta

Well i have one file on my server and other on my computer. What i want to do is a simple updater that checks if the file of my computer is equal to the one uploaded in the server. (If it's equal then it hasn't been updated, if it's not equal then download)

I'm using QNetworkAccessManager to download files. Any idea?

Foi útil?

Solução

You could calculate the SHA-1 checksum of the file and then compare the two checksums. If they are equal, the files have the same contents.

Outras dicas

You can generate a checksum from a file in the following way:

QCryptographicHash hash( QCryptographicHash::Sha1 );
QFile file( fileName );

if ( file.open( QIODevice::ReadOnly ) ) {
    hash.addData( file.readAll() );
} else {
    // Handle "cannot open file" error
}

// Retrieve the SHA1 signature of the file
QByteArray sig = hash.result();

Do this for both files (while somehow getting the signature from one machine to the other) and compare the results.

You will need something on your server (a WebService, or a plain servlet/php) that would take a file name (or ID or smth) as parameter and reply with its checksum (SHA1, MD5).

If your local file checksum differs from the remote one - download it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top