patch.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef LEGACYPATCH_H
  2. #define LEGACYPATCH_H
  3. #include <QObject>
  4. #include <QQueue>
  5. #include <QTimer>
  6. #include "models/downloader.h"
  7. #include "models/filesystem.h"
  8. #include "models/lotrodatmanager.h"
  9. #include "models/settings.h"
  10. class Patch : public QObject
  11. {
  12. Q_OBJECT
  13. public:
  14. enum Operation {
  15. E_CHECKFORUPDATES,
  16. E_DOWNLOAD,
  17. E_INSTALL,
  18. E_ACTIVATE
  19. };
  20. struct OperationProgress {
  21. OperationProgress() = default;
  22. OperationProgress(Downloader::Status status);
  23. OperationProgress(LotroDatManager::Status status);
  24. OperationProgress operator+(const Patch::OperationProgress& other) const;
  25. double getDownloadPercent() const;
  26. double getInstallPercent() const;
  27. public:
  28. quint64 download_finished_bytes = 0;
  29. quint64 download_total_bytes = 0;
  30. quint64 download_speed = 0;
  31. quint64 download_elapsed_time = 0;
  32. quint64 install_finished_parts = 0;
  33. quint64 install_total_parts = 0;
  34. };
  35. public:
  36. explicit Patch(QString patch_name, LotroDatManager* mgr, QObject* parent);
  37. QString getPatchName() const;
  38. public slots:
  39. void enqueue(const Patch::Operation& operation);
  40. void enqueue(const QList<Patch::Operation>& operations);
  41. void processQueue();
  42. private slots: // WARNING: THESE CAN BE NON-BLOCKING OPERATIONS! Use them in chain only via operationFinished signal handlers.
  43. virtual void checkForUpdates() = 0; // Checks for updates. Updates patches info in Settings.
  44. virtual void download() = 0; // Downloads patch contents, prepared for installation.
  45. virtual void install() = 0; // Installs patch into game resources (needs to be activated in order to be available in-game)
  46. virtual void activate() = 0; // Activates (or deactivates) patch components based on user preferences (patch needs to be installed)
  47. void onOperationStarted(Operation operation, Patch* patch);
  48. void onOperationFinished(Operation operation, Patch* patch);
  49. signals: // each signal brings with it pointer to class-emitter, operation name is equal to function name
  50. void operationStarted(Operation operation, Patch* patch);
  51. void progressChanged(OperationProgress progress, Patch* patch);
  52. void operationFinished(Operation operation, Patch* patch);
  53. void errorOccured(Operation operation, Patch* patch, QString msg);
  54. protected:
  55. bool needDownloadDatabase(QString db_name); // Checks if database needs to be downloaded (by checksum comparing)
  56. static bool isDatabaseDownloadEnabled(QString db_name); // Checks if database is checked for installation by user (via Settings)
  57. void execOperation(Operation operation); // Starts operation execution by its "name"
  58. protected:
  59. bool running_operation_ = false;
  60. LotroDatManager* lotro_mgr_;
  61. QString patch_name_;
  62. QSet<Downloader*> downloaders_;
  63. QQueue<Operation> operations_queue_;
  64. bool is_being_patched_by_lotro_dat_manager_ = false;
  65. quint32 elapsed_patches_to_install_ = 0;
  66. };
  67. QDebug operator<<(QDebug dbg, const Patch::Operation& operation);
  68. QDebug operator<<(QDebug dbg, const Patch::OperationProgress& operation_progress);
  69. QDebug operator<<(QDebug dbg, const Patch& patch);
  70. #endif // LEGACYPATCH_H