BsProjectLibrary.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  1. #include "BsProjectLibrary.h"
  2. #include "BsFileSystem.h"
  3. #include "BsException.h"
  4. #include "BsResources.h"
  5. #include "BsResourceManifest.h"
  6. #include "BsImporter.h"
  7. #include "BsProjectResourceMeta.h"
  8. #include "BsResources.h"
  9. #include "BsImporter.h"
  10. #include "BsImportOptions.h"
  11. #include "BsFileSerializer.h"
  12. #include "BsDebug.h"
  13. #include "BsProjectLibraryEntries.h"
  14. #include "BsResource.h"
  15. #include "BsEditorApplication.h"
  16. #include "BsShader.h"
  17. #include <regex>
  18. using namespace std::placeholders;
  19. namespace BansheeEngine
  20. {
  21. const Path ProjectLibrary::RESOURCES_DIR = L"Resources\\";
  22. const Path ProjectLibrary::INTERNAL_RESOURCES_DIR = PROJECT_INTERNAL_DIR + L"Resources\\";
  23. const WString ProjectLibrary::LIBRARY_ENTRIES_FILENAME = L"ProjectLibrary.asset";
  24. const WString ProjectLibrary::RESOURCE_MANIFEST_FILENAME = L"ResourceManifest.asset";
  25. ProjectLibrary::LibraryEntry::LibraryEntry()
  26. :parent(nullptr), type(LibraryEntryType::Directory)
  27. { }
  28. ProjectLibrary::LibraryEntry::LibraryEntry(const Path& path, const WString& name, DirectoryEntry* parent, LibraryEntryType type)
  29. :path(path), parent(parent), type(type), elementName(name)
  30. { }
  31. ProjectLibrary::ResourceEntry::ResourceEntry()
  32. : lastUpdateTime(0)
  33. { }
  34. ProjectLibrary::ResourceEntry::ResourceEntry(const Path& path, const WString& name, DirectoryEntry* parent)
  35. : LibraryEntry(path, name, parent, LibraryEntryType::File), lastUpdateTime(0)
  36. { }
  37. ProjectLibrary::DirectoryEntry::DirectoryEntry()
  38. { }
  39. ProjectLibrary::DirectoryEntry::DirectoryEntry(const Path& path, const WString& name, DirectoryEntry* parent)
  40. :LibraryEntry(path, name, parent, LibraryEntryType::Directory)
  41. { }
  42. ProjectLibrary::ProjectLibrary()
  43. : mRootEntry(nullptr), mIsLoaded(false)
  44. {
  45. mRootEntry = bs_new<DirectoryEntry>(mResourcesFolder, mResourcesFolder.getWTail(), nullptr);
  46. }
  47. ProjectLibrary::~ProjectLibrary()
  48. {
  49. clearEntries();
  50. }
  51. void ProjectLibrary::checkForModifications(const Path& fullPath)
  52. {
  53. Vector<Path> dirtyResources;
  54. checkForModifications(fullPath, true, dirtyResources);
  55. }
  56. void ProjectLibrary::checkForModifications(const Path& fullPath, bool import, Vector<Path>& dirtyResources)
  57. {
  58. if (!mResourcesFolder.includes(fullPath))
  59. return; // Folder not part of our resources path, so no modifications
  60. if(mRootEntry == nullptr)
  61. {
  62. mRootEntry = bs_new<DirectoryEntry>(mResourcesFolder, mResourcesFolder.getWTail(), nullptr);
  63. }
  64. Path pathToSearch = fullPath;
  65. LibraryEntry* entry = findEntry(pathToSearch);
  66. if (entry == nullptr) // File could be new, try to find parent directory entry
  67. {
  68. if (FileSystem::exists(pathToSearch))
  69. {
  70. if (isMeta(pathToSearch))
  71. {
  72. Path sourceFilePath = pathToSearch;
  73. sourceFilePath.setExtension(L"");
  74. if (!FileSystem::isFile(sourceFilePath))
  75. {
  76. LOGWRN("Found a .meta file without a corresponding resource. Deleting.");
  77. FileSystem::remove(pathToSearch);
  78. }
  79. }
  80. else
  81. {
  82. Path parentDirPath = pathToSearch.getParent();
  83. entry = findEntry(parentDirPath);
  84. // Cannot find parent directory. Create the needed hierarchy.
  85. DirectoryEntry* entryParent = nullptr;
  86. DirectoryEntry* newHierarchyParent = nullptr;
  87. if (entry == nullptr)
  88. createInternalParentHierarchy(pathToSearch, &newHierarchyParent, &entryParent);
  89. else
  90. entryParent = static_cast<DirectoryEntry*>(entry);
  91. if (FileSystem::isFile(pathToSearch))
  92. {
  93. if (import)
  94. addResourceInternal(entryParent, pathToSearch);
  95. dirtyResources.push_back(pathToSearch);
  96. }
  97. else if (FileSystem::isDirectory(pathToSearch))
  98. {
  99. addDirectoryInternal(entryParent, pathToSearch);
  100. checkForModifications(pathToSearch, import, dirtyResources);
  101. }
  102. }
  103. }
  104. }
  105. else if(entry->type == LibraryEntryType::File)
  106. {
  107. if(FileSystem::isFile(entry->path))
  108. {
  109. ResourceEntry* resEntry = static_cast<ResourceEntry*>(entry);
  110. if (import)
  111. reimportResourceInternal(resEntry);
  112. if (!isUpToDate(resEntry))
  113. dirtyResources.push_back(entry->path);
  114. }
  115. else
  116. {
  117. deleteResourceInternal(static_cast<ResourceEntry*>(entry));
  118. }
  119. }
  120. else if(entry->type == LibraryEntryType::Directory) // Check folder and all subfolders for modifications
  121. {
  122. if(!FileSystem::isDirectory(entry->path))
  123. {
  124. deleteDirectoryInternal(static_cast<DirectoryEntry*>(entry));
  125. }
  126. else
  127. {
  128. Stack<DirectoryEntry*> todo;
  129. todo.push(static_cast<DirectoryEntry*>(entry));
  130. Vector<Path> childFiles;
  131. Vector<Path> childDirectories;
  132. Vector<bool> existingEntries;
  133. Vector<LibraryEntry*> toDelete;
  134. while(!todo.empty())
  135. {
  136. DirectoryEntry* currentDir = todo.top();
  137. todo.pop();
  138. existingEntries.clear();
  139. existingEntries.resize(currentDir->mChildren.size());
  140. for(UINT32 i = 0; i < (UINT32)currentDir->mChildren.size(); i++)
  141. existingEntries[i] = false;
  142. childFiles.clear();
  143. childDirectories.clear();
  144. FileSystem::getChildren(currentDir->path, childFiles, childDirectories);
  145. for(auto& filePath : childFiles)
  146. {
  147. if(isMeta(filePath))
  148. {
  149. Path sourceFilePath = filePath;
  150. sourceFilePath.setExtension(L"");
  151. if(!FileSystem::isFile(sourceFilePath))
  152. {
  153. LOGWRN("Found a .meta file without a corresponding resource. Deleting.");
  154. FileSystem::remove(filePath);
  155. }
  156. }
  157. else
  158. {
  159. ResourceEntry* existingEntry = nullptr;
  160. UINT32 idx = 0;
  161. for(auto& child : currentDir->mChildren)
  162. {
  163. if(child->type == LibraryEntryType::File && child->path == filePath)
  164. {
  165. existingEntries[idx] = true;
  166. existingEntry = static_cast<ResourceEntry*>(child);
  167. break;
  168. }
  169. idx++;
  170. }
  171. if(existingEntry != nullptr)
  172. {
  173. if (import)
  174. reimportResourceInternal(existingEntry);
  175. if (!isUpToDate(existingEntry))
  176. dirtyResources.push_back(existingEntry->path);
  177. }
  178. else
  179. {
  180. if (import)
  181. addResourceInternal(currentDir, filePath);
  182. dirtyResources.push_back(filePath);
  183. }
  184. }
  185. }
  186. for(auto& dirPath : childDirectories)
  187. {
  188. DirectoryEntry* existingEntry = nullptr;
  189. UINT32 idx = 0;
  190. for(auto& child : currentDir->mChildren)
  191. {
  192. if(child->type == LibraryEntryType::Directory && child->path == dirPath)
  193. {
  194. existingEntries[idx] = true;
  195. existingEntry = static_cast<DirectoryEntry*>(child);
  196. break;
  197. }
  198. idx++;
  199. }
  200. if(existingEntry == nullptr)
  201. addDirectoryInternal(currentDir, dirPath);
  202. }
  203. {
  204. for(UINT32 i = 0; i < (UINT32)existingEntries.size(); i++)
  205. {
  206. if(existingEntries[i])
  207. continue;
  208. toDelete.push_back(currentDir->mChildren[i]);
  209. }
  210. for(auto& child : toDelete)
  211. {
  212. if(child->type == LibraryEntryType::Directory)
  213. deleteDirectoryInternal(static_cast<DirectoryEntry*>(child));
  214. else if(child->type == LibraryEntryType::File)
  215. deleteResourceInternal(static_cast<ResourceEntry*>(child));
  216. }
  217. toDelete.clear();
  218. }
  219. for(auto& child : currentDir->mChildren)
  220. {
  221. if(child->type == LibraryEntryType::Directory)
  222. todo.push(static_cast<DirectoryEntry*>(child));
  223. }
  224. }
  225. }
  226. }
  227. }
  228. ProjectLibrary::ResourceEntry* ProjectLibrary::addResourceInternal(DirectoryEntry* parent, const Path& filePath,
  229. const ImportOptionsPtr& importOptions, bool forceReimport)
  230. {
  231. ResourceEntry* newResource = bs_new<ResourceEntry>(filePath, filePath.getWTail(), parent);
  232. parent->mChildren.push_back(newResource);
  233. reimportResourceInternal(newResource, importOptions, forceReimport);
  234. onEntryAdded(newResource->path);
  235. return newResource;
  236. }
  237. ProjectLibrary::DirectoryEntry* ProjectLibrary::addDirectoryInternal(DirectoryEntry* parent, const Path& dirPath)
  238. {
  239. DirectoryEntry* newEntry = bs_new<DirectoryEntry>(dirPath, dirPath.getWTail(), parent);
  240. parent->mChildren.push_back(newEntry);
  241. onEntryAdded(newEntry->path);
  242. return newEntry;
  243. }
  244. void ProjectLibrary::deleteResourceInternal(ResourceEntry* resource)
  245. {
  246. if(resource->meta != nullptr)
  247. {
  248. String uuid = resource->meta->getUUID();
  249. Path path;
  250. if (mResourceManifest->uuidToFilePath(uuid, path))
  251. {
  252. if(FileSystem::isFile(path))
  253. FileSystem::remove(path);
  254. mResourceManifest->unregisterResource(uuid);
  255. }
  256. mUUIDToPath.erase(uuid);
  257. }
  258. Path metaPath = getMetaPath(resource->path);
  259. if (FileSystem::isFile(metaPath))
  260. FileSystem::remove(metaPath);
  261. DirectoryEntry* parent = resource->parent;
  262. auto findIter = std::find_if(parent->mChildren.begin(), parent->mChildren.end(),
  263. [&] (const LibraryEntry* entry) { return entry == resource; });
  264. parent->mChildren.erase(findIter);
  265. Path originalPath = resource->path;
  266. onEntryRemoved(originalPath);
  267. removeDependencies(resource);
  268. bs_delete(resource);
  269. reimportDependants(originalPath);
  270. }
  271. void ProjectLibrary::deleteDirectoryInternal(DirectoryEntry* directory)
  272. {
  273. if(directory == mRootEntry)
  274. mRootEntry = nullptr;
  275. Vector<LibraryEntry*> childrenToDestroy = directory->mChildren;
  276. for(auto& child : childrenToDestroy)
  277. {
  278. if(child->type == LibraryEntryType::Directory)
  279. deleteDirectoryInternal(static_cast<DirectoryEntry*>(child));
  280. else
  281. deleteResourceInternal(static_cast<ResourceEntry*>(child));
  282. }
  283. DirectoryEntry* parent = directory->parent;
  284. if(parent != nullptr)
  285. {
  286. auto findIter = std::find_if(parent->mChildren.begin(), parent->mChildren.end(),
  287. [&] (const LibraryEntry* entry) { return entry == directory; });
  288. parent->mChildren.erase(findIter);
  289. }
  290. onEntryRemoved(directory->path);
  291. bs_delete(directory);
  292. }
  293. void ProjectLibrary::reimportResourceInternal(ResourceEntry* resource, const ImportOptionsPtr& importOptions, bool forceReimport)
  294. {
  295. Path metaPath = resource->path;
  296. metaPath.setFilename(metaPath.getWFilename() + L".meta");
  297. if(resource->meta == nullptr)
  298. {
  299. if(FileSystem::isFile(metaPath))
  300. {
  301. FileDecoder fs(metaPath);
  302. std::shared_ptr<IReflectable> loadedMeta = fs.decode();
  303. if(loadedMeta != nullptr && loadedMeta->isDerivedFrom(ProjectResourceMeta::getRTTIStatic()))
  304. {
  305. ProjectResourceMetaPtr resourceMeta = std::static_pointer_cast<ProjectResourceMeta>(loadedMeta);
  306. resource->meta = resourceMeta;
  307. mUUIDToPath[resourceMeta->getUUID()] = resource->path;
  308. }
  309. }
  310. }
  311. if (!isUpToDate(resource) || forceReimport)
  312. {
  313. // Note: If resource is native we just copy it to the internal folder. We could avoid the copy and
  314. // load the resource directly from the Resources folder but that requires complicating library code.
  315. bool isNativeResource = isNative(resource);
  316. ImportOptionsPtr curImportOptions = nullptr;
  317. if (importOptions == nullptr && !isNativeResource)
  318. {
  319. if (resource->meta != nullptr)
  320. curImportOptions = resource->meta->getImportOptions();
  321. else
  322. curImportOptions = Importer::instance().createImportOptions(resource->path);
  323. }
  324. else
  325. curImportOptions = importOptions;
  326. HResource importedResource;
  327. if (isNativeResource)
  328. {
  329. // If meta exists make sure it is registered in the manifest before load, otherwise it will get assigned a new UUID.
  330. // This can happen if library isn't properly saved before exiting the application.
  331. if (resource->meta != nullptr)
  332. mResourceManifest->registerResource(resource->meta->getUUID(), resource->path);
  333. // Don't load dependencies because we don't need them, but also because they might not be in the manifest
  334. // which would screw up their UUIDs.
  335. importedResource = gResources().load(resource->path, false);
  336. }
  337. if(resource->meta == nullptr)
  338. {
  339. if (!isNativeResource)
  340. importedResource = Importer::instance().import(resource->path, curImportOptions);
  341. if (importedResource != nullptr)
  342. {
  343. ResourceMetaDataPtr subMeta = importedResource->getMetaData();
  344. UINT32 typeId = importedResource->getTypeId();
  345. resource->meta = ProjectResourceMeta::create(importedResource.getUUID(), typeId, subMeta, curImportOptions);
  346. }
  347. else
  348. resource->meta = ProjectResourceMeta::create(importedResource.getUUID(), 0, nullptr, curImportOptions);
  349. FileEncoder fs(metaPath);
  350. fs.encode(resource->meta.get());
  351. mUUIDToPath[resource->meta->getUUID()] = resource->path;
  352. }
  353. else
  354. {
  355. removeDependencies(resource);
  356. if (!isNativeResource)
  357. {
  358. importedResource = HResource(resource->meta->getUUID());
  359. Importer::instance().reimport(importedResource, resource->path, curImportOptions);
  360. }
  361. }
  362. addDependencies(resource);
  363. if (importedResource != nullptr)
  364. {
  365. Path internalResourcesPath = mProjectFolder;
  366. internalResourcesPath.append(INTERNAL_RESOURCES_DIR);
  367. if (!FileSystem::isDirectory(internalResourcesPath))
  368. FileSystem::createDir(internalResourcesPath);
  369. internalResourcesPath.setFilename(toWString(importedResource.getUUID()) + L".asset");
  370. gResources().save(importedResource, internalResourcesPath, true);
  371. if (!isNativeResource)
  372. gResources().unload(importedResource);
  373. mResourceManifest->registerResource(importedResource.getUUID(), internalResourcesPath);
  374. }
  375. resource->lastUpdateTime = std::time(nullptr);
  376. onEntryImported(resource->path);
  377. reimportDependants(resource->path);
  378. }
  379. }
  380. bool ProjectLibrary::isUpToDate(ResourceEntry* resource) const
  381. {
  382. if(resource->meta == nullptr)
  383. return false;
  384. Path path;
  385. if(!mResourceManifest->uuidToFilePath(resource->meta->getUUID(), path))
  386. return false;
  387. if(!FileSystem::isFile(path))
  388. return false;
  389. std::time_t lastModifiedTime = FileSystem::getLastModifiedTime(path);
  390. return lastModifiedTime <= resource->lastUpdateTime;
  391. }
  392. Vector<ProjectLibrary::LibraryEntry*> ProjectLibrary::search(const WString& pattern)
  393. {
  394. return search(pattern, {});
  395. }
  396. Vector<ProjectLibrary::LibraryEntry*> ProjectLibrary::search(const WString& pattern, const Vector<UINT32>& typeIds)
  397. {
  398. Vector<LibraryEntry*> foundEntries;
  399. std::wregex escape(L"[.^$|()\\[\\]{}*+?\\\\]");
  400. WString replace(L"\\\\&");
  401. WString escapedPattern = std::regex_replace(pattern, escape, replace, std::regex_constants::match_default | std::regex_constants::format_sed);
  402. std::wregex wildcard(L"\\\\\\*");
  403. WString wildcardReplace(L".*");
  404. WString searchPattern = std::regex_replace(escapedPattern, wildcard, L".*");
  405. std::wregex searchRegex(searchPattern, std::regex_constants::ECMAScript | std::regex_constants::icase);
  406. Stack<DirectoryEntry*> todo;
  407. todo.push(mRootEntry);
  408. while (!todo.empty())
  409. {
  410. DirectoryEntry* dirEntry = todo.top();
  411. todo.pop();
  412. for (auto& child : dirEntry->mChildren)
  413. {
  414. if (std::regex_match(child->elementName, searchRegex))
  415. {
  416. if (typeIds.size() == 0)
  417. foundEntries.push_back(child);
  418. else
  419. {
  420. if (child->type == LibraryEntryType::File)
  421. {
  422. ResourceEntry* childResEntry = static_cast<ResourceEntry*>(child);
  423. for (auto& typeId : typeIds)
  424. {
  425. if (childResEntry->meta != nullptr && childResEntry->meta->getTypeID() == typeId)
  426. {
  427. foundEntries.push_back(child);
  428. break;
  429. }
  430. }
  431. }
  432. }
  433. }
  434. if (child->type == LibraryEntryType::Directory)
  435. {
  436. DirectoryEntry* childDirEntry = static_cast<DirectoryEntry*>(child);
  437. todo.push(childDirEntry);
  438. }
  439. }
  440. }
  441. std::sort(foundEntries.begin(), foundEntries.end(),
  442. [&](const LibraryEntry* a, const LibraryEntry* b)
  443. {
  444. return a->elementName.compare(b->elementName) < 0;
  445. });
  446. return foundEntries;
  447. }
  448. ProjectLibrary::LibraryEntry* ProjectLibrary::findEntry(const Path& path) const
  449. {
  450. Path fullPath = path;
  451. if (fullPath.isAbsolute())
  452. {
  453. if (!mResourcesFolder.includes(fullPath))
  454. return nullptr;
  455. }
  456. else
  457. fullPath.makeAbsolute(mResourcesFolder);
  458. Path relPath = fullPath.getRelative(mRootEntry->path);
  459. UINT32 numElems = relPath.getNumDirectories() + (relPath.isFile() ? 1 : 0);
  460. UINT32 idx = 0;
  461. LibraryEntry* current = mRootEntry;
  462. while (current != nullptr)
  463. {
  464. if (idx == numElems)
  465. return current;
  466. WString curElem;
  467. if (relPath.isFile() && idx == (numElems - 1))
  468. curElem = relPath.getWFilename();
  469. else
  470. curElem = relPath[idx];
  471. if (current->type == LibraryEntryType::Directory)
  472. {
  473. DirectoryEntry* dirEntry = static_cast<DirectoryEntry*>(current);
  474. current = nullptr;
  475. for (auto& child : dirEntry->mChildren)
  476. {
  477. if (Path::comparePathElem(curElem, child->elementName))
  478. {
  479. idx++;
  480. current = child;
  481. break;
  482. }
  483. }
  484. }
  485. else
  486. break;
  487. }
  488. return nullptr;
  489. }
  490. Path ProjectLibrary::uuidToPath(const String& uuid) const
  491. {
  492. auto iterFind = mUUIDToPath.find(uuid);
  493. if (iterFind != mUUIDToPath.end())
  494. return iterFind->second;
  495. return Path::BLANK;
  496. }
  497. void ProjectLibrary::createEntry(const HResource& resource, const Path& path)
  498. {
  499. if (resource == nullptr)
  500. return;
  501. Path assetPath = path;
  502. if (path.isAbsolute())
  503. {
  504. if (!getResourcesFolder().includes(path))
  505. return;
  506. assetPath = path.getRelative(getResourcesFolder());
  507. }
  508. LibraryEntry* existingEntry = findEntry(assetPath);
  509. if (existingEntry != nullptr)
  510. {
  511. LOGWRN("Resource already exists at the specified path : " + assetPath.toString() + ". Unable to save.");
  512. return;
  513. }
  514. resource->setName(path.getWFilename(false));
  515. Path absPath = assetPath.getAbsolute(getResourcesFolder());
  516. Resources::instance().save(resource, absPath, false);
  517. checkForModifications(absPath);
  518. }
  519. void ProjectLibrary::saveEntry(const HResource& resource)
  520. {
  521. if (resource == nullptr)
  522. return;
  523. Path filePath = uuidToPath(resource.getUUID());
  524. filePath.makeAbsolute(getResourcesFolder());
  525. Resources::instance().save(resource, filePath, true);
  526. }
  527. void ProjectLibrary::createFolderEntry(const Path& path)
  528. {
  529. Path fullPath = path;
  530. if (fullPath.isAbsolute())
  531. {
  532. if (!mResourcesFolder.includes(fullPath))
  533. return;
  534. }
  535. else
  536. fullPath.makeAbsolute(mResourcesFolder);
  537. if (FileSystem::isDirectory(fullPath))
  538. return; // Already exists
  539. FileSystem::createDir(fullPath);
  540. Path parentPath = fullPath.getParent();
  541. DirectoryEntry* newEntryParent = nullptr;
  542. LibraryEntry* newEntryParentLib = findEntry(parentPath);
  543. if (newEntryParentLib != nullptr)
  544. {
  545. assert(newEntryParentLib->type == LibraryEntryType::Directory);
  546. newEntryParent = static_cast<DirectoryEntry*>(newEntryParentLib);
  547. }
  548. DirectoryEntry* newHierarchyParent = nullptr;
  549. if (newEntryParent == nullptr) // New path parent doesn't exist, so we need to create the hierarchy
  550. createInternalParentHierarchy(fullPath, &newHierarchyParent, &newEntryParent);
  551. addDirectoryInternal(newEntryParent, fullPath);
  552. }
  553. void ProjectLibrary::moveEntry(const Path& oldPath, const Path& newPath, bool overwrite)
  554. {
  555. Path oldFullPath = oldPath;
  556. if (!oldFullPath.isAbsolute())
  557. oldFullPath.makeAbsolute(mResourcesFolder);
  558. Path newFullPath = newPath;
  559. if (!newFullPath.isAbsolute())
  560. newFullPath.makeAbsolute(mResourcesFolder);
  561. if(FileSystem::isFile(oldFullPath) || FileSystem::isDirectory(oldFullPath))
  562. FileSystem::move(oldFullPath, newFullPath, overwrite);
  563. Path oldMetaPath = getMetaPath(oldFullPath);
  564. Path newMetaPath = getMetaPath(newFullPath);
  565. LibraryEntry* oldEntry = findEntry(oldFullPath);
  566. if(oldEntry != nullptr) // Moving from the Resources folder
  567. {
  568. // Moved outside of Resources, delete entry & meta file
  569. if (!mResourcesFolder.includes(newFullPath))
  570. {
  571. if(oldEntry->type == LibraryEntryType::File)
  572. deleteResourceInternal(static_cast<ResourceEntry*>(oldEntry));
  573. else if(oldEntry->type == LibraryEntryType::Directory)
  574. deleteDirectoryInternal(static_cast<DirectoryEntry*>(oldEntry));
  575. }
  576. else // Just moving internally
  577. {
  578. onEntryRemoved(oldEntry->path);
  579. ResourceEntry* resEntry = nullptr;
  580. if (oldEntry->type == LibraryEntryType::File)
  581. {
  582. resEntry = static_cast<ResourceEntry*>(oldEntry);
  583. removeDependencies(resEntry);
  584. }
  585. if(FileSystem::isFile(oldMetaPath))
  586. FileSystem::move(oldMetaPath, newMetaPath);
  587. DirectoryEntry* parent = oldEntry->parent;
  588. auto findIter = std::find(parent->mChildren.begin(), parent->mChildren.end(), oldEntry);
  589. if(findIter != parent->mChildren.end())
  590. parent->mChildren.erase(findIter);
  591. Path parentPath = newFullPath.getParent();
  592. DirectoryEntry* newEntryParent = nullptr;
  593. LibraryEntry* newEntryParentLib = findEntry(parentPath);
  594. if(newEntryParentLib != nullptr)
  595. {
  596. assert(newEntryParentLib->type == LibraryEntryType::Directory);
  597. newEntryParent = static_cast<DirectoryEntry*>(newEntryParentLib);
  598. }
  599. DirectoryEntry* newHierarchyParent = nullptr;
  600. if(newEntryParent == nullptr) // New path parent doesn't exist, so we need to create the hierarchy
  601. createInternalParentHierarchy(newFullPath, &newHierarchyParent, &newEntryParent);
  602. newEntryParent->mChildren.push_back(oldEntry);
  603. oldEntry->parent = newEntryParent;
  604. oldEntry->path = newFullPath;
  605. oldEntry->elementName = newFullPath.getWTail();
  606. if(oldEntry->type == LibraryEntryType::Directory) // Update child paths
  607. {
  608. Stack<LibraryEntry*> todo;
  609. todo.push(oldEntry);
  610. while(!todo.empty())
  611. {
  612. LibraryEntry* curEntry = todo.top();
  613. todo.pop();
  614. DirectoryEntry* curDirEntry = static_cast<DirectoryEntry*>(curEntry);
  615. for(auto& child : curDirEntry->mChildren)
  616. {
  617. child->path = child->parent->path;
  618. child->path.append(child->elementName);
  619. if(child->type == LibraryEntryType::Directory)
  620. todo.push(child);
  621. }
  622. }
  623. }
  624. onEntryAdded(oldEntry->path);
  625. if (resEntry != nullptr)
  626. {
  627. reimportDependants(oldFullPath);
  628. reimportDependants(newFullPath);
  629. }
  630. }
  631. }
  632. else // Moving from outside of the Resources folder (likely adding a new resource)
  633. {
  634. checkForModifications(newFullPath);
  635. }
  636. }
  637. void ProjectLibrary::copyEntry(const Path& oldPath, const Path& newPath, bool overwrite)
  638. {
  639. Path oldFullPath = oldPath;
  640. if (!oldFullPath.isAbsolute())
  641. oldFullPath.makeAbsolute(mResourcesFolder);
  642. Path newFullPath = newPath;
  643. if (!newFullPath.isAbsolute())
  644. newFullPath.makeAbsolute(mResourcesFolder);
  645. if (!FileSystem::exists(oldFullPath))
  646. return;
  647. FileSystem::copy(oldFullPath, newFullPath, overwrite);
  648. // Copying a file/folder outside of the Resources folder, no special handling needed
  649. if (!mResourcesFolder.includes(newFullPath))
  650. return;
  651. Path parentPath = newFullPath.getParent();
  652. DirectoryEntry* newEntryParent = nullptr;
  653. LibraryEntry* newEntryParentLib = findEntry(parentPath);
  654. if (newEntryParentLib != nullptr)
  655. {
  656. assert(newEntryParentLib->type == LibraryEntryType::Directory);
  657. newEntryParent = static_cast<DirectoryEntry*>(newEntryParentLib);
  658. }
  659. // If the source is outside of Resources folder, just plain import the copy
  660. LibraryEntry* oldEntry = findEntry(oldFullPath);
  661. if (oldEntry == nullptr)
  662. {
  663. checkForModifications(newFullPath);
  664. return;
  665. }
  666. // Both source and destination are within Resources folder, need to preserve import options on the copies
  667. LibraryEntry* newEntry = nullptr;
  668. if (FileSystem::isFile(newFullPath))
  669. {
  670. assert(oldEntry->type == LibraryEntryType::File);
  671. ResourceEntry* oldResEntry = static_cast<ResourceEntry*>(oldEntry);
  672. ImportOptionsPtr importOptions;
  673. if (oldResEntry->meta != nullptr)
  674. importOptions = oldResEntry->meta->getImportOptions();
  675. newEntry = addResourceInternal(newEntryParent, newFullPath, importOptions, true);
  676. }
  677. else
  678. {
  679. assert(oldEntry->type == LibraryEntryType::File);
  680. DirectoryEntry* oldDirEntry = static_cast<DirectoryEntry*>(oldEntry);
  681. DirectoryEntry* newDirEntry = addDirectoryInternal(newEntryParent, newFullPath);
  682. newEntry = newDirEntry;
  683. Stack<std::tuple<DirectoryEntry*, DirectoryEntry*>> todo;
  684. todo.push(std::make_tuple(oldDirEntry, newDirEntry));
  685. while (!todo.empty())
  686. {
  687. auto current = todo.top();
  688. todo.pop();
  689. DirectoryEntry* sourceDir = std::get<0>(current);
  690. DirectoryEntry* destDir = std::get<1>(current);
  691. for (auto& child : sourceDir->mChildren)
  692. {
  693. Path childDestPath = destDir->path;
  694. childDestPath.append(child->path.getWTail());
  695. if (child->type == LibraryEntryType::File)
  696. {
  697. ResourceEntry* childResEntry = static_cast<ResourceEntry*>(child);
  698. ImportOptionsPtr importOptions;
  699. if (childResEntry->meta != nullptr)
  700. importOptions = childResEntry->meta->getImportOptions();
  701. addResourceInternal(destDir, childDestPath, importOptions, true);
  702. }
  703. else // Directory
  704. {
  705. DirectoryEntry* childSourceDirEntry = static_cast<DirectoryEntry*>(child);
  706. DirectoryEntry* childDestDirEntry = addDirectoryInternal(destDir, childDestPath);
  707. todo.push(std::make_tuple(childSourceDirEntry, childSourceDirEntry));
  708. }
  709. }
  710. }
  711. }
  712. }
  713. void ProjectLibrary::deleteEntry(const Path& path)
  714. {
  715. Path fullPath = path;
  716. if (!fullPath.isAbsolute())
  717. fullPath.makeAbsolute(mResourcesFolder);
  718. if(FileSystem::exists(fullPath))
  719. FileSystem::remove(fullPath);
  720. LibraryEntry* entry = findEntry(fullPath);
  721. if(entry != nullptr)
  722. {
  723. if(entry->type == LibraryEntryType::File)
  724. deleteResourceInternal(static_cast<ResourceEntry*>(entry));
  725. else if(entry->type == LibraryEntryType::Directory)
  726. deleteDirectoryInternal(static_cast<DirectoryEntry*>(entry));
  727. }
  728. }
  729. void ProjectLibrary::reimport(const Path& path, const ImportOptionsPtr& importOptions, bool forceReimport)
  730. {
  731. LibraryEntry* entry = findEntry(path);
  732. if (entry != nullptr)
  733. {
  734. if (entry->type == LibraryEntryType::File)
  735. {
  736. ResourceEntry* resEntry = static_cast<ResourceEntry*>(entry);
  737. reimportResourceInternal(resEntry, importOptions, forceReimport);
  738. }
  739. }
  740. }
  741. void ProjectLibrary::setIncludeInBuild(const Path& path, bool include)
  742. {
  743. LibraryEntry* entry = findEntry(path);
  744. if (entry == nullptr || entry->type == LibraryEntryType::Directory)
  745. return;
  746. ResourceEntry* resEntry = static_cast<ResourceEntry*>(entry);
  747. if (resEntry->meta == nullptr)
  748. return;
  749. resEntry->meta->setIncludeInBuild(include);
  750. Path metaPath = resEntry->path;
  751. metaPath.setFilename(metaPath.getWFilename() + L".meta");
  752. FileEncoder fs(metaPath);
  753. fs.encode(resEntry->meta.get());
  754. }
  755. Vector<ProjectLibrary::ResourceEntry*> ProjectLibrary::getResourcesForBuild() const
  756. {
  757. Vector<ResourceEntry*> output;
  758. Stack<DirectoryEntry*> todo;
  759. todo.push(mRootEntry);
  760. while (!todo.empty())
  761. {
  762. DirectoryEntry* directory = todo.top();
  763. todo.pop();
  764. for (auto& child : directory->mChildren)
  765. {
  766. if (child->type == LibraryEntryType::File)
  767. {
  768. ResourceEntry* resEntry = static_cast<ResourceEntry*>(child);
  769. if (resEntry->meta != nullptr && resEntry->meta->getIncludeInBuild())
  770. output.push_back(resEntry);
  771. }
  772. else if (child->type == LibraryEntryType::Directory)
  773. {
  774. todo.push(static_cast<DirectoryEntry*>(child));
  775. }
  776. }
  777. }
  778. return output;
  779. }
  780. HResource ProjectLibrary::load(const Path& path)
  781. {
  782. LibraryEntry* entry = findEntry(path);
  783. if (entry == nullptr || entry->type == LibraryEntryType::Directory)
  784. return HResource();
  785. ResourceEntry* resEntry = static_cast<ResourceEntry*>(entry);
  786. if (resEntry->meta == nullptr)
  787. return HResource();
  788. String resUUID = resEntry->meta->getUUID();
  789. return gResources().loadFromUUID(resUUID);
  790. }
  791. void ProjectLibrary::createInternalParentHierarchy(const Path& fullPath, DirectoryEntry** newHierarchyRoot, DirectoryEntry** newHierarchyLeaf)
  792. {
  793. Path parentPath = fullPath;
  794. DirectoryEntry* newEntryParent = nullptr;
  795. Stack<Path> parentPaths;
  796. do
  797. {
  798. Path newParentPath = parentPath.getParent();
  799. if(newParentPath == parentPath)
  800. break;
  801. LibraryEntry* newEntryParentLib = findEntry(newParentPath);
  802. if(newEntryParentLib != nullptr)
  803. {
  804. assert(newEntryParentLib->type == LibraryEntryType::Directory);
  805. newEntryParent = static_cast<DirectoryEntry*>(newEntryParentLib);
  806. break;
  807. }
  808. parentPaths.push(newParentPath);
  809. parentPath = newParentPath;
  810. } while (true);
  811. assert(newEntryParent != nullptr); // Must exist
  812. if(newHierarchyRoot != nullptr)
  813. *newHierarchyRoot = newEntryParent;
  814. while(!parentPaths.empty())
  815. {
  816. Path curPath = parentPaths.top();
  817. parentPaths.pop();
  818. newEntryParent = addDirectoryInternal(newEntryParent, curPath);
  819. }
  820. if(newHierarchyLeaf != nullptr)
  821. *newHierarchyLeaf = newEntryParent;
  822. }
  823. Path ProjectLibrary::getMetaPath(const Path& path) const
  824. {
  825. Path metaPath = path;
  826. metaPath.setFilename(metaPath.getWFilename() + L".meta");
  827. return metaPath;
  828. }
  829. bool ProjectLibrary::isMeta(const Path& fullPath) const
  830. {
  831. return fullPath.getWExtension() == L".meta";
  832. }
  833. bool ProjectLibrary::isNative(ResourceEntry* resource) const
  834. {
  835. WString extension = resource->path.getWExtension();
  836. return extension == L".asset" || extension == L".prefab";
  837. }
  838. void ProjectLibrary::unloadLibrary()
  839. {
  840. if (!mIsLoaded)
  841. return;
  842. mProjectFolder = Path::BLANK;
  843. mResourcesFolder = Path::BLANK;
  844. clearEntries();
  845. mRootEntry = bs_new<DirectoryEntry>(mResourcesFolder, mResourcesFolder.getWTail(), nullptr);
  846. mDependencies.clear();
  847. gResources().unregisterResourceManifest(mResourceManifest);
  848. mResourceManifest = nullptr;
  849. mIsLoaded = false;
  850. }
  851. void ProjectLibrary::makeEntriesRelative()
  852. {
  853. // Make all paths relative before saving
  854. std::function<void(LibraryEntry*, const Path&)> makeRelative =
  855. [&](LibraryEntry* entry, const Path& root)
  856. {
  857. entry->path.makeRelative(root);
  858. if (entry->type == LibraryEntryType::Directory)
  859. {
  860. DirectoryEntry* dirEntry = static_cast<DirectoryEntry*>(entry);
  861. for (auto& child : dirEntry->mChildren)
  862. makeRelative(child, root);
  863. }
  864. };
  865. Path root = getResourcesFolder();
  866. makeRelative(mRootEntry, root);
  867. }
  868. void ProjectLibrary::makeEntriesAbsolute()
  869. {
  870. std::function<void(LibraryEntry*, const Path&)> makeAbsolute =
  871. [&](LibraryEntry* entry, const Path& root)
  872. {
  873. entry->path.makeAbsolute(root);
  874. if (entry->type == LibraryEntryType::Directory)
  875. {
  876. DirectoryEntry* dirEntry = static_cast<DirectoryEntry*>(entry);
  877. for (auto& child : dirEntry->mChildren)
  878. makeAbsolute(child, root);
  879. }
  880. };
  881. Path root = getResourcesFolder();
  882. makeAbsolute(mRootEntry, root);
  883. }
  884. void ProjectLibrary::saveLibrary()
  885. {
  886. if (!mIsLoaded)
  887. return;
  888. // Make all paths relative before saving
  889. makeEntriesRelative();
  890. std::shared_ptr<ProjectLibraryEntries> libEntries = ProjectLibraryEntries::create(*mRootEntry);
  891. Path libraryEntriesPath = mProjectFolder;
  892. libraryEntriesPath.append(INTERNAL_RESOURCES_DIR);
  893. libraryEntriesPath.append(LIBRARY_ENTRIES_FILENAME);
  894. FileEncoder fs(libraryEntriesPath);
  895. fs.encode(libEntries.get());
  896. // Restore absolute entry paths
  897. makeEntriesAbsolute();
  898. Path resourceManifestPath = mProjectFolder;
  899. resourceManifestPath.append(INTERNAL_RESOURCES_DIR);
  900. resourceManifestPath.append(RESOURCE_MANIFEST_FILENAME);
  901. ResourceManifest::save(mResourceManifest, resourceManifestPath, mProjectFolder);
  902. }
  903. void ProjectLibrary::loadLibrary()
  904. {
  905. unloadLibrary();
  906. mProjectFolder = gEditorApplication().getProjectPath();
  907. mResourcesFolder = mProjectFolder;
  908. mResourcesFolder.append(RESOURCES_DIR);
  909. mRootEntry = bs_new<DirectoryEntry>(mResourcesFolder, mResourcesFolder.getWTail(), nullptr);
  910. Path libraryEntriesPath = mProjectFolder;
  911. libraryEntriesPath.append(INTERNAL_RESOURCES_DIR);
  912. libraryEntriesPath.append(LIBRARY_ENTRIES_FILENAME);
  913. if(FileSystem::exists(libraryEntriesPath))
  914. {
  915. FileDecoder fs(libraryEntriesPath);
  916. std::shared_ptr<ProjectLibraryEntries> libEntries = std::static_pointer_cast<ProjectLibraryEntries>(fs.decode());
  917. *mRootEntry = libEntries->getRootEntry();
  918. for(auto& child : mRootEntry->mChildren)
  919. child->parent = mRootEntry;
  920. mRootEntry->parent = nullptr;
  921. }
  922. // Entries are stored relative to project folder, but we want their absolute paths now
  923. makeEntriesAbsolute();
  924. // Load resource manifest
  925. Path resourceManifestPath = mProjectFolder;
  926. resourceManifestPath.append(INTERNAL_RESOURCES_DIR);
  927. resourceManifestPath.append(RESOURCE_MANIFEST_FILENAME);
  928. if (FileSystem::exists(resourceManifestPath))
  929. mResourceManifest = ResourceManifest::load(resourceManifestPath, mProjectFolder);
  930. else
  931. mResourceManifest = ResourceManifest::create("ProjectLibrary");
  932. gResources().registerResourceManifest(mResourceManifest);
  933. // Load all meta files
  934. Stack<DirectoryEntry*> todo;
  935. todo.push(mRootEntry);
  936. Vector<LibraryEntry*> deletedEntries;
  937. while(!todo.empty())
  938. {
  939. DirectoryEntry* curDir = todo.top();
  940. todo.pop();
  941. for(auto& child : curDir->mChildren)
  942. {
  943. if(child->type == LibraryEntryType::File)
  944. {
  945. ResourceEntry* resEntry = static_cast<ResourceEntry*>(child);
  946. if (FileSystem::isFile(resEntry->path))
  947. {
  948. if (resEntry->meta == nullptr)
  949. {
  950. Path metaPath = resEntry->path;
  951. metaPath.setFilename(metaPath.getWFilename() + L".meta");
  952. if (FileSystem::isFile(metaPath))
  953. {
  954. FileDecoder fs(metaPath);
  955. std::shared_ptr<IReflectable> loadedMeta = fs.decode();
  956. if (loadedMeta != nullptr && loadedMeta->isDerivedFrom(ProjectResourceMeta::getRTTIStatic()))
  957. {
  958. ProjectResourceMetaPtr resourceMeta = std::static_pointer_cast<ProjectResourceMeta>(loadedMeta);
  959. resEntry->meta = resourceMeta;
  960. }
  961. }
  962. }
  963. if (resEntry->meta != nullptr)
  964. mUUIDToPath[resEntry->meta->getUUID()] = resEntry->path;
  965. addDependencies(resEntry);
  966. }
  967. else
  968. deletedEntries.push_back(resEntry);
  969. }
  970. else if(child->type == LibraryEntryType::Directory)
  971. {
  972. if (FileSystem::isDirectory(child->path))
  973. todo.push(static_cast<DirectoryEntry*>(child));
  974. else
  975. deletedEntries.push_back(child);
  976. }
  977. }
  978. }
  979. // Remove entries that no longer have corresponding files
  980. for (auto& deletedEntry : deletedEntries)
  981. {
  982. if (deletedEntry->type == LibraryEntryType::File)
  983. {
  984. ResourceEntry* resEntry = static_cast<ResourceEntry*>(deletedEntry);
  985. deleteResourceInternal(resEntry);
  986. }
  987. else
  988. {
  989. DirectoryEntry* dirEntry = static_cast<DirectoryEntry*>(deletedEntry);
  990. deleteDirectoryInternal(dirEntry);
  991. }
  992. }
  993. // Clean up internal library folder from obsolete files
  994. Path internalResourcesFolder = mProjectFolder;
  995. internalResourcesFolder.append(INTERNAL_RESOURCES_DIR);
  996. Vector<Path> toDelete;
  997. auto processFile = [&](const Path& file)
  998. {
  999. String uuid = file.getFilename(false);
  1000. if (mUUIDToPath.find(uuid) == mUUIDToPath.end())
  1001. {
  1002. mResourceManifest->unregisterResource(uuid);
  1003. toDelete.push_back(file);
  1004. }
  1005. return true;
  1006. };
  1007. FileSystem::iterate(internalResourcesFolder, processFile);
  1008. for (auto& entry : toDelete)
  1009. FileSystem::remove(entry);
  1010. mIsLoaded = true;
  1011. }
  1012. void ProjectLibrary::clearEntries()
  1013. {
  1014. if (mRootEntry == nullptr)
  1015. return;
  1016. std::function<void(LibraryEntry*)> deleteRecursive =
  1017. [&](LibraryEntry* entry)
  1018. {
  1019. if (entry->type == LibraryEntryType::Directory)
  1020. {
  1021. DirectoryEntry* dirEntry = static_cast<DirectoryEntry*>(entry);
  1022. for (auto& child : dirEntry->mChildren)
  1023. deleteRecursive(child);
  1024. }
  1025. bs_delete(entry);
  1026. };
  1027. deleteRecursive(mRootEntry);
  1028. mRootEntry = nullptr;
  1029. }
  1030. Vector<Path> ProjectLibrary::getImportDependencies(const ResourceEntry* entry)
  1031. {
  1032. Vector<Path> output;
  1033. if (entry->meta == nullptr)
  1034. return output;
  1035. if (entry->meta->getTypeID() == TID_Shader)
  1036. {
  1037. SPtr<ShaderMetaData> metaData = std::static_pointer_cast<ShaderMetaData>(entry->meta->getResourceMetaData());
  1038. for (auto& include : metaData->includes)
  1039. output.push_back(include);
  1040. }
  1041. return output;
  1042. }
  1043. void ProjectLibrary::addDependencies(const ResourceEntry* entry)
  1044. {
  1045. Vector<Path> dependencies = getImportDependencies(entry);
  1046. for (auto& dependency : dependencies)
  1047. mDependencies[dependency].push_back(entry->path);
  1048. }
  1049. void ProjectLibrary::removeDependencies(const ResourceEntry* entry)
  1050. {
  1051. Vector<Path> dependencies = getImportDependencies(entry);
  1052. for (auto& dependency : dependencies)
  1053. {
  1054. Vector<Path>& curDependencies = mDependencies[dependency];
  1055. auto iterRemove = std::remove_if(curDependencies.begin(), curDependencies.end(),
  1056. [&](const Path& x)
  1057. {
  1058. return x == entry->path;
  1059. });
  1060. curDependencies.erase(iterRemove, curDependencies.end());
  1061. }
  1062. }
  1063. void ProjectLibrary::reimportDependants(const Path& entryPath)
  1064. {
  1065. auto iterFind = mDependencies.find(entryPath);
  1066. if (iterFind == mDependencies.end())
  1067. return;
  1068. // Make a copy since we might modify this list during reimport
  1069. Vector<Path> dependencies = iterFind->second;
  1070. for (auto& dependency : dependencies)
  1071. {
  1072. LibraryEntry* entry = findEntry(dependency);
  1073. if (entry != nullptr && entry->type == LibraryEntryType::File)
  1074. {
  1075. ResourceEntry* resEntry = static_cast<ResourceEntry*>(entry);
  1076. ImportOptionsPtr importOptions;
  1077. if (resEntry->meta != nullptr)
  1078. importOptions = resEntry->meta->getImportOptions();
  1079. reimportResourceInternal(resEntry, importOptions, true);
  1080. }
  1081. }
  1082. }
  1083. BS_ED_EXPORT ProjectLibrary& gProjectLibrary()
  1084. {
  1085. return ProjectLibrary::instance();
  1086. }
  1087. }