CmImporter.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "CmImporter.h"
  2. #include "CmPath.h"
  3. #include "CmSpecificImporter.h"
  4. #include "CmDebug.h"
  5. #include "CmException.h"
  6. namespace CamelotEngine
  7. {
  8. Importer::~Importer()
  9. {
  10. for(auto i = mAssetImporters.begin(); i != mAssetImporters.end(); ++i)
  11. {
  12. if((*i) != nullptr)
  13. delete *i;
  14. }
  15. mAssetImporters.clear();
  16. }
  17. bool Importer::supportsFileType(const std::string& extension) const
  18. {
  19. for(auto iter = mAssetImporters.begin(); iter != mAssetImporters.end(); ++iter)
  20. {
  21. if(*iter != nullptr && (*iter)->isExtensionSupported(extension))
  22. return true;
  23. }
  24. return false;
  25. }
  26. bool Importer::supportsFileType(const UINT8* magicNumber, UINT32 magicNumSize) const
  27. {
  28. for(auto iter = mAssetImporters.begin(); iter != mAssetImporters.end(); ++iter)
  29. {
  30. if(*iter != nullptr && (*iter)->isMagicNumberSupported(magicNumber, magicNumSize))
  31. return true;
  32. }
  33. return false;
  34. }
  35. void Importer::import(const String& inputFilePath, const String& outputFilePath, bool keepReferences)
  36. {
  37. if(!Path::exists(inputFilePath))
  38. {
  39. LOGWRN("Trying to import asset that doesn't exists. Asset path: " + inputFilePath);
  40. return;
  41. }
  42. String ext = Path::getExtension(inputFilePath);
  43. ext = ext.substr(1, ext.size() - 1); // Remove the .
  44. if(!supportsFileType(ext))
  45. {
  46. LOGWRN("There is no importer for the provided file type. (" + inputFilePath + ")");
  47. return;
  48. }
  49. //SpecificImporter* importer = mAssetImporters[ext];
  50. //ResourcePtr importedResource = importer->import(inputFilePath);
  51. // TODO - Use AssetDatabase for loading the resource
  52. // TODO - Serialize the resource to output location
  53. }
  54. void Importer::registerAssetImporter(SpecificImporter* importer)
  55. {
  56. if(!importer)
  57. {
  58. LOGWRN("Trying to register a null asset importer!");
  59. return;
  60. }
  61. mAssetImporters.push_back(importer);
  62. }
  63. }