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.

164 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCER_AUTOUPDATER_H_INCLUDED
  18. #define JUCER_AUTOUPDATER_H_INCLUDED
  19. //==============================================================================
  20. class LatestVersionChecker : private Thread,
  21. private Timer
  22. {
  23. public:
  24. LatestVersionChecker() : Thread ("Updater"),
  25. hasAttemptedToReadWebsite (false)
  26. {
  27. startTimer (2000);
  28. }
  29. ~LatestVersionChecker()
  30. {
  31. stopThread (20000);
  32. }
  33. static URL getLatestVersionURL()
  34. {
  35. return URL ("http://www.juce.com/juce/updates/updatelist.php");
  36. }
  37. void processResult (var reply)
  38. {
  39. DBG (JSON::toString (reply));
  40. if (reply.isArray())
  41. {
  42. checkVersion (VersionInfo (reply[0]));
  43. }
  44. else if (reply.isObject())
  45. {
  46. // In the far-distant future, this may be contacting a defunct
  47. // URL, so hopefully the website will contain a helpful message
  48. // for the user..
  49. String message = reply.getProperty ("message", var()).toString();
  50. if (message.isNotEmpty())
  51. {
  52. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  53. TRANS("JUCE Updater"),
  54. message);
  55. }
  56. }
  57. }
  58. struct VersionInfo
  59. {
  60. VersionInfo (var v)
  61. {
  62. version = v.getProperty ("version", var()).toString().trim();
  63. url = v.getProperty (
  64. #if JUCE_MAC
  65. "url_osx",
  66. #elif JUCE_WINDOWS
  67. "url_win",
  68. #elif JUCE_LINUX
  69. "url_linux",
  70. #endif
  71. var()).toString();
  72. }
  73. String version;
  74. URL url;
  75. };
  76. void checkVersion (const VersionInfo& info)
  77. {
  78. if (info.version != SystemStats::getJUCEVersion()
  79. && info.version.containsChar ('.')
  80. && info.version.length() > 2)
  81. {
  82. DBG (info.version);
  83. DBG (info.url.toString (true));
  84. if (isRunningFromZipFolder())
  85. {
  86. JUCE_COMPILER_WARNING("todo")
  87. }
  88. else
  89. {
  90. }
  91. }
  92. }
  93. bool isRunningFromZipFolder() const
  94. {
  95. File appParentFolder (File::getSpecialLocation (File::currentApplicationFile));
  96. return appParentFolder.getChildFile ("modules").isDirectory()
  97. && appParentFolder.getChildFile ("extras").isDirectory()
  98. && appParentFolder.getChildFile ("examples").isDirectory();
  99. }
  100. private:
  101. void timerCallback() override
  102. {
  103. stopTimer();
  104. if (hasAttemptedToReadWebsite)
  105. processResult (jsonReply);
  106. else
  107. startThread (3);
  108. }
  109. void run() override
  110. {
  111. hasAttemptedToReadWebsite = true;
  112. {
  113. const ScopedPointer<InputStream> in (getLatestVersionURL().createInputStream (false));
  114. if (in == nullptr || threadShouldExit())
  115. return; // can't connect: fail silently.
  116. jsonReply = JSON::parse (in->readEntireStreamAsString());
  117. }
  118. if (threadShouldExit())
  119. return;
  120. if (jsonReply.isArray() || jsonReply.isObject())
  121. startTimer (100);
  122. }
  123. var jsonReply;
  124. bool hasAttemptedToReadWebsite;
  125. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LatestVersionChecker)
  126. };
  127. #endif // JUCER_AUTOUPDATER_H_INCLUDED