filesystem.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "filesystem.h"
  2. #include <QFile>
  3. #include <QFileInfo>
  4. #include <QCryptographicHash>
  5. #include <QDebug>
  6. bool FileSystem::fileExists(QString path) {
  7. QFileInfo check_file(path);
  8. bool exists = check_file.exists() && check_file.isFile();
  9. if(exists == false)
  10. qWarning("%s:%i: %s%s", __FILE__, __LINE__, "Файл не найден: ", path.toStdString().c_str());
  11. return exists;
  12. }
  13. QString FileSystem::fileHash(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm) {
  14. QFile file(fileName);
  15. if (file.open(QIODevice::ReadOnly)) {
  16. QByteArray fileData = file.readAll();
  17. QByteArray hashData = QCryptographicHash::hash(fileData, hashAlgorithm);
  18. return hashData.toHex();
  19. }
  20. return QByteArray();
  21. }
  22. void FileSystem::clearFolder(QDir &dir) {
  23. //Получаем список файлов
  24. QStringList lstFiles = dir.entryList(QDir::Files);
  25. //Удаляем файлы
  26. foreach (QString entry, lstFiles){
  27. QString entryAbsPath = dir.absolutePath() + "/" + entry;
  28. //QFile::setPermissions(entryAbsPath, QFile::ReadOwner | QFile::WriteOwner);
  29. qDebug() << dir.absolutePath();
  30. QFile::remove(entryAbsPath);
  31. }
  32. }