filesystem.cpp 1.2 KB

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