ToolSystem.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <Atomic/Core/Context.h>
  2. #include <Atomic/IO/FileSystem.h>
  3. #include <Atomic/Resource/ResourceCache.h>
  4. #include "Platform/PlatformWeb.h"
  5. #include "Platform/PlatformMac.h"
  6. #include "Platform/PlatformWindows.h"
  7. #include "Net/CurlManager.h"
  8. #include "License/LicenseSystem.h"
  9. #include "Build/BuildSystem.h"
  10. #include "ToolSystem.h"
  11. #include "ToolEnvironment.h"
  12. #include "Project/Project.h"
  13. namespace ToolCore
  14. {
  15. ToolSystem::ToolSystem(Context* context) : Object(context),
  16. cli_(false)
  17. {
  18. context_->RegisterSubsystem(new CurlManager(context_));
  19. context_->RegisterSubsystem(new LicenseSystem(context_));
  20. context_->RegisterSubsystem(new BuildSystem(context_));
  21. // platform registration
  22. RegisterPlatform(new PlatformMac(context));
  23. RegisterPlatform(new PlatformWeb(context));
  24. RegisterPlatform(new PlatformWindows(context));
  25. }
  26. ToolSystem::~ToolSystem()
  27. {
  28. }
  29. bool ToolSystem::LoadProject(const String& fullpath)
  30. {
  31. String path = RemoveTrailingSlash(GetPath(AddTrailingSlash(fullpath)));
  32. ResourceCache* cache = GetSubsystem<ResourceCache>();
  33. cache->AddResourceDir(path, 0);
  34. String resourcePath = path;
  35. resourcePath += "/Resources";
  36. cache->AddResourceDir(resourcePath, 0);
  37. project_ = new Project(context_);
  38. project_->SetResourcePath(resourcePath);
  39. return project_->Load(fullpath);
  40. }
  41. void ToolSystem::SetCurrentPlatform(PlatformID platform)
  42. {
  43. if (platform == PLATFORMID_UNDEFINED)
  44. {
  45. currentPlatform_ = NULL;
  46. return;
  47. }
  48. if (!platforms_.Contains((unsigned) platform))
  49. return;
  50. currentPlatform_ = platforms_[(unsigned)platform];
  51. }
  52. Platform* ToolSystem::GetPlatformByID(PlatformID platform)
  53. {
  54. if (!platforms_.Contains((unsigned) platform))
  55. return NULL;
  56. return platforms_[(unsigned)platform];
  57. }
  58. Platform* ToolSystem::GetPlatformByName(const String& name)
  59. {
  60. HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
  61. while (itr != platforms_.End())
  62. {
  63. if ((*itr).second_->GetName().ToLower()== name.ToLower())
  64. return (*itr).second_;
  65. itr++;
  66. }
  67. return NULL;
  68. }
  69. Platform *ToolSystem::GetCurrentPlatform()
  70. {
  71. return currentPlatform_;
  72. }
  73. void ToolSystem::RegisterPlatform(Platform* platform)
  74. {
  75. platforms_.Insert(MakePair((unsigned)platform->GetPlatformID(), SharedPtr<Platform>(platform)));
  76. }
  77. }