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