ToolSystem.cpp 2.3 KB

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