BuildBase.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/IO/Log.h>
  8. #include <Atomic/IO/FileSystem.h>
  9. #include "../Subprocess/SubprocessSystem.h"
  10. #include "../Project/Project.h"
  11. #include "../ToolEnvironment.h"
  12. #include "BuildEvents.h"
  13. #include "BuildBase.h"
  14. #include "ResourcePackager.h"
  15. namespace ToolCore
  16. {
  17. BuildBase::BuildBase(Context * context, Project* project, PlatformID platform) : Object(context),
  18. platformID_(platform),
  19. containsMDL_(false)
  20. {
  21. if (UseResourcePackager())
  22. resourcePackager_ = new ResourcePackager(context, this);
  23. project_ = project;
  24. }
  25. BuildBase::~BuildBase()
  26. {
  27. for (unsigned i = 0; i < resourceEntries_.Size(); i++)
  28. {
  29. delete resourceEntries_[i];
  30. }
  31. }
  32. void BuildBase::BuildLog(const String& message)
  33. {
  34. buildLog_.Push(message);
  35. }
  36. void BuildBase::BuildWarn(const String& warning)
  37. {
  38. buildWarnings_.Push(warning);
  39. }
  40. void BuildBase::BuildError(const String& error)
  41. {
  42. buildErrors_.Push(error);
  43. }
  44. void BuildBase::SendBuildFailure(const String& message)
  45. {
  46. VariantMap buildError;
  47. buildError[BuildComplete::P_PLATFORMID] = platformID_;
  48. buildError[BuildComplete::P_MESSAGE] = message;
  49. SendEvent(E_BUILDCOMPLETE, buildError);
  50. }
  51. void BuildBase::HandleSubprocessOutputEvent(StringHash eventType, VariantMap& eventData)
  52. {
  53. // E_SUBPROCESSOUTPUT
  54. const String& text = eventData[SubprocessOutput::P_TEXT].GetString();
  55. // convert to a build output event and forward to subscribers
  56. VariantMap buildOutputData;
  57. buildOutputData[BuildOutput::P_TEXT] = text;
  58. SendEvent(E_BUILDOUTPUT, buildOutputData);
  59. }
  60. void BuildBase::GetDefaultResourcePaths(Vector<String>& paths)
  61. {
  62. paths.Clear();
  63. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  64. paths.Push(AddTrailingSlash(tenv->GetCoreDataDir()));
  65. paths.Push(AddTrailingSlash(tenv->GetPlayerDataDir()));
  66. }
  67. void BuildBase::ScanResourceDirectory(const String& resourceDir)
  68. {
  69. Vector<String> fileNames;
  70. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  71. fileSystem->ScanDir(fileNames, resourceDir, "*.*", SCAN_FILES, true);
  72. for (unsigned i = 0; i < fileNames.Size(); i++)
  73. {
  74. const String& filename = fileNames[i];
  75. for (unsigned j = 0; j < resourceEntries_.Size(); j++)
  76. {
  77. const BuildResourceEntry* entry = resourceEntries_[j];
  78. if (entry->packagePath_ == filename)
  79. {
  80. BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
  81. continue;
  82. }
  83. }
  84. // TODO: Add additional filters
  85. if (GetExtension(filename) == ".psd")
  86. continue;
  87. BuildResourceEntry* newEntry = new BuildResourceEntry;
  88. // BEGIN LICENSE MANAGEMENT
  89. if (GetExtension(filename) == ".mdl")
  90. {
  91. containsMDL_ = true;
  92. }
  93. // END LICENSE MANAGEMENT
  94. newEntry->absolutePath_ = resourceDir + filename;
  95. newEntry->resourceDir_ = resourceDir;
  96. newEntry->packagePath_ = filename;
  97. resourceEntries_.Push(newEntry);
  98. //LOGINFOF("Adding resource: %s : %s", newEntry->absolutePath_.CString(), newEntry->packagePath_.CString());
  99. }
  100. }
  101. void BuildBase::BuildResourceEntries()
  102. {
  103. for (unsigned i = 0; i < resourceDirs_.Size(); i++)
  104. {
  105. ScanResourceDirectory(resourceDirs_[i]);
  106. }
  107. if (resourcePackager_.NotNull())
  108. {
  109. for (unsigned i = 0; i < resourceEntries_.Size(); i++)
  110. {
  111. BuildResourceEntry* entry = resourceEntries_[i];
  112. resourcePackager_->AddResourceEntry(entry);
  113. }
  114. }
  115. }
  116. void BuildBase::GenerateResourcePackage(const String& resourcePackagePath)
  117. {
  118. resourcePackager_->GeneratePackage(resourcePackagePath);
  119. }
  120. void BuildBase::AddResourceDir(const String& dir)
  121. {
  122. assert(!resourceDirs_.Contains(dir));
  123. resourceDirs_.Push(dir);
  124. }
  125. }