LicenseSystem.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. // BEGIN LICENSE MANAGEMENT
  23. #ifdef ATOMIC_PLATFORM_WINDOWS
  24. #ifndef _MSC_VER
  25. #define _WIN32_IE 0x501
  26. #endif
  27. #include <windows.h>
  28. #include <shellapi.h>
  29. #include <direct.h>
  30. #include <shlobj.h>
  31. #include <sys/types.h>
  32. #include <sys/utime.h>
  33. #endif
  34. #include <Atomic/Core/CoreEvents.h>
  35. #include <Atomic/Core/Context.h>
  36. #include <Atomic/Core/Timer.h>
  37. #include <Atomic/IO/FileSystem.h>
  38. #include <Atomic/IO/File.h>
  39. #include <Atomic/IO/Log.h>
  40. #include "LicenseEvents.h"
  41. #include "LicenseSystem.h"
  42. #include <Poco/MD5Engine.h>
  43. #include <Poco/File.h>
  44. namespace ToolCore
  45. {
  46. LicenseSystem::LicenseSystem(Context* context) :
  47. Object(context)
  48. , eulaAgreementConfirmed_(false)
  49. {
  50. FileSystem* filesystem = GetSubsystem<FileSystem>();
  51. eulaAgreementPath_ = filesystem->GetAppPreferencesDir("AtomicEditor", "License");
  52. eulaAgreementPath_ = AddTrailingSlash(eulaAgreementPath_);
  53. eulaAgreementPath_ += "EulaConfirmed";
  54. }
  55. LicenseSystem::~LicenseSystem()
  56. {
  57. }
  58. void LicenseSystem::Initialize()
  59. {
  60. FileSystem* filesystem = GetSubsystem<FileSystem>();
  61. eulaAgreementConfirmed_ = filesystem->FileExists(eulaAgreementPath_);
  62. if (!eulaAgreementConfirmed_)
  63. {
  64. SendEvent(E_LICENSE_EULAREQUIRED);
  65. return;
  66. }
  67. else
  68. {
  69. SendEvent(E_LICENSE_EULAACCEPTED);
  70. }
  71. }
  72. void LicenseSystem::LicenseAgreementConfirmed()
  73. {
  74. eulaAgreementConfirmed_ = true;
  75. SharedPtr<File> file(new File(context_, eulaAgreementPath_, FILE_WRITE));
  76. file->WriteInt(1);
  77. file->Close();
  78. }
  79. }
  80. // END LICENSE MANAGEMENT