patchdownloader.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef PATCHDOWNLOADER_H
  2. #define PATCHDOWNLOADER_H
  3. #include <QObject>
  4. #include <QTimer>
  5. #include <QDate>
  6. #include <QDir>
  7. #include <QSettings>
  8. #include <QMap>
  9. #include "models/downloader.h"
  10. struct Patch {
  11. QUrl url;
  12. QString md5_hash;
  13. QString datetime;
  14. QString name;
  15. };
  16. class PatchDownloader : public QObject
  17. {
  18. Q_OBJECT
  19. public:
  20. explicit PatchDownloader(QSettings* settings, QObject *parent = nullptr);
  21. ~PatchDownloader();
  22. void enableAutoUpdate();
  23. void disableAutoUpdate();
  24. void stopAllDownloads();
  25. void startAllDownloads();
  26. QString getPredictedDownloadSizeFormatted();
  27. QString getDatabasePathByPatchName(QString name);
  28. public slots:
  29. void checkForUpdates();
  30. private slots:
  31. void onDownloaderCompleted(Downloader* downloader_ptr);
  32. void onDownloaderProgressChanged(Downloader* downloader_ptr);
  33. signals:
  34. void checkForUpdatesStarted();
  35. void checkForUpdatesFinished();
  36. void getPatchListError();
  37. void removeFileError(QString filename);
  38. void downloadNewFilesError();
  39. void downloadCompleted();
  40. void downloadStarted();
  41. void progressChanged(quint64 bytesDownloaded, quint64 bytesTotal,
  42. QString download_speed_formatted,
  43. QString elapsed_time_formatted);
  44. void patchDateChanged(QString patch_name, QDate patch_date);
  45. private:
  46. int versionFromPatchFilename(QString filename);
  47. bool updatePatchList();
  48. bool removeOldPatchesFromDirecrory();
  49. bool DownloadMissingPatches();
  50. private:
  51. QSettings* app_settings;
  52. quint8 active_downloads_number = 0;
  53. const QDir patch_download_dir;
  54. const QStringList all_patch_names = {"sound", "text", "image", "loadscreen", "texture", "font", "video"};
  55. QTimer update_check_timer;
  56. QMap<QString, Downloader*> downloads_list;
  57. QMap<QString, Patch> patch_data;
  58. };
  59. #endif // PATCHDOWNLOADER_H