Check if a file equals to other
Asked Answered
C

3

6

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?

Costplus answered 15/12, 2011 at 8:18 Comment(0)
C
3

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.

Caren answered 15/12, 2011 at 8:22 Comment(0)
H
6

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.

Hemichordate answered 15/12, 2011 at 23:43 Comment(0)
C
3

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.

Caren answered 15/12, 2011 at 8:22 Comment(0)
N
1

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.

Nepotism answered 15/12, 2011 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.