Browse Source

GameRes and FileSystem classes added. They contain some functions from Helper class part 2

Ivan Arkhipov 7 years ago
parent
commit
e2e87c6235
3 changed files with 28 additions and 5 deletions
  1. 6 2
      Legacy.pro
  2. 22 2
      filesystem.cpp
  3. 0 1
      gameres.h

+ 6 - 2
Legacy.pro

@@ -33,7 +33,9 @@ SOURCES += \
     network.cpp \
     helper.cpp \
     downloadmanager.cpp \
-    gui.cpp
+    gui.cpp \
+    gameres.cpp \
+    filesystem.cpp
 
 HEADERS += \
         mainwindow.h \
@@ -42,7 +44,9 @@ HEADERS += \
     network.h \
     helper.h \
     downloadmanager.h \
-    gui.h
+    gui.h \
+    gameres.h \
+    filesystem.h
 
 FORMS += \
         mainwindow.ui

+ 22 - 2
filesystem.cpp

@@ -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);
+    }
+}

+ 0 - 1
gameres.h

@@ -62,7 +62,6 @@ private:
     void prepareMicroPatch();
     void applyMicroPatch();
     void applyLoadscreens();
-    void saveLocale(int locale, QPushButton *button);
     bool isDatReady(); // Checks if file is ready to write data
 
 private: