|
@@ -1,6 +1,7 @@
|
|
|
#include "filesystem.h"
|
|
|
#include <QFile>
|
|
|
#include <QFileInfo>
|
|
|
+#include <QCryptographicHash>
|
|
|
|
|
|
static bool FileSystem::fileExists(QString path) {
|
|
|
QFileInfo check_file(path);
|
|
@@ -12,6 +13,25 @@ static bool FileSystem::fileExists(QString path) {
|
|
|
return exists;
|
|
|
}
|
|
|
|
|
|
-static QString FileSystem::fileHash(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm);
|
|
|
+static QString FileSystem::fileHash(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm) {
|
|
|
+ QFile file(fileName);
|
|
|
+ if (file.open(QIODevice::ReadOnly)) {
|
|
|
+ QByteArray fileData = file.readAll();
|
|
|
+ QByteArray hashData = QCryptographicHash::hash(fileData, hashAlgorithm);
|
|
|
+ return hashData.toHex();
|
|
|
+ }
|
|
|
+ return QByteArray();
|
|
|
+}
|
|
|
+
|
|
|
+static void FileSystem::clearFolder(QDir &dir) {
|
|
|
+ //Получаем список файлов
|
|
|
+ QStringList lstFiles = dir.entryList(QDir::Files);
|
|
|
|
|
|
-static void FileSystem::clearFolder(QDir &dir);
|
|
|
+ //Удаляем файлы
|
|
|
+ foreach (QString entry, lstFiles){
|
|
|
+ QString entryAbsPath = dir.absolutePath() + "/" + entry;
|
|
|
+ //QFile::setPermissions(entryAbsPath, QFile::ReadOwner | QFile::WriteOwner);
|
|
|
+ qDebug() << dir.absolutePath();
|
|
|
+ QFile::remove(entryAbsPath);
|
|
|
+ }
|
|
|
+}
|