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