BuildSystem.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <Atomic/Core/Context.h>
  6. #include <Atomic/Core/StringUtils.h>
  7. #include <Atomic/IO/FileSystem.h>
  8. #include <Atomic/IO/Log.h>
  9. #include "BuildSystem.h"
  10. #include "BuildMac.h"
  11. #include "BuildWindows.h"
  12. #include "BuildAndroid.h"
  13. #include "BuildWeb.h"
  14. #include "../AEEvents.h"
  15. #include "../AEEditor.h"
  16. namespace AtomicEditor
  17. {
  18. BuildSystem::BuildSystem(Context* context) :
  19. Object(context)
  20. {
  21. buildSettings_ = new BuildSettings(context);
  22. SubscribeToEvent(E_EDITORBUILD, HANDLER(BuildSystem, HandleEditorBuild));
  23. }
  24. BuildSystem::~BuildSystem()
  25. {
  26. }
  27. void BuildSystem::BuildComplete()
  28. {
  29. currentBuild_ = 0;
  30. }
  31. void BuildSystem::DoBuildMac(const String& buildPath)
  32. {
  33. currentBuild_ = SharedPtr<BuildBase>(new BuildMac(context_));
  34. currentBuild_->Build(buildPath);
  35. }
  36. void BuildSystem::DoBuildWindows(const String& buildPath)
  37. {
  38. currentBuild_ = SharedPtr<BuildBase>(new BuildWindows(context_));
  39. currentBuild_->Build(buildPath);
  40. }
  41. void BuildSystem::DoBuildAndroid(const String& buildPath)
  42. {
  43. currentBuild_ = SharedPtr<BuildBase>(new BuildAndroid(context_));
  44. currentBuild_->Build(buildPath);
  45. }
  46. void BuildSystem::DoBuildWeb(const String& buildPath)
  47. {
  48. currentBuild_ = SharedPtr<BuildBase>(new BuildWeb(context_));
  49. currentBuild_->Build(buildPath);
  50. }
  51. void BuildSystem::LoadBuildSettings(rapidjson::Value::Member* jobject)
  52. {
  53. buildSettings_->Load(jobject);
  54. }
  55. void BuildSystem::SaveBuildSettings(rapidjson::PrettyWriter<rapidjson::FileStream>& writer)
  56. {
  57. buildSettings_->Save(writer);
  58. }
  59. void BuildSystem::HandleEditorBuild(StringHash eventType, VariantMap& eventData)
  60. {
  61. using namespace EditorBuild;
  62. String buildPlatform = eventData[P_PLATFORM].GetString();
  63. String buildPath = eventData[P_BUILDPATH].GetString();
  64. if (buildPlatform == "Mac")
  65. {
  66. buildPath += "/AtomicPlayer.app";
  67. }
  68. Editor* editor = GetSubsystem<Editor>();
  69. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  70. // OK, we need to redo this as can't be removing folders like this
  71. if (buildPlatform != "Web") // removing the folder is screwing up the simple web server I am using
  72. {
  73. if (fileSystem->DirExists(buildPath) || fileSystem->FileExists(buildPath))
  74. {
  75. bool result;
  76. if (fileSystem->DirExists(buildPath))
  77. result = fileSystem->RemoveDir(buildPath, true);
  78. else
  79. result = fileSystem->Delete(buildPath);
  80. if (!result)
  81. {
  82. editor->PostModalError("Build Path Exists", ToString("The build path:\n\n%s\n\nalready exists and failed to be removed", buildPath.CString()));
  83. return;
  84. }
  85. }
  86. }
  87. if (buildPlatform == "Mac")
  88. {
  89. DoBuildMac(buildPath);
  90. }
  91. else if (buildPlatform == "Windows")
  92. {
  93. DoBuildWindows(buildPath);
  94. }
  95. else if (buildPlatform == "Android")
  96. {
  97. DoBuildAndroid(buildPath);
  98. }
  99. else if (buildPlatform == "HTML5")
  100. {
  101. DoBuildWeb(buildPath);
  102. }
  103. }
  104. }