1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
---|---|
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #include "Resources/BsPlainTextImporter.h" |
4 | #include "Resources/BsPlainText.h" |
5 | #include "FileSystem/BsDataStream.h" |
6 | #include "FileSystem/BsFileSystem.h" |
7 | |
8 | namespace bs |
9 | { |
10 | bool PlainTextImporter::isExtensionSupported(const String& ext) const |
11 | { |
12 | String lowerCaseExt = ext; |
13 | StringUtil::toLowerCase(lowerCaseExt); |
14 | |
15 | return lowerCaseExt == u8"txt"|| lowerCaseExt == u8 "xml"|| lowerCaseExt == u8 "json"; |
16 | } |
17 | |
18 | bool PlainTextImporter::isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const |
19 | { |
20 | return true; // Plain-text so we don't even check for magic number |
21 | } |
22 | |
23 | SPtr<Resource> PlainTextImporter::import(const Path& filePath, SPtr<const ImportOptions> importOptions) |
24 | { |
25 | WString textData; |
26 | { |
27 | Lock fileLock = FileScheduler::getLock(filePath); |
28 | |
29 | SPtr<DataStream> stream = FileSystem::openFile(filePath); |
30 | textData = stream->getAsWString(); |
31 | } |
32 | |
33 | SPtr<PlainText> plainText = PlainText::_createPtr(textData); |
34 | |
35 | String fileName = filePath.getFilename(false); |
36 | plainText->setName(fileName); |
37 | |
38 | return plainText; |
39 | } |
40 | } |