source: smplayer/trunk/src/filehash.cpp@ 184

Last change on this file since 184 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

File size: 1.6 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "filehash.h"
20#include <QFile>
21#include <QDataStream>
22
23// From the patch by Kamil Dziobek turbos11(at)gmail.com
24// (c) Kamil Dziobek turbos11(at)gmail.com | BSD or GPL or public domain
25QString FileHash::calculateHash(QString filename) {
26 QFile file(filename);
27
28 if (!file.exists()) {
29 qWarning("OSParser:calculateHash: error hashing file. File doesn't exist.");
30 return QString();
31 }
32
33 file.open(QIODevice::ReadOnly);
34 QDataStream in(&file);
35 in.setByteOrder(QDataStream::LittleEndian);
36 quint64 size=file.size ();
37 quint64 hash=size;
38 quint64 a;
39 for(int i = 0; i < 8192; i++) {
40 in >> a ; hash += a;
41 };
42 file.seek(size-65536);
43 for(int i = 0; i < 8192; i++) {
44 in >> a ; hash += a;
45 };
46
47 QString hexhash = QString("%1").arg(hash, 16, 16, QChar('0'));
48
49 return hexhash;
50}
51
Note: See TracBrowser for help on using the repository browser.