BuildWeb.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <Atomic/Core/StringUtils.h>
  5. #include <Atomic/IO/FileSystem.h>
  6. #include <Atomic/IO/File.h>
  7. #include "../ToolSystem.h"
  8. #include "../ToolEnvironment.h"
  9. #include "../Project/Project.h"
  10. #include "BuildEvents.h"
  11. #include "BuildSystem.h"
  12. #include "BuildWeb.h"
  13. namespace ToolCore
  14. {
  15. BuildWeb::BuildWeb(Context* context, Project* project) : BuildBase(context, project, PLATFORMID_WEB)
  16. {
  17. }
  18. BuildWeb::~BuildWeb()
  19. {
  20. }
  21. void BuildWeb::Initialize()
  22. {
  23. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  24. Project* project = tsystem->GetProject();
  25. Vector<String> defaultResourcePaths;
  26. GetDefaultResourcePaths(defaultResourcePaths);
  27. String projectResources = project->GetResourcePath();
  28. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  29. {
  30. AddResourceDir(defaultResourcePaths[i]);
  31. }
  32. // TODO: smart filtering of cache
  33. AddResourceDir(project->GetProjectPath() + "Cache/");
  34. AddResourceDir(projectResources);
  35. BuildResourceEntries();
  36. }
  37. void BuildWeb::Build(const String& buildPath)
  38. {
  39. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  40. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  41. VariantMap buildOutput;
  42. buildOutput[BuildOutput::P_TEXT] = "\n\n<color #D4FB79>Starting Web Deployment</color>\n\n";
  43. SendEvent(E_BUILDOUTPUT, buildOutput);
  44. Initialize();
  45. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  46. if (fileSystem->DirExists(buildPath_))
  47. fileSystem->RemoveDir(buildPath_, true);
  48. String dataPath = tenv->GetToolDataDir();
  49. String buildSourceDir = dataPath + "Deployment/Web";
  50. fileSystem->CreateDir(buildPath_);
  51. String resourcePackagePath = buildPath_ + "/AtomicResources.data";
  52. GenerateResourcePackage(resourcePackagePath);
  53. fileSystem->Copy(buildSourceDir + "/AtomicPlayer.html", buildPath_ + "/AtomicPlayer.html");
  54. fileSystem->Copy(buildSourceDir + "/AtomicPlayer.html.mem", buildPath_ + "/AtomicPlayer.html.mem");
  55. fileSystem->Copy(buildSourceDir + "/AtomicPlayer.js", buildPath_ + "/AtomicPlayer.js");
  56. fileSystem->Copy(buildSourceDir + "/AtomicLoader.js", buildPath_ + "/AtomicLoader.js");
  57. fileSystem->Copy(buildSourceDir + "/index.html", buildPath_ + "/index.html");
  58. fileSystem->Copy(buildSourceDir + "/Atomic_Logo_Header.png", buildPath_ + "/Atomic_Logo_Header.png");
  59. File file(context_, buildSourceDir + "/AtomicResources_js.template", FILE_READ);
  60. unsigned size = file.GetSize();
  61. SharedArrayPtr<char> buffer(new char[size + 1]);
  62. file.Read(buffer.Get(), size);
  63. buffer[size] = '\0';
  64. String resourcejs = (const char*) buffer.Get();
  65. file.Close();
  66. file.Open(buildPath_ + "/AtomicResources.data", FILE_READ);
  67. int rsize = (int) file.GetSize();
  68. file.Close();
  69. String request;
  70. request.AppendWithFormat("new DataRequest(0, %i, 0, 0).open('GET', '/AtomicResources.pak');", rsize);
  71. resourcejs.Replace("$$REMOTE_PACKAGE_SIZE$$", ToString("%i", rsize));
  72. resourcejs.Replace("$$ATOMIC_RESOURCES_DATA_REQUEST$$", request);
  73. file.Open(buildPath_ + "/AtomicResources.js", FILE_WRITE);
  74. file.Write(resourcejs.CString(), resourcejs.Length());
  75. file.Close();
  76. buildOutput[BuildOutput::P_TEXT] = "\n\n<color #D4FB79>Web Deployment Complete</color>\n\n";
  77. SendEvent(E_BUILDOUTPUT, buildOutput);
  78. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  79. buildSystem->BuildComplete(PLATFORMID_WEB, buildPath_);
  80. //fileSystem->SystemCommandAsync("/Applications/Firefox.app/Contents/MacOS/firefox");
  81. }
  82. }