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.

139 lines
4.2KB

  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. //==============================================================================
  19. struct ProjucerLicenses : private DeletedAtShutdown
  20. {
  21. ProjucerLicenses()
  22. {
  23. dll.initialise (crashCallback, quitCallback, false);
  24. }
  25. juce_DeclareSingleton (ProjucerLicenses, false)
  26. //==============================================================================
  27. struct LoginCallback
  28. {
  29. virtual ~LoginCallback() {}
  30. // always called on message thread
  31. virtual void loginError (const String& errorMessage, bool hiliteUserID) = 0;
  32. virtual void loginSuccess (const String& username, const String& apiKey) = 0;
  33. };
  34. // Log the user in. This will return immedietely
  35. void login (const String& userLoginName, const String& userPassword,
  36. bool remainLoggedIn, LoginCallback* callback)
  37. {
  38. if (dll.isLoaded())
  39. {
  40. jassert (callback != nullptr);
  41. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  42. userCallback = callback;
  43. dll.projucer_login (userLoginName.toRawUTF8(), userPassword.toRawUTF8(),
  44. remainLoggedIn, staticCallbackFunction, this);
  45. }
  46. else
  47. {
  48. callback->loginError ("The Projucer DLL is missing", false);
  49. }
  50. }
  51. // Log the user out. Only call on the message thread!
  52. void logout()
  53. {
  54. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  55. if (dll.isLoaded())
  56. dll.projucer_logout();
  57. }
  58. bool isLoggedIn() const noexcept
  59. {
  60. return dll.isLoaded() && dll.projucer_isLoggedIn();
  61. }
  62. String getLoginName() const noexcept
  63. {
  64. if (dll.isLoaded())
  65. {
  66. char name[256] = { 0 };
  67. dll.projucer_getLoginName (name);
  68. return String::fromUTF8 (name);
  69. }
  70. return {};
  71. }
  72. bool isDLLPresent() const
  73. {
  74. return dll.isLoaded();
  75. }
  76. bool hasLiveCodingLicence() const
  77. {
  78. return isDLLPresent() && dll.projucer_hasLiveCodingLicence();
  79. }
  80. bool hasFreeToUseLicense() const
  81. {
  82. return isDLLPresent() && dll.projucer_hasLicense ("ProjucerFreeToUse");
  83. }
  84. bool retryLoadDll()
  85. {
  86. dll.tryLoadDll();
  87. return dll.isLoaded();
  88. }
  89. private:
  90. CompileEngineDLL dll;
  91. LoginCallback* userCallback = nullptr;
  92. void callbackFunction (const char* errorMessage, const char* username, const char* apiKey)
  93. {
  94. jassert (userCallback != nullptr);
  95. if (userCallback != nullptr)
  96. {
  97. if (errorMessage != nullptr)
  98. userCallback->loginError (String::fromUTF8 (errorMessage), false);
  99. else
  100. userCallback->loginSuccess (String::fromUTF8 (username), String::fromUTF8 (apiKey));
  101. }
  102. }
  103. static void staticCallbackFunction (void* userInfo, const char* errorMessage, const char* username, const char* apiKey)
  104. {
  105. static_cast<ProjucerLicenses*> (userInfo)->callbackFunction (errorMessage, username, apiKey);
  106. }
  107. static void crashCallback (const char*) {}
  108. static void quitCallback() {}
  109. };