BuildBase.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <Atomic/IO/Log.h>
  6. #include <Atomic/IO/FileSystem.h>
  7. #include "BuildBase.h"
  8. #include "ResourcePackager.h"
  9. namespace ToolCore
  10. {
  11. BuildBase::BuildBase(Context * context) : Object(context), containsMDL_(false)
  12. {
  13. if (UseResourcePackager())
  14. resourcePackager_ = new ResourcePackager(context, this);
  15. BuildLog("Build Started");
  16. }
  17. BuildBase::~BuildBase()
  18. {
  19. for (unsigned i = 0; i < resourceEntries_.Size(); i++)
  20. {
  21. delete resourceEntries_[i];
  22. }
  23. }
  24. void BuildBase::BuildLog(const String& message)
  25. {
  26. buildLog_.Push(message);
  27. }
  28. void BuildBase::BuildWarn(const String& warning)
  29. {
  30. buildWarnings_.Push(warning);
  31. }
  32. void BuildBase::BuildError(const String& error)
  33. {
  34. buildErrors_.Push(error);
  35. }
  36. void BuildBase::ScanResourceDirectory(const String& resourceDir)
  37. {
  38. Vector<String> fileNames;
  39. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  40. fileSystem->ScanDir(fileNames, resourceDir, "*.*", SCAN_FILES, true);
  41. for (unsigned i = 0; i < fileNames.Size(); i++)
  42. {
  43. const String& filename = fileNames[i];
  44. for (unsigned j = 0; j < resourceEntries_.Size(); j++)
  45. {
  46. const BuildResourceEntry* entry = resourceEntries_[j];
  47. if (entry->packagePath_ == filename)
  48. {
  49. BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
  50. continue;
  51. }
  52. }
  53. BuildResourceEntry* newEntry = new BuildResourceEntry;
  54. // BEGIN LICENSE MANAGEMENT
  55. if (GetExtension(filename) == ".mdl")
  56. {
  57. containsMDL_ = true;
  58. }
  59. // END LICENSE MANAGEMENT
  60. newEntry->absolutePath_ = resourceDir + filename;
  61. newEntry->packagePath_ = filename;
  62. newEntry->resourceDir_ = resourceDir;
  63. resourceEntries_.Push(newEntry);
  64. }
  65. }
  66. void BuildBase::BuildResourceEntries()
  67. {
  68. for (unsigned i = 0; i < resourceDirs_.Size(); i++)
  69. {
  70. ScanResourceDirectory(resourceDirs_[i]);
  71. }
  72. if (resourcePackager_.NotNull())
  73. {
  74. for (unsigned i = 0; i < resourceEntries_.Size(); i++)
  75. {
  76. BuildResourceEntry* entry = resourceEntries_[i];
  77. resourcePackager_->AddResourceEntry(entry);
  78. }
  79. }
  80. }
  81. void BuildBase::GenerateResourcePackage(const String& resourcePackagePath)
  82. {
  83. resourcePackager_->GeneratePackage(resourcePackagePath);
  84. }
  85. void BuildBase::AddResourceDir(const String& dir)
  86. {
  87. assert(!resourceDirs_.Contains(dir));
  88. resourceDirs_.Push(dir);
  89. }
  90. }