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.

116 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. Copyright 2015 by Raw Material Software Ltd.
  4. ==============================================================================
  5. */
  6. #ifndef PROJUCER_PROJUCERLICENSES_H_INCLUDED
  7. #define PROJUCER_PROJUCERLICENSES_H_INCLUDED
  8. //==============================================================================
  9. struct ProjucerLicences : private DeletedAtShutdown
  10. {
  11. ProjucerLicences()
  12. {
  13. dll.initialise (crashCallback, quitCallback, false);
  14. }
  15. juce_DeclareSingleton (ProjucerLicences, false);
  16. //==============================================================================
  17. struct LoginCallback
  18. {
  19. virtual ~LoginCallback() {}
  20. // always called on message thread
  21. virtual void loginError (const String& errorMessage, bool hiliteUserID) = 0;
  22. virtual void loginSuccess (const String& username, const String& apiKey) = 0;
  23. };
  24. // Log the user in. This will return immedietely
  25. void login (const String& userLoginName, const String& userPassword,
  26. bool remainLoggedIn, LoginCallback* callback)
  27. {
  28. if (dll.isLoaded())
  29. {
  30. jassert (callback != nullptr);
  31. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  32. userCallback = callback;
  33. dll.projucer_login (userLoginName.toRawUTF8(), userPassword.toRawUTF8(),
  34. remainLoggedIn, staticCallbackFunction, this);
  35. }
  36. else
  37. {
  38. callback->loginError ("The Projucer DLL is missing", false);
  39. }
  40. }
  41. // Log the user out. Only call on the message thread!
  42. void logout()
  43. {
  44. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  45. if (dll.isLoaded())
  46. dll.projucer_logout();
  47. }
  48. bool isLoggedIn() const noexcept
  49. {
  50. return dll.isLoaded() && dll.projucer_isLoggedIn();
  51. }
  52. String getLoginName() const noexcept
  53. {
  54. if (dll.isLoaded())
  55. {
  56. char name[256] = { 0 };
  57. dll.projucer_getLoginName (name);
  58. return String::fromUTF8 (name);
  59. }
  60. return String();
  61. }
  62. bool isDLLPresent() const
  63. {
  64. return dll.isLoaded();
  65. }
  66. bool hasLiveCodingLicence() const
  67. {
  68. return isDLLPresent() && dll.projucer_hasLiveCodingLicence();
  69. }
  70. private:
  71. CompileEngineDLL dll;
  72. LoginCallback* userCallback = nullptr;
  73. void callbackFunction (const char* errorMessage, const char* username, const char* apiKey)
  74. {
  75. jassert (userCallback != nullptr);
  76. if (userCallback != nullptr)
  77. {
  78. if (errorMessage != nullptr)
  79. userCallback->loginError (String::fromUTF8 (errorMessage), false);
  80. else
  81. userCallback->loginSuccess (String::fromUTF8 (username), String::fromUTF8 (apiKey));
  82. }
  83. }
  84. static void staticCallbackFunction (void* userInfo, const char* errorMessage, const char* username, const char* apiKey)
  85. {
  86. static_cast<ProjucerLicences*> (userInfo)->callbackFunction (errorMessage, username, apiKey);
  87. }
  88. static void crashCallback (const char*) {}
  89. static void quitCallback() {}
  90. };
  91. #endif // PROJUCER_PROJUCERLICENSES_H_INCLUDED