ToolSystem.cpp 2.2 KB

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