NETProjectSystem.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. #include <Poco/Environment.h>
  23. #include <Atomic/Core/CoreEvents.h>
  24. #include <Atomic/IO/Log.h>
  25. #include <Atomic/IO/FileSystem.h>
  26. #include <Atomic/Resource/ResourceEvents.h>
  27. #include "../ToolSystem.h"
  28. #include "../Assets/AssetEvents.h"
  29. #include "../Project/Project.h"
  30. #include "../Project/ProjectEvents.h"
  31. #include "NETProjectGen.h"
  32. #include "NETBuildSystem.h"
  33. #include "NETProjectSystem.h"
  34. namespace ToolCore
  35. {
  36. NETProjectSystem::NETProjectSystem(Context* context) :
  37. Object(context)
  38. {
  39. Initialize();
  40. }
  41. NETProjectSystem::~NETProjectSystem()
  42. {
  43. }
  44. void NETProjectSystem::Clear()
  45. {
  46. quietPeriod_ = 0.0f;
  47. solutionPath_.Clear();
  48. projectAssemblyPath_.Clear();
  49. solutionDirty_ = false;
  50. projectAssemblyDirty_ = false;
  51. }
  52. void NETProjectSystem::HandleUpdate(StringHash eventType, VariantMap& eventData)
  53. {
  54. using namespace Update;
  55. float delta = eventData[P_TIMESTEP].GetFloat();
  56. quietPeriod_ -= delta;
  57. if (quietPeriod_ < 0.0f)
  58. quietPeriod_ = 0.0f;
  59. if (quietPeriod_ > 0.0f)
  60. return;
  61. if (solutionDirty_)
  62. {
  63. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  64. Project* project = tsystem->GetProject();
  65. SharedPtr<NETProjectGen> gen(new NETProjectGen(context_));
  66. gen->SetScriptPlatform("WINDOWS");
  67. if (!gen->LoadProject(project))
  68. {
  69. return;
  70. }
  71. if (!gen->Generate())
  72. {
  73. return;
  74. }
  75. solutionDirty_ = false;
  76. }
  77. if (projectAssemblyDirty_)
  78. {
  79. using namespace NETBuildAtomicProject;
  80. VariantMap eventData;
  81. Project* project = GetSubsystem<ToolSystem>()->GetProject();
  82. eventData[P_PROJECT] = project;
  83. // We need to rebuild the project assembly
  84. SendEvent(E_NETBUILDATOMICPROJECT, eventData);
  85. projectAssemblyDirty_ = false;
  86. }
  87. }
  88. void NETProjectSystem::HandleProjectLoaded(StringHash eventType, VariantMap& eventData)
  89. {
  90. using namespace ProjectLoaded;
  91. String projectPath = eventData[P_PROJECTPATH].GetString();
  92. if (GetExtension(projectPath) == ".atomic")
  93. projectPath = GetParentPath(projectPath);
  94. solutionPath_ = AddTrailingSlash(projectPath) + "AtomicNET/Solution/AtomicProject.sln";
  95. projectAssemblyPath_ = AddTrailingSlash(projectPath) + "Resource/AtomicProject.dll";
  96. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  97. // if the solution or project assemblies don't exist mark as dirty
  98. if (!fileSystem->FileExists(solutionPath_))
  99. solutionDirty_ = true;
  100. if (!fileSystem->FileExists(projectAssemblyPath_))
  101. projectAssemblyDirty_ = true;
  102. }
  103. void NETProjectSystem::HandleProjectUnloaded(StringHash eventType, VariantMap& eventData)
  104. {
  105. Clear();
  106. }
  107. void NETProjectSystem::HandleFileChanged(StringHash eventType, VariantMap& eventData)
  108. {
  109. }
  110. void NETProjectSystem::HandleResourceAdded(StringHash eventType, VariantMap& eventData)
  111. {
  112. }
  113. void NETProjectSystem::HandleResourceRemoved(StringHash eventType, VariantMap& eventData)
  114. {
  115. }
  116. void NETProjectSystem::HandleAssetRenamed(StringHash eventType, VariantMap& eventData)
  117. {
  118. }
  119. void NETProjectSystem::HandleAssetMoved(StringHash eventType, VariantMap& eventData)
  120. {
  121. }
  122. void NETProjectSystem::Initialize()
  123. {
  124. Clear();
  125. SubscribeToEvent(E_UPDATE, HANDLER(NETProjectSystem, HandleUpdate));
  126. SubscribeToEvent(E_PROJECTLOADED, HANDLER(NETProjectSystem, HandleProjectLoaded));
  127. SubscribeToEvent(E_PROJECTUNLOADED, HANDLER(NETProjectSystem, HandleProjectUnloaded));
  128. SubscribeToEvent(E_FILECHANGED, HANDLER(NETProjectSystem, HandleFileChanged));
  129. SubscribeToEvent(E_RESOURCEADDED, HANDLER(NETProjectSystem, HandleResourceAdded));
  130. SubscribeToEvent(E_RESOURCEREMOVED, HANDLER(NETProjectSystem, HandleResourceRemoved));
  131. SubscribeToEvent(E_ASSETRENAMED, HANDLER(NETProjectSystem, HandleAssetRenamed));
  132. SubscribeToEvent(E_ASSETMOVED, HANDLER(NETProjectSystem, HandleAssetMoved));
  133. #ifdef ATOMIC_PLATFORM_WINDOWS
  134. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  135. // Query for Visual Studio 2015 path
  136. String visualStudioPath_ = Poco::Environment::get("VS140COMNTOOLS").c_str();
  137. if (visualStudioPath_.Length())
  138. {
  139. visualStudioPath_.Replace("Tools\\", "IDE\\devenv.exe");
  140. if (!fileSystem->FileExists(visualStudioPath_))
  141. visualStudioPath_.Clear();
  142. }
  143. }
  144. #endif
  145. }