BuildWindows.cpp 6.8 KB

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