filesystem.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "filesystem.h"
  2. #include <QDebug>
  3. #include <QSettings>
  4. bool FileSystem::fileExists(QString path) {
  5. QFileInfo check_file(path);
  6. bool exists = check_file.exists() && check_file.isFile();
  7. if (exists == false)
  8. qWarning("%s:%i: %s%s", __FILE__, __LINE__, "Файл не найден: ", path.toStdString().c_str());
  9. else
  10. qInfo("%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. }
  33. QStringList FileSystem::recognizeRegistryLotroPath()
  34. {
  35. QStringList paths;
  36. #ifdef _WIN32
  37. // Windows 8, 10
  38. QSettings n("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\12bbe590-c890-11d9-9669-0800200c9a66_is1", QSettings::NativeFormat);
  39. foreach (QString key, n.allKeys()) {
  40. qDebug() << key;
  41. if(key.contains("InstallLocation") || key.contains("installlocation")){
  42. QString folder = n.value(key).toString()
  43. .replace("\\", "/")
  44. .replace("/TurbineLauncher.exe", "")
  45. .replace("/LotroLauncher.exe", "")
  46. .replace("\"", "");
  47. if(FileSystem::fileExists(folder + "/LotroLauncher.exe"))
  48. paths.append(folder);
  49. }
  50. }
  51. // Windows 7
  52. QSettings m("HKEY_CLASSES_ROOT\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache", QSettings::NativeFormat);
  53. foreach (QString key, m.allKeys()) {
  54. if((key.contains("TurbineLauncher.exe") || key.contains("LotroLauncher.exe")) && FileSystem::fileExists(key)){
  55. QString folder = n.value(key).toString()
  56. .replace("\\", "/")
  57. .replace("/TurbineLauncher.exe", "")
  58. .replace("/LotroLauncher.exe", "")
  59. .replace("\"", "");
  60. if(FileSystem::fileExists(folder + "/LotroLauncher.exe"))
  61. paths.append(folder);
  62. }
  63. }
  64. #else
  65. // Реализация под Linux
  66. #endif
  67. return paths;
  68. }