BuildWindows.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. String projectResources = project->GetResourcePath();
  47. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  48. {
  49. AddResourceDir(defaultResourcePaths[i]);
  50. }
  51. // TODO: smart filtering of cache
  52. AddResourceDir(project->GetProjectPath() + "Cache/");
  53. AddResourceDir(projectResources);
  54. BuildResourceEntries();
  55. }
  56. bool BuildWindows::CheckIncludeResourceFile(const String& resourceDir, const String& fileName)
  57. {
  58. // #623 BEGIN TODO: Skip files that have a converted version in the cache
  59. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  60. String cachePath = db->GetCachePath();
  61. if (resourceDir != cachePath)
  62. {
  63. String ext = GetExtension(fileName);
  64. if (ext == ".jpg" || ext == ".png" || ext == ".tga")
  65. {
  66. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  67. String compressedPath = cachePath + "DDS/" + fileName + ".dds";
  68. if (fileSystem->FileExists(compressedPath))
  69. return false;
  70. }
  71. }
  72. // #623 END TODO
  73. return BuildBase::CheckIncludeResourceFile(resourceDir, fileName);
  74. }
  75. void BuildWindows::Build(const String& buildPath)
  76. {
  77. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  78. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  79. BuildLog("Starting Windows Deployment");
  80. Initialize();
  81. if (!BuildClean(buildPath_))
  82. return;
  83. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  84. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  85. String rootSourceDir = tenv->GetRootSourceDir();
  86. String playerBinary = tenv->GetPlayerBinary();
  87. String d3d9dll = GetPath(playerBinary) + "/D3DCompiler_47.dll";
  88. if (!BuildCreateDirectory(buildPath_))
  89. return;
  90. if (!BuildCreateDirectory(buildPath_ + "/AtomicPlayer_Resources"))
  91. return;
  92. String resourcePackagePath = buildPath_ + "/AtomicPlayer_Resources/AtomicResources" + PAK_EXTENSION;
  93. GenerateResourcePackage(resourcePackagePath);
  94. if (buildFailed_)
  95. return;
  96. if (!BuildCreateDirectory(buildPath_ + "/Settings"))
  97. return;
  98. String engineJSON(GetSettingsDirectory() + "/Engine.json");
  99. if (fileSystem->FileExists(engineJSON))
  100. {
  101. if (!BuildCopyFile(engineJSON, buildPath_ + "/Settings/Engine.json"))
  102. return;
  103. }
  104. if (!BuildCopyFile(playerBinary, buildPath_ + "/AtomicPlayer.exe"))
  105. return;
  106. if (!BuildCopyFile(d3d9dll, buildPath_ + "/D3DCompiler_47.dll"))
  107. return;
  108. BuildLog("Windows Deployment Complete");
  109. buildSystem->BuildComplete(PLATFORMID_WINDOWS, buildPath_);
  110. }
  111. }