BuildWindows.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <Atomic/Core/StringUtils.h>
  23. #include <Atomic/IO/FileSystem.h>
  24. #include <Atomic/Resource/ResourceCache.h>
  25. #include "../ToolSystem.h"
  26. #include "../ToolEnvironment.h"
  27. #include "../Project/Project.h"
  28. #include "../Assets/AssetDatabase.h"
  29. #include "BuildWindows.h"
  30. #include "BuildSystem.h"
  31. #include "BuildEvents.h"
  32. namespace ToolCore
  33. {
  34. BuildWindows::BuildWindows(Context * context, Project *project) : BuildBase(context, project, PLATFORMID_WINDOWS)
  35. {
  36. }
  37. BuildWindows::~BuildWindows()
  38. {
  39. }
  40. void BuildWindows::Initialize()
  41. {
  42. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  43. Project* project = tsystem->GetProject();
  44. Vector<String> defaultResourcePaths;
  45. GetDefaultResourcePaths(defaultResourcePaths);
  46. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  47. {
  48. AddResourceDir(defaultResourcePaths[i]);
  49. }
  50. BuildDefaultResourceEntries();
  51. // Include the project resources and cache separately
  52. AddProjectResourceDir(project->GetResourcePath());
  53. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  54. String cachePath = db->GetCachePath();
  55. AddProjectResourceDir(cachePath);
  56. BuildProjectResourceEntries();
  57. }
  58. bool BuildWindows::CheckIncludeResourceFile(const String& resourceDir, const String& fileName)
  59. {
  60. // #623 BEGIN TODO: Skip files that have a converted version in the cache
  61. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  62. String cachePath = db->GetCachePath();
  63. if (resourceDir != cachePath)
  64. {
  65. String ext = GetExtension(fileName);
  66. if (ext == ".jpg" || ext == ".png" || ext == ".tga")
  67. {
  68. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  69. String compressedPath = cachePath + "DDS/" + fileName + ".dds";
  70. if (fileSystem->FileExists(compressedPath))
  71. return false;
  72. }
  73. else if (ext == ".psd")
  74. {
  75. return false;
  76. }
  77. }
  78. // #623 END TODO
  79. return BuildBase::CheckIncludeResourceFile(resourceDir, fileName);
  80. }
  81. void BuildWindows::BuildAtomicNET()
  82. {
  83. // AtomicNET
  84. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  85. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  86. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  87. Project* project = tsystem->GetProject();
  88. String projectResources = project->GetResourcePath();
  89. String assembliesPath = projectResources + "Assemblies/";
  90. // if no assemblies path, no need to install AtomicNET
  91. if (!fileSystem->DirExists(assembliesPath))
  92. return;
  93. Vector<String> results;
  94. fileSystem->ScanDir(results, assembliesPath, "*.dll", SCAN_FILES, true);
  95. // if no assembiles in Assemblies path, no need to install AtomicNET
  96. if (!results.Size())
  97. return;
  98. BuildLog("Building AtomicNET");
  99. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET");
  100. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic");
  101. fileSystem->CreateDir(buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies");
  102. fileSystem->CopyDir(tenv->GetNETCoreCLRAbsPath(), buildPath_ + "/AtomicPlayer_Resources/AtomicNET/CoreCLR");
  103. fileSystem->CopyDir(tenv->GetNETTPAPaths(), buildPath_ + "/AtomicPlayer_Resources/AtomicNET/Atomic/TPA");
  104. // Atomic Assemblies
  105. const String& assemblyLoadPaths = tenv->GetNETAssemblyLoadPaths();
  106. Vector<String> paths = assemblyLoadPaths.Split(';');
  107. for (unsigned i = 0; i < paths.Size(); i++)
  108. {
  109. Vector<String> loadResults;
  110. fileSystem->ScanDir(loadResults, paths[i], "*.dll", SCAN_FILES, true);
  111. for (unsigned j = 0; j < loadResults.Size(); j++)
  112. {
  113. String pathName, fileName, ext;
  114. SplitPath(loadResults[j], pathName, fileName, ext);
  115. if (fileName != "AtomicNETEngine")
  116. continue;
  117. fileSystem->Copy(paths[i] + "/" + loadResults[j], ToString("%s/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies/%s.dll", buildPath_.CString(), fileName.CString()));
  118. }
  119. }
  120. // Project assemblied
  121. for (unsigned i = 0; i < results.Size(); i++)
  122. {
  123. String pathName, fileName, ext;
  124. SplitPath(results[i], pathName, fileName, ext);
  125. fileSystem->Copy(assembliesPath + results[i], ToString("%s/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies/%s.dll", buildPath_.CString(), fileName.CString()));
  126. }
  127. }
  128. void BuildWindows::Build(const String& buildPath)
  129. {
  130. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  131. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  132. BuildLog("Starting Windows Deployment");
  133. Initialize();
  134. if (!BuildClean(buildPath_))
  135. return;
  136. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  137. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  138. String rootSourceDir = tenv->GetRootSourceDir();
  139. String playerBinary = tenv->GetPlayerBinary();
  140. String d3d9dll = GetPath(playerBinary) + "/D3DCompiler_47.dll";
  141. if (!BuildCreateDirectory(buildPath_))
  142. return;
  143. if (!BuildCreateDirectory(buildPath_ + "/AtomicPlayer_Resources"))
  144. return;
  145. String resourcePackagePath = buildPath_ + "/AtomicPlayer_Resources/AtomicResources" + PAK_EXTENSION;
  146. GenerateResourcePackage(resourcePackagePath);
  147. if (buildFailed_)
  148. return;
  149. if (!BuildCreateDirectory(buildPath_ + "/Settings"))
  150. return;
  151. String engineJSON(GetSettingsDirectory() + "/Engine.json");
  152. if (fileSystem->FileExists(engineJSON))
  153. {
  154. if (!BuildCopyFile(engineJSON, buildPath_ + "/Settings/Engine.json"))
  155. return;
  156. }
  157. if (!BuildCopyFile(playerBinary, buildPath_ + "/AtomicPlayer.exe"))
  158. return;
  159. if (!BuildCopyFile(d3d9dll, buildPath_ + "/D3DCompiler_47.dll"))
  160. return;
  161. BuildLog("Windows Deployment Complete");
  162. buildSystem->BuildComplete(PLATFORMID_WINDOWS, buildPath_);
  163. }
  164. }