BsPlainTextImporter.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsPlainTextImporter.h"
  4. #include "BsPlainText.h"
  5. #include "BsDataStream.h"
  6. #include "BsFileSystem.h"
  7. namespace BansheeEngine
  8. {
  9. PlainTextImporter::PlainTextImporter()
  10. :SpecificImporter()
  11. {
  12. }
  13. PlainTextImporter::~PlainTextImporter()
  14. {
  15. }
  16. bool PlainTextImporter::isExtensionSupported(const WString& ext) const
  17. {
  18. WString lowerCaseExt = ext;
  19. StringUtil::toLowerCase(lowerCaseExt);
  20. return lowerCaseExt == L"txt" || lowerCaseExt == L"xml" || lowerCaseExt == L"json";
  21. }
  22. bool PlainTextImporter::isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const
  23. {
  24. return true; // Plain-text so we don't even check for magic number
  25. }
  26. SPtr<Resource> PlainTextImporter::import(const Path& filePath, SPtr<const ImportOptions> importOptions)
  27. {
  28. SPtr<DataStream> stream = FileSystem::openFile(filePath);
  29. WString textData = stream->getAsWString();
  30. SPtr<PlainText> plainText = PlainText::_createPtr(textData);
  31. WString fileName = filePath.getWFilename(false);
  32. plainText->setName(fileName);
  33. return plainText;
  34. }
  35. }