BuildBase.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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 <Poco/File.h>
  23. #include <Atomic/IO/Log.h>
  24. #include <Atomic/IO/FileSystem.h>
  25. #include <Atomic/Resource/JSONFile.h>
  26. #include "../Subprocess/SubprocessSystem.h"
  27. #include "../Project/Project.h"
  28. #include "../ToolEnvironment.h"
  29. #include "../Assets/Asset.h"
  30. #include "../Assets/AssetDatabase.h"
  31. #include "../Import/ImportConfig.h"
  32. #include "BuildSystem.h"
  33. #include "BuildEvents.h"
  34. #include "BuildBase.h"
  35. #include "ResourcePackager.h"
  36. #include "AssetBuildConfig.h"
  37. namespace ToolCore
  38. {
  39. BuildBase::BuildBase(Context * context, Project* project, PlatformID platform) : Object(context),
  40. platformID_(platform),
  41. project_(project),
  42. containsMDL_(false),
  43. buildFailed_(false),
  44. assetBuildTag_(String::EMPTY),
  45. fileIncludedResourcesLog_(nullptr),
  46. resourcesOnly_(false),
  47. verbose_(false)
  48. {
  49. if (UseResourcePackager())
  50. resourcePackager_ = new ResourcePackager(context, this);
  51. fileIncludedResourcesLog_ = new File(context_, "BuildIncludedResources.log", Atomic::FILE_WRITE);
  52. ReadAssetBuildConfig();
  53. }
  54. BuildBase::~BuildBase()
  55. {
  56. for (unsigned i = 0; i < resourceEntries_.Size(); i++)
  57. {
  58. delete resourceEntries_[i];
  59. }
  60. fileIncludedResourcesLog_->Close();
  61. delete fileIncludedResourcesLog_;
  62. }
  63. #ifdef ATOMIC_PLATFORM_WINDOWS
  64. bool BuildBase::BuildClean(const String& path)
  65. {
  66. if (buildFailed_)
  67. {
  68. ATOMIC_LOGERRORF("BuildBase::BuildClean - Attempt to clean directory of failed build, %s", path.CString());
  69. return false;
  70. }
  71. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  72. if (!fileSystem->DirExists(path))
  73. return true;
  74. // On Windows, do a little dance with the folder to avoid issues
  75. // with deleting folder and immediately recreating it
  76. String pathName, fileName, ext;
  77. SplitPath(path, pathName, fileName, ext);
  78. pathName = AddTrailingSlash(pathName);
  79. unsigned i = 0;
  80. while (true)
  81. {
  82. String newPath = ToString("%s%s_Temp_%u", pathName.CString(), fileName.CString(), i++);
  83. if (!fileSystem->DirExists(newPath))
  84. {
  85. if (!MoveFileExW(GetWideNativePath(path).CString(), GetWideNativePath(newPath).CString(), MOVEFILE_WRITE_THROUGH))
  86. {
  87. FailBuild(ToString("BuildBase::BuildClean: Unable to move directory %s -> ", path.CString(), newPath.CString()));
  88. return false;
  89. }
  90. // Remove the moved directory
  91. return BuildRemoveDirectory(newPath);
  92. }
  93. else
  94. {
  95. ATOMIC_LOGWARNINGF("BuildBase::BuildClean - temp build folder exists, removing: %s", newPath.CString());
  96. fileSystem->RemoveDir(newPath, true);
  97. }
  98. if (i == 255)
  99. {
  100. FailBuild(ToString("BuildBase::BuildClean: Unable to move directory ( i == 255) %s -> ", path.CString(), newPath.CString()));
  101. return false;
  102. }
  103. }
  104. return false;
  105. }
  106. #else
  107. bool BuildBase::BuildClean(const String& path)
  108. {
  109. return BuildRemoveDirectory(path);
  110. }
  111. #endif
  112. bool BuildBase::BuildCreateDirectory(const String& path)
  113. {
  114. if (buildFailed_)
  115. {
  116. ATOMIC_LOGERRORF("BuildBase::BuildCreateDirectory - Attempt to create directory of failed build, %s", path.CString());
  117. return false;
  118. }
  119. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  120. if (fileSystem->DirExists(path))
  121. return true;
  122. bool result = fileSystem->CreateDir(path);
  123. if (!result)
  124. {
  125. FailBuild(ToString("BuildBase::BuildCreateDirectory: Unable to create directory %s", path.CString()));
  126. return false;
  127. }
  128. return true;
  129. }
  130. bool BuildBase::BuildCopyFile(const String& srcFileName, const String& destFileName)
  131. {
  132. if (buildFailed_)
  133. {
  134. ATOMIC_LOGERRORF("BuildBase::BuildCopyFile - Attempt to copy file of failed build, %s", srcFileName.CString());
  135. return false;
  136. }
  137. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  138. bool result = fileSystem->Copy(srcFileName, destFileName);
  139. if (!result)
  140. {
  141. FailBuild(ToString("BuildBase::BuildCopyFile: Unable to copy file %s -> %s", srcFileName.CString(), destFileName.CString()));
  142. return false;
  143. }
  144. return true;
  145. }
  146. bool BuildBase::BuildCopyDir(const String& srcDir, const String& destDir)
  147. {
  148. if (buildFailed_)
  149. {
  150. ATOMIC_LOGERRORF("BuildBase::BuildCopyDir - Attempt to copy directory of failed build, %s", srcDir.CString());
  151. return false;
  152. }
  153. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  154. bool result = fileSystem->CopyDir(srcDir, destDir);
  155. if (!result)
  156. {
  157. FailBuild(ToString("BuildBase::BuildCopyDir: Unable to copy dir %s -> %s", srcDir.CString(), destDir.CString()));
  158. return false;
  159. }
  160. return true;
  161. }
  162. bool BuildBase::CheckIncludeResourceFile(const String & resourceDir, const String & fileName)
  163. {
  164. return (GetExtension(fileName) != ".psd");
  165. }
  166. bool BuildBase::BuildRemoveDirectory(const String& path)
  167. {
  168. if (buildFailed_)
  169. {
  170. ATOMIC_LOGERRORF("BuildBase::BuildRemoveDirectory - Attempt to remove directory of failed build, %s", path.CString());
  171. return false;
  172. }
  173. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  174. if (!fileSystem->DirExists(path))
  175. return true;
  176. #ifdef ATOMIC_PLATFORM_LINUX
  177. bool result = true; // fileSystem->RemoveDir(path, true); crashes on linux
  178. Poco::File dirs(buildPath_.CString());
  179. dirs.remove(true);
  180. if (fileSystem->DirExists(buildPath_))
  181. result = false;
  182. #else
  183. bool result = fileSystem->RemoveDir(path, true);
  184. #endif
  185. if (!result)
  186. {
  187. FailBuild(ToString("BuildBase::BuildRemoveDirectory: Unable to remove directory %s", path.CString()));
  188. return false;
  189. }
  190. return true;
  191. }
  192. void BuildBase::BuildLog(const String& message, bool sendEvent)
  193. {
  194. buildLog_.Push(message);
  195. if (autoLog_)
  196. ATOMIC_LOGINFO(message);
  197. if (sendEvent)
  198. {
  199. String colorMsg = ToString("<color #D4FB79>%s</color>\n", message.CString());
  200. VariantMap buildOutput;
  201. buildOutput[BuildOutput::P_TEXT] = colorMsg;
  202. SendEvent(E_BUILDOUTPUT, buildOutput);
  203. }
  204. }
  205. void BuildBase::BuildWarn(const String& warning, bool sendEvent)
  206. {
  207. buildWarnings_.Push(warning);
  208. if (autoLog_)
  209. ATOMIC_LOGWARNING(warning);
  210. if (sendEvent)
  211. {
  212. String colorMsg = ToString("<color #FFFF00>%s</color>\n", warning.CString());
  213. VariantMap buildOutput;
  214. buildOutput[BuildOutput::P_TEXT] = colorMsg;
  215. SendEvent(E_BUILDOUTPUT, buildOutput);
  216. }
  217. }
  218. void BuildBase::BuildError(const String& error, bool sendEvent)
  219. {
  220. buildErrors_.Push(error);
  221. if (autoLog_)
  222. ATOMIC_LOGERROR(error);
  223. if (sendEvent)
  224. {
  225. String colorMsg = ToString("<color #FF0000>%s</color>\n", error.CString());
  226. VariantMap buildOutput;
  227. buildOutput[BuildOutput::P_TEXT] = colorMsg;
  228. SendEvent(E_BUILDOUTPUT, buildOutput);
  229. }
  230. }
  231. void BuildBase::FailBuild(const String& message)
  232. {
  233. if (buildFailed_)
  234. {
  235. ATOMIC_LOGERRORF("BuildBase::FailBuild - Attempt to fail already failed build: %s", message.CString());
  236. return;
  237. }
  238. buildFailed_ = true;
  239. BuildError(message);
  240. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  241. buildSystem->BuildComplete(platformID_, buildPath_, false, message);
  242. }
  243. void BuildBase::HandleSubprocessOutputEvent(StringHash eventType, VariantMap& eventData)
  244. {
  245. // E_SUBPROCESSOUTPUT
  246. const String& text = eventData[SubprocessOutput::P_TEXT].GetString();
  247. // convert to a build output event and forward to subscribers
  248. VariantMap buildOutputData;
  249. buildOutputData[BuildOutput::P_TEXT] = text;
  250. SendEvent(E_BUILDOUTPUT, buildOutputData);
  251. }
  252. void BuildBase::GetDefaultResourcePaths(Vector<String>& paths)
  253. {
  254. paths.Clear();
  255. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  256. paths.Push(AddTrailingSlash(tenv->GetCoreDataDir()));
  257. paths.Push(AddTrailingSlash(tenv->GetPlayerDataDir()));
  258. }
  259. String BuildBase::GetSettingsDirectory()
  260. {
  261. return project_->GetProjectPath() + "/Settings";
  262. }
  263. void BuildBase::BuildDefaultResourceEntries()
  264. {
  265. String buildLogOutput(String::EMPTY);
  266. for (unsigned i = 0; i < resourceDirs_.Size(); i++)
  267. {
  268. String resourceDir = resourceDirs_[i];
  269. fileIncludedResourcesLog_->WriteLine("\nBuildBase::BuildDefaultResourceEntries - Default resources being included from: " + resourceDir);
  270. Vector<String> fileNames;
  271. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  272. fileSystem->ScanDir(fileNames, resourceDir, "*.*", SCAN_FILES, true);
  273. for (unsigned i = 0; i < fileNames.Size(); i++)
  274. {
  275. const String& filename = fileNames[i];
  276. AddToResourcePackager(filename, resourceDir);
  277. if (verbose_)
  278. {
  279. ATOMIC_LOGINFO(ToString("Default Resource Added: %s%s", resourceDir.CString(), filename.CString()));
  280. }
  281. }
  282. }
  283. }
  284. void BuildBase::BuildProjectResourceEntries()
  285. {
  286. String buildLogOutput(String::EMPTY);
  287. if (AssetBuildConfig::IsLoaded())
  288. {
  289. buildLogOutput += "\nBaseBuild::BuildProjectResourceEntries - ./Settings/AssetBuildConfig.json found. ";
  290. if (!assetBuildTag_.Empty())
  291. {
  292. buildLogOutput += "Using build-tag parameter : " + assetBuildTag_;
  293. fileIncludedResourcesLog_->WriteLine(buildLogOutput);
  294. BuildFilteredProjectResourceEntries();
  295. return;
  296. }
  297. buildLogOutput += "No build-tag parameter used.";
  298. }
  299. buildLogOutput += "\nBaseBuild::BuildProjectResourceEntries - No custom asset include configuration being used - ";
  300. buildLogOutput += "AssetBuildConfig.json not loaded, OR no build-tag parameter used.";
  301. fileIncludedResourcesLog_->WriteLine(buildLogOutput);
  302. BuildAllProjectResourceEntries();
  303. }
  304. void BuildBase::BuildAllProjectResourceEntries()
  305. {
  306. for (unsigned i = 0; i < projectResourceDir_.Size(); i++)
  307. {
  308. String projectResourceDir = projectResourceDir_[i];
  309. fileIncludedResourcesLog_->WriteLine("\nBuildBase::BuildAllProjectResourceEntries - Project resources being included from: " + projectResourceDir);
  310. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  311. bool compressTextures = false;
  312. if (ImportConfig::IsLoaded())
  313. {
  314. VariantMap tiParameters;
  315. ImportConfig::ApplyConfig(tiParameters);
  316. VariantMap::ConstIterator itr = tiParameters.Begin();
  317. for (; itr != tiParameters.End(); itr++)
  318. {
  319. if (itr->first_ == "tiProcess_CompressTextures")
  320. compressTextures = itr->second_.GetBool();
  321. }
  322. }
  323. Vector<String> assetFileNamesInProject;
  324. fileSystem->ScanDir(assetFileNamesInProject, projectResourceDir, "*.asset", SCAN_FILES, true);
  325. Vector<String> cachedFileNames;
  326. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  327. String cachePath = db->GetCachePath();
  328. Vector<String> filesInCacheFolder;
  329. Vector<String> fileNamesInCacheFolder;
  330. Vector<String> compressedResources;
  331. if (assetFileNamesInProject.Size() > 0)
  332. {
  333. fileSystem->ScanDir(filesInCacheFolder, cachePath, "*.*", SCAN_FILES, false);
  334. for (unsigned j = 0; j < filesInCacheFolder.Size(); ++j)
  335. {
  336. const String &fileName = GetFileNameAndExtension(filesInCacheFolder[j]);
  337. fileNamesInCacheFolder.Push(fileName);
  338. }
  339. }
  340. for (unsigned i = 0; i < assetFileNamesInProject.Size(); i++)
  341. {
  342. unsigned assetSubStrPos = assetFileNamesInProject[i].Find(".asset");
  343. String baseFileName = assetFileNamesInProject[i].Substring(0, assetSubStrPos);
  344. String extension = GetExtension(baseFileName);
  345. if (compressTextures && (extension == ".jpg" || extension == ".png" || extension == ".tga"))
  346. {
  347. SharedPtr<File> file(new File(context_, project_->GetResourcePath() + assetFileNamesInProject[i]));
  348. SharedPtr<JSONFile> json(new JSONFile(context_));
  349. json->Load(*file);
  350. file->Close();
  351. JSONValue& root = json->GetRoot();
  352. int test = root.Get("version").GetInt();
  353. assert(root.Get("version").GetInt() == ASSET_VERSION);
  354. String guid = root.Get("guid").GetString();
  355. String dds = guid + ".dds";
  356. if (fileNamesInCacheFolder.Contains(dds))
  357. {
  358. compressedResources.Push(baseFileName);
  359. }
  360. }
  361. }
  362. Vector<String> fileNamesInProject;
  363. fileSystem->ScanDir(fileNamesInProject, projectResourceDir, "*.*", SCAN_FILES, true);
  364. for (unsigned i = 0; i < fileNamesInProject.Size(); i++)
  365. {
  366. String fName = fileNamesInProject[i];
  367. if (compressedResources.Contains(fName))
  368. {
  369. if (autoLog_)
  370. {
  371. ATOMIC_LOGINFO(ToString("Project Resource not included because compressed version exists: %s%s", projectResourceDir.CString(), fileNamesInProject[i].CString()));
  372. }
  373. }
  374. else
  375. {
  376. AddToResourcePackager(fileNamesInProject[i], projectResourceDir);
  377. if (verbose_)
  378. {
  379. ATOMIC_LOGINFO(ToString("Project Resource Added: %s%s", projectResourceDir.CString(), fileNamesInProject[i].CString()));
  380. }
  381. }
  382. }
  383. }
  384. }
  385. void BuildBase::BuildFilteredProjectResourceEntries()
  386. {
  387. // Loading up the AssetBuildConfig.json,
  388. // obtaining a list of files to include in the build.
  389. VariantMap resourceTags;
  390. AssetBuildConfig::ApplyConfig(resourceTags);
  391. Vector<String> assetBuildConfigFiles;
  392. VariantMap::ConstIterator itr = resourceTags.Begin();
  393. while (itr != resourceTags.End())
  394. {
  395. if (itr->first_ == assetBuildTag_)
  396. {
  397. assetBuildConfigFiles = itr->second_.GetStringVector();
  398. for (unsigned i = 0; i < assetBuildConfigFiles.Size(); ++i)
  399. {
  400. // remove case sensitivity
  401. assetBuildConfigFiles[i] = assetBuildConfigFiles[i].ToLower();
  402. }
  403. break;
  404. }
  405. itr++;
  406. if (itr == resourceTags.End())
  407. {
  408. ATOMIC_LOGERRORF("BuildBase::BuildFilteredProjectResourceEntries - Asset build-tag \"%s\" not defined in ./Settings/AssetBuildConfig.json", assetBuildTag_.CString());
  409. }
  410. }
  411. // find any folders defined in assetbuildconfig.json, and add the non-".asset" files in them.
  412. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  413. Vector<String> filesInFolderToAdd;
  414. for (unsigned i = 0; i < assetBuildConfigFiles.Size(); ++i)
  415. {
  416. String &filename = assetBuildConfigFiles[i];
  417. if (GetExtension(filename) == String::EMPTY &&
  418. fileSystem->DirExists(project_->GetResourcePath() + filename))
  419. {
  420. // rename 'filename' to 'folder' for context
  421. String folder(filename);
  422. // add a trailing slash if not defined
  423. if (folder.Back() != '/')
  424. folder = AddTrailingSlash(folder);
  425. Vector<String> filesInFolder;
  426. fileSystem->ScanDir(filesInFolder, project_->GetResourcePath() + folder, "*.*", SCAN_FILES, true);
  427. for (unsigned j = 0; j < filesInFolder.Size(); ++j)
  428. {
  429. String path = filesInFolder[j];
  430. // not interested in .asset files for now, will be included later.
  431. if (GetExtension(path) != ".asset")
  432. {
  433. filesInFolderToAdd.Push(folder + path.ToLower());
  434. }
  435. }
  436. }
  437. }
  438. // add the files defined using a folder in AssetBuildConfig.json
  439. for (unsigned i = 0; i < filesInFolderToAdd.Size(); ++i)
  440. {
  441. assetBuildConfigFiles.Push(filesInFolderToAdd[i]);
  442. }
  443. // check if the files in AssetBuildConfig.json exist,
  444. // as well as their corresponding .asset file
  445. Vector<String> filesInResourceFolder;
  446. Vector<String> resourceFilesToInclude;
  447. fileSystem->ScanDir(filesInResourceFolder, project_->GetResourcePath(), "*.*", SCAN_FILES, true);
  448. for (unsigned j = 0; j < filesInResourceFolder.Size(); ++j)
  449. {
  450. // don't want to checks to be case sensitive
  451. filesInResourceFolder[j] = filesInResourceFolder[j].ToLower();
  452. }
  453. for (unsigned i = 0; i < assetBuildConfigFiles.Size(); ++i)
  454. {
  455. // .asset file is of primary importance since we used it to identify the associated cached file.
  456. // without the .asset file the resource is removed from being included in the build.
  457. // don't want checks to be case sensitive
  458. String &filename = assetBuildConfigFiles[i];
  459. if (filesInResourceFolder.Contains(filename) &&
  460. filesInResourceFolder.Contains(filename + ".asset"))
  461. {
  462. resourceFilesToInclude.Push(filename);
  463. resourceFilesToInclude.Push(filename + ".asset");
  464. continue;
  465. }
  466. fileIncludedResourcesLog_->WriteLine("File " + filename + " ignored since it does not have an associated .asset file");
  467. }
  468. // add valid files included from the AssetBuildConfig.json
  469. for (StringVector::ConstIterator it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
  470. {
  471. AddToResourcePackager(*it, project_->GetResourcePath());
  472. }
  473. // Get associated cache GUID from the asset file
  474. Vector<String> filesWithGUIDtoInclude;
  475. for (StringVector::Iterator it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
  476. {
  477. String &filename = *it;
  478. if (GetExtension(*it) == ".asset")
  479. {
  480. SharedPtr<File> file(new File(context_, project_->GetResourcePath() + *it));
  481. SharedPtr<JSONFile> json(new JSONFile(context_));
  482. json->Load(*file);
  483. file->Close();
  484. JSONValue& root = json->GetRoot();
  485. int test = root.Get("version").GetInt();
  486. assert(root.Get("version").GetInt() == ASSET_VERSION);
  487. String guid = root.Get("guid").GetString();
  488. filesWithGUIDtoInclude.Push(guid);
  489. }
  490. }
  491. // Obtain files in cache folder,
  492. // Check if the file contains the guid, and add it to the cacheFilesToInclude
  493. Vector<String> filesInCacheFolder;
  494. Vector<String> cacheFilesToInclude;
  495. AssetDatabase* db = GetSubsystem<AssetDatabase>();
  496. String cachePath = db->GetCachePath();
  497. fileSystem->ScanDir(filesInCacheFolder, cachePath, "*.*", SCAN_FILES, false);
  498. for (unsigned i = 0; i < filesWithGUIDtoInclude.Size(); ++i)
  499. {
  500. String &guid = filesWithGUIDtoInclude[i];
  501. for (unsigned j = 0; j < filesInCacheFolder.Size(); ++j)
  502. {
  503. const String &filename = GetFileName(filesInCacheFolder[j]);
  504. String &filenamePath = filesInCacheFolder[j];
  505. if (filename.Contains(guid))
  506. {
  507. cacheFilesToInclude.Push(filesInCacheFolder[j]);
  508. // do not continue...
  509. // there might be multiple files with the same guid having an guid_animaiton extention.
  510. }
  511. }
  512. }
  513. // include a texture file's cached .dds file when building in windows
  514. #ifdef ATOMIC_PLATFORM_DESKTOP
  515. for (StringVector::ConstIterator it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
  516. {
  517. if (!CheckIncludeResourceFile(project_->GetResourcePath(), *it))
  518. {
  519. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  520. String associatedDDSpath = "DDS/" + *it + ".dds";
  521. String compressedPath = cachePath + associatedDDSpath;
  522. if (fileSystem->FileExists(compressedPath))
  523. {
  524. cacheFilesToInclude.Push(associatedDDSpath);
  525. }
  526. }
  527. }
  528. #endif
  529. // Add the cache files to the resource packager
  530. for (StringVector::ConstIterator it = cacheFilesToInclude.Begin(); it != cacheFilesToInclude.End(); ++it)
  531. {
  532. AddToResourcePackager(*it, cachePath);
  533. }
  534. }
  535. void BuildBase::AddToResourcePackager(const String& filename, const String& resourceDir)
  536. {
  537. // Check if the file is already included in the resourceEntries_ list
  538. for (unsigned j = 0; j < resourceEntries_.Size(); j++)
  539. {
  540. const BuildResourceEntry* entry = resourceEntries_[j];
  541. if (entry->packagePath_ == filename)
  542. {
  543. BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
  544. continue;
  545. }
  546. }
  547. if (!CheckIncludeResourceFile(resourceDir, filename))
  548. {
  549. fileIncludedResourcesLog_->WriteLine(resourceDir + filename + " skipped because of file extention: " + GetExtension(filename));
  550. return;
  551. }
  552. BuildResourceEntry* newEntry = new BuildResourceEntry;
  553. // BEGIN LICENSE MANAGEMENT
  554. if (GetExtension(filename) == ".mdl")
  555. {
  556. containsMDL_ = true;
  557. }
  558. // END LICENSE MANAGEMENT
  559. newEntry->absolutePath_ = resourceDir + filename;
  560. newEntry->resourceDir_ = resourceDir;
  561. newEntry->packagePath_ = filename;
  562. resourceEntries_.Push(newEntry);
  563. assert(resourcePackager_.NotNull());
  564. resourcePackager_->AddResourceEntry(newEntry);
  565. fileIncludedResourcesLog_->WriteLine(newEntry->absolutePath_);
  566. }
  567. void BuildBase::GenerateResourcePackage(const String& resourcePackagePath)
  568. {
  569. resourcePackager_->GeneratePackage(resourcePackagePath);
  570. }
  571. void BuildBase::AddResourceDir(const String& dir)
  572. {
  573. assert(!resourceDirs_.Contains(dir));
  574. resourceDirs_.Push(dir);
  575. }
  576. void BuildBase::AddProjectResourceDir(const String& dir)
  577. {
  578. assert(!projectResourceDir_.Contains(dir));
  579. projectResourceDir_.Push(dir);
  580. }
  581. void BuildBase::ReadAssetBuildConfig()
  582. {
  583. String projectPath = project_->GetProjectPath();
  584. projectPath = RemoveTrailingSlash(projectPath);
  585. String filename = projectPath + "Settings/AssetBuildConfig.json";
  586. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  587. if (!fileSystem->FileExists(filename))
  588. return;
  589. if (AssetBuildConfig::LoadFromFile(context_, filename))
  590. {
  591. VariantMap assetBuildConfig;
  592. AssetBuildConfig::ApplyConfig(assetBuildConfig);
  593. }
  594. }
  595. }