1 #ifndef UNSHIELDWORKER_HPP 2 #define UNSHIELDWORKER_HPP 3 4 #include <QObject> 5 #include <QThread> 6 #include <QMutex> 7 #include <QWaitCondition> 8 #include <QReadWriteLock> 9 #include <QStringList> 10 11 #include <libunshield.h> 12 13 #include "../inisettings.hpp" 14 15 16 namespace Wizard 17 { 18 enum Component { 19 Component_Morrowind, 20 Component_Tribunal, 21 Component_Bloodmoon 22 }; 23 24 class UnshieldWorker : public QObject 25 { 26 Q_OBJECT 27 28 public: 29 UnshieldWorker(QObject *parent = nullptr); 30 ~UnshieldWorker(); 31 32 void stopWorker(); 33 34 void setInstallComponent(Wizard::Component component, bool install); 35 36 void setDiskPath(const QString &path); 37 38 void setPath(const QString &path); 39 void setIniPath(const QString &path); 40 41 QString getPath(); 42 QString getIniPath(); 43 44 void setIniCodec(QTextCodec *codec); 45 46 bool setupSettings(); 47 48 private: 49 50 bool writeSettings(); 51 52 bool getInstallComponent(Component component); 53 54 QString getDiskPath(); 55 56 void setComponentDone(Component component, bool done = true); 57 bool getComponentDone(Component component); 58 59 bool removeDirectory(const QString &dirName); 60 61 bool copyFile(const QString &source, const QString &destination, bool keepSource = true); 62 bool copyDirectory(const QString &source, const QString &destination, bool keepSource = true); 63 64 bool extractCab(const QString &cabFile, const QString &destination); 65 bool extractFile(Unshield *unshield, const QString &destination, const QString &prefix, int index, int counter); 66 67 bool findInCab(const QString &fileName, const QString &cabFile); 68 69 QString findFile(const QString &fileName, const QString &path); 70 71 QStringList findFiles(const QString &fileName, const QString &path, int depth = 0, bool recursive = true, 72 bool directories = false, Qt::MatchFlags flags = Qt::MatchExactly); 73 74 QStringList findDirectories(const QString &dirName, const QString &path, bool recursive = true); 75 76 bool installFile(const QString &fileName, const QString &path, Qt::MatchFlags flags = Qt::MatchExactly, 77 bool keepSource = false); 78 79 bool installFiles(const QString &fileName, const QString &path, Qt::MatchFlags flags = Qt::MatchExactly, 80 bool keepSource = false, bool single = false); 81 82 bool installDirectories(const QString &dirName, const QString &path, 83 bool recursive = true, bool keepSource = false); 84 85 bool installComponent(Component component, const QString &path); 86 bool setupComponent(Component component); 87 88 bool mInstallMorrowind; 89 bool mInstallTribunal; 90 bool mInstallBloodmoon; 91 92 bool mMorrowindDone; 93 bool mTribunalDone; 94 bool mBloodmoonDone; 95 96 bool mStopped; 97 98 QString mPath; 99 QString mIniPath; 100 QString mDiskPath; 101 102 IniSettings mIniSettings; 103 104 QTextCodec *mIniCodec; 105 106 QWaitCondition mWait; 107 108 QReadWriteLock mLock; 109 110 public slots: 111 void extract(); 112 113 signals: 114 void finished(); 115 void requestFileDialog(Wizard::Component component); 116 117 void textChanged(const QString &text); 118 119 void error(const QString &text, const QString &details); 120 void progressChanged(int progress); 121 122 }; 123 } 124 125 #endif // UNSHIELDWORKER_HPP 126