The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. class UpdaterDialogModalCallback;
  19. //==============================================================================
  20. class LatestVersionChecker : private Thread,
  21. private Timer
  22. {
  23. public:
  24. struct JuceVersionTriple
  25. {
  26. JuceVersionTriple();
  27. JuceVersionTriple (int juceVersionNumber);
  28. JuceVersionTriple (int majorInt, int minorInt, int buildNumber);
  29. static bool fromString (const String& versionString, JuceVersionTriple& result);
  30. String toString() const;
  31. bool operator> (const JuceVersionTriple& b) const noexcept;
  32. int major, minor, build;
  33. };
  34. //==============================================================================
  35. struct JuceServerLocationsAndKeys
  36. {
  37. const char* updateSeverHostname;
  38. const char* publicAPIKey;
  39. int apiVersion;
  40. const char* updatePath;
  41. };
  42. //==============================================================================
  43. LatestVersionChecker();
  44. ~LatestVersionChecker();
  45. static String getOSString();
  46. URL getLatestVersionURL (String& headers, const String& path) const;
  47. URL getLatestVersionURL (String& headers) const;
  48. void checkForNewVersion();
  49. bool processResult (var reply, const String& downloadPath);
  50. bool askUserAboutNewVersion (const JuceVersionTriple& version,
  51. const String& releaseNotes,
  52. URL& newVersionToDownload,
  53. const String& extraHeaders);
  54. void askUserForLocationToDownload (URL& newVersionToDownload, const String& extraHeaders);
  55. static bool isZipFolder (const File&);
  56. virtual Result performUpdate (const MemoryBlock& data, File& targetFolder);
  57. protected:
  58. const JuceServerLocationsAndKeys& getJuceServerURLsAndKeys() const;
  59. int getProductVersionNumber() const;
  60. const char* getProductName() const;
  61. bool allowCustomLocation() const;
  62. private:
  63. //==============================================================================
  64. friend class UpdaterDialogModalCallback;
  65. // callbacks
  66. void timerCallback() override;
  67. void run() override;
  68. void modalStateFinished (int result,
  69. URL& newVersionToDownload,
  70. const String& extraHeaders,
  71. File appParentFolder);
  72. int statusCode;
  73. var jsonReply;
  74. bool hasAttemptedToReadWebsite;
  75. String newRelativeDownloadPath;
  76. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LatestVersionChecker)
  77. };