BuildWeb.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/IO/FileSystem.h>
  5. #include <Atomic/IO/File.h>
  6. #include "../ToolSystem.h"
  7. #include "../Project/Project.h"
  8. #include "BuildSystem.h"
  9. #include "BuildWeb.h"
  10. namespace ToolCore
  11. {
  12. BuildWeb::BuildWeb(Context* context, Project* project) : BuildBase(context, project)
  13. {
  14. }
  15. BuildWeb::~BuildWeb()
  16. {
  17. }
  18. void BuildWeb::Initialize()
  19. {
  20. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  21. Project* project = tsystem->GetProject();
  22. String dataPath = tsystem->GetDataPath();
  23. String projectResources = project->GetResourcePath();
  24. String coreDataFolder = dataPath + "Atomic/Resources/CoreData/";
  25. AddResourceDir(coreDataFolder);
  26. AddResourceDir(projectResources);
  27. BuildResourceEntries();
  28. }
  29. void BuildWeb::Build(const String& buildPath)
  30. {
  31. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  32. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  33. Initialize();
  34. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  35. if (fileSystem->DirExists(buildPath_))
  36. fileSystem->RemoveDir(buildPath_, true);
  37. String dataPath = tsystem->GetDataPath();
  38. String buildSourceDir = dataPath + "Atomic/Deployment/Web";
  39. fileSystem->CreateDir(buildPath_);
  40. String resourcePackagePath = buildPath_ + "/AtomicResources.data";
  41. GenerateResourcePackage(resourcePackagePath);
  42. fileSystem->Copy(buildSourceDir + "/AtomicPlayer.html", buildPath_ + "/AtomicPlayer.html");
  43. fileSystem->Copy(buildSourceDir + "/AtomicPlayer.js", buildPath_ + "/AtomicPlayer.js");
  44. File file(context_, buildSourceDir + "/AtomicResources_js.template", FILE_READ);
  45. unsigned size = file.GetSize();
  46. SharedArrayPtr<char> buffer(new char[size + 1]);
  47. file.Read(buffer.Get(), size);
  48. buffer[size] = '\0';
  49. String resourcejs = (const char*) buffer.Get();
  50. file.Close();
  51. file.Open(buildPath_ + "/AtomicResources.data", FILE_READ);
  52. int rsize = (int) file.GetSize();
  53. file.Close();
  54. String request;
  55. request.AppendWithFormat("new DataRequest(0, %i, 0, 0).open('GET', '/AtomicResources.pak');", rsize);
  56. resourcejs.Replace("$$ATOMIC_RESOURCES_DATA_REQUEST$$", request);
  57. file.Open(buildPath_ + "/AtomicResources.js", FILE_WRITE);
  58. file.Write(resourcejs.CString(), resourcejs.Length());
  59. file.Close();
  60. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  61. buildSystem->BuildComplete(PLATFORMID_WEB, buildPath_);
  62. //fileSystem->SystemCommandAsync("/Applications/Firefox.app/Contents/MacOS/firefox");
  63. }
  64. }