BuildWindows.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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/Log.h>
  24. #include <Atomic/IO/FileSystem.h>
  25. #include <Atomic/Resource/ResourceCache.h>
  26. #include "../ToolSystem.h"
  27. #include "../ToolEnvironment.h"
  28. #include "../Project/Project.h"
  29. #include "../Assets/AssetDatabase.h"
  30. #include "BuildWindows.h"
  31. #include "BuildSystem.h"
  32. #include "BuildEvents.h"
  33. namespace ToolCore
  34. {
  35. BuildWindows::BuildWindows(Context * context, Project *project) : BuildBase(context, project, PLATFORMID_WINDOWS)
  36. {
  37. }
  38. BuildWindows::~BuildWindows()
  39. {
  40. }
  41. void BuildWindows::Initialize()
  42. {
  43. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  44. Project* project = tsystem->GetProject();
  45. Vector<String> defaultResourcePaths;
  46. GetDefaultResourcePaths(defaultResourcePaths);
  47. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  48. {
  49. AddResourceDir(defaultResourcePaths[i]);
  50. }
  51. BuildDefaultResourceEntries();
  52. // Include the project resources and cache separately
  53. AddProjectResourceDir(project->GetResourcePath());
  54. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  55. String cachePath = db->GetCachePath();
  56. AddProjectResourceDir(cachePath);
  57. BuildProjectResourceEntries();
  58. }
  59. bool BuildWindows::CheckIncludeResourceFile(const String& resourceDir, const String& fileName)
  60. {
  61. // #623 BEGIN TODO: Skip files that have a converted version in the cache
  62. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  63. String cachePath = db->GetCachePath();
  64. if (resourceDir != cachePath)
  65. {
  66. String ext = GetExtension(fileName);
  67. if (ext == ".jpg" || ext == ".png" || ext == ".tga")
  68. {
  69. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  70. String compressedPath = cachePath + "DDS/" + fileName + ".dds";
  71. if (fileSystem->FileExists(compressedPath))
  72. return false;
  73. }
  74. }
  75. // #623 END TODO
  76. return BuildBase::CheckIncludeResourceFile(resourceDir, fileName);
  77. }
  78. void BuildWindows::BuildManaged(const String& buildPath)
  79. {
  80. BuildLog("Building Managed Application");
  81. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  82. ToolSystem* toolSystem = GetSubsystem<ToolSystem>();
  83. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  84. Project* project = toolSystem->GetProject();
  85. StringVector results;
  86. StringVector filtered;
  87. fileSystem->ScanDir(results, tenv->GetAtomicNETCoreAssemblyDir(), "", SCAN_FILES, false);
  88. StringVector filterList;
  89. filterList.Push("AtomicIPCPlayer");
  90. filterList.Push(".pdb");
  91. filterList.Push("System.Collections.Immutable");
  92. filterList.Push("System.Reflection.Metadata");
  93. filterList.Push("ComponentTest");
  94. filterList.Push("AtomicNETService");
  95. StringVector::Iterator itr = results.Begin();
  96. while (itr != results.End())
  97. {
  98. unsigned i;
  99. for (i = 0; i < filterList.Size(); i++)
  100. {
  101. if (itr->Contains(filterList[i]))
  102. break;
  103. }
  104. if (i == filterList.Size())
  105. filtered.Push(*itr);
  106. itr++;
  107. }
  108. String playerBinary = tenv->GetAtomicNETManagedPlayerBinary();
  109. if (!BuildCopyFile(playerBinary, buildPath_ + "/AtomicPlayer.exe"))
  110. return;
  111. for (unsigned i = 0; i < filtered.Size(); i++)
  112. {
  113. String filename = filtered[i];
  114. if (!BuildCopyFile(tenv->GetAtomicNETCoreAssemblyDir() + filename, buildPath_ + "/" + filename))
  115. return;
  116. }
  117. if (!BuildCopyFile(project->GetResourcePath() + "/AtomicProject.dll", buildPath_ + "/AtomicProject.dll"));
  118. return;
  119. }
  120. void BuildWindows::BuildNative(const String& buildPath)
  121. {
  122. BuildLog("Building Native Application");
  123. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  124. String playerBinary = tenv->GetPlayerBinary();
  125. String d3d9dll = GetPath(playerBinary) + "/D3DCompiler_47.dll";
  126. if (!BuildCopyFile(playerBinary, buildPath_ + "/AtomicPlayer.exe"))
  127. return;
  128. if (!BuildCopyFile(d3d9dll, buildPath_ + "/D3DCompiler_47.dll"))
  129. return;
  130. }
  131. void BuildWindows::Build(const String& buildPath)
  132. {
  133. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  134. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  135. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  136. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  137. Project* project = tsystem->GetProject();
  138. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  139. BuildLog("Starting Windows Deployment");
  140. Initialize();
  141. if (!BuildClean(buildPath_))
  142. return;
  143. String rootSourceDir = tenv->GetRootSourceDir();
  144. if (!BuildCreateDirectory(buildPath_))
  145. return;
  146. if (!BuildCreateDirectory(buildPath_ + "/AtomicPlayer_Resources"))
  147. return;
  148. String resourcePackagePath = buildPath_ + "/AtomicPlayer_Resources/AtomicResources" + PAK_EXTENSION;
  149. GenerateResourcePackage(resourcePackagePath);
  150. if (buildFailed_)
  151. return;
  152. if (!BuildCreateDirectory(buildPath_ + "/Settings"))
  153. return;
  154. String engineJSON(GetSettingsDirectory() + "/Engine.json");
  155. if (fileSystem->FileExists(engineJSON))
  156. {
  157. if (!BuildCopyFile(engineJSON, buildPath_ + "/Settings/Engine.json"))
  158. return;
  159. }
  160. // TODO: Set project as managed and don't key off AtomicProject.dll
  161. if (fileSystem->FileExists(project->GetResourcePath() + "/AtomicProject.dll"))
  162. {
  163. BuildManaged(buildPath);
  164. }
  165. else
  166. {
  167. BuildNative(buildPath);
  168. }
  169. BuildLog("Windows Deployment Complete");
  170. buildSystem->BuildComplete(PLATFORMID_WINDOWS, buildPath_);
  171. }
  172. }