BuildWindows.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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/Core/StringUtils.h>
  8. #include <Atomic/IO/FileSystem.h>
  9. #include <Atomic/Resource/ResourceCache.h>
  10. #include "../ToolSystem.h"
  11. #include "../ToolEnvironment.h"
  12. #include "../Project/Project.h"
  13. #include "../Assets/AssetDatabase.h"
  14. #include "BuildWindows.h"
  15. #include "BuildSystem.h"
  16. #include "BuildEvents.h"
  17. namespace ToolCore
  18. {
  19. BuildWindows::BuildWindows(Context * context, Project *project) : BuildBase(context, project, PLATFORMID_WINDOWS)
  20. {
  21. }
  22. BuildWindows::~BuildWindows()
  23. {
  24. }
  25. void BuildWindows::Initialize()
  26. {
  27. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  28. Project* project = tsystem->GetProject();
  29. Vector<String> defaultResourcePaths;
  30. GetDefaultResourcePaths(defaultResourcePaths);
  31. String projectResources = project->GetResourcePath();
  32. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  33. {
  34. AddResourceDir(defaultResourcePaths[i]);
  35. }
  36. // TODO: smart filtering of cache
  37. AddResourceDir(project->GetProjectPath() + "Cache/");
  38. AddResourceDir(projectResources);
  39. BuildResourceEntries();
  40. }
  41. bool BuildWindows::CheckIncludeResourceFile(const String& resourceDir, const String& fileName)
  42. {
  43. // #623 BEGIN TODO: Skip files that have a converted version in the cache
  44. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  45. String cachePath = db->GetCachePath();
  46. if (resourceDir != cachePath)
  47. {
  48. String ext = GetExtension(fileName);
  49. if (ext == ".jpg" || ext == ".png" || ext == ".tga")
  50. {
  51. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  52. String compressedPath = cachePath + "DDS/" + fileName + ".dds";
  53. if (fileSystem->FileExists(compressedPath))
  54. return false;
  55. }
  56. }
  57. // #623 END TODO
  58. return BuildBase::CheckIncludeResourceFile(resourceDir, fileName);
  59. }
  60. void BuildWindows::BuildAtomicNET()
  61. {
  62. // AtomicNET
  63. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  64. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  65. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  66. Project* project = tsystem->GetProject();
  67. String projectResources = project->GetResourcePath();
  68. String assembliesPath = projectResources + "Assemblies/";
  69. // if no assemblies path, no need to install AtomicNET
  70. if (!fileSystem->DirExists(assembliesPath))
  71. return;
  72. Vector<String> results;
  73. fileSystem->ScanDir(results, assembliesPath, "*.dll", SCAN_FILES, true);
  74. // if no assembiles in Assemblies path, no need to install AtomicNET
  75. if (!results.Size())
  76. return;
  77. BuildLog("Building AtomicNET");
  78. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET");
  79. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic");
  80. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies");
  81. fileSystem->CopyDir(tenv->GetNETCoreCLRAbsPath(), buildPath_ + "/AtomicPlayer_Resources/AtomicNET/CoreCLR");
  82. fileSystem->CopyDir(tenv->GetNETTPAPaths(), buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic/TPA");
  83. // Atomic Assemblies
  84. const String& assemblyLoadPaths = tenv->GetNETAssemblyLoadPaths();
  85. Vector<String> paths = assemblyLoadPaths.Split(';');
  86. for (unsigned i = 0; i < paths.Size(); i++)
  87. {
  88. Vector<String> loadResults;
  89. fileSystem->ScanDir(loadResults, paths[i], "*.dll", SCAN_FILES, true);
  90. for (unsigned j = 0; j < loadResults.Size(); j++)
  91. {
  92. String pathName, fileName, ext;
  93. SplitPath(loadResults[j], pathName, fileName, ext);
  94. if (fileName != "AtomicNETEngine")
  95. continue;
  96. fileSystem->Copy(paths[i] + "/" + loadResults[j], ToString("%s/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies/%s.dll", buildPath_.CString(), fileName.CString()));
  97. }
  98. }
  99. // Project assemblied
  100. for (unsigned i = 0; i < results.Size(); i++)
  101. {
  102. String pathName, fileName, ext;
  103. SplitPath(results[i], pathName, fileName, ext);
  104. fileSystem->Copy(assembliesPath + results[i], ToString("%s/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies/%s.dll", buildPath_.CString(), fileName.CString()));
  105. }
  106. }
  107. void BuildWindows::Build(const String& buildPath)
  108. {
  109. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  110. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  111. BuildLog("Starting Windows Deployment");
  112. Initialize();
  113. if (!BuildClean(buildPath_))
  114. return;
  115. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  116. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  117. String rootSourceDir = tenv->GetRootSourceDir();
  118. String playerBinary = tenv->GetPlayerBinary();
  119. String d3d9dll = GetPath(playerBinary) + "/D3DCompiler_47.dll";
  120. if (!BuildCreateDirectory(buildPath_))
  121. return;
  122. if (!BuildCreateDirectory(buildPath_ + "/AtomicPlayer_Resources"))
  123. return;
  124. String resourcePackagePath = buildPath_ + "/AtomicPlayer_Resources/AtomicResources" + PAK_EXTENSION;
  125. GenerateResourcePackage(resourcePackagePath);
  126. if (buildFailed_)
  127. return;
  128. if (!BuildCreateDirectory(buildPath_ + "/Settings"))
  129. return;
  130. String engineJSON(GetSettingsDirectory() + "/Engine.json");
  131. if (fileSystem->FileExists(engineJSON))
  132. {
  133. if (!BuildCopyFile(engineJSON, buildPath_ + "/Settings/Engine.json"))
  134. return;
  135. }
  136. if (!BuildCopyFile(playerBinary, buildPath_ + "/AtomicPlayer.exe"))
  137. return;
  138. if (!BuildCopyFile(d3d9dll, buildPath_ + "/D3DCompiler_47.dll"))
  139. return;
  140. BuildAtomicNET();
  141. BuildLog("Windows Deployment Complete");
  142. buildSystem->BuildComplete(PLATFORMID_WINDOWS, buildPath_);
  143. }
  144. }