1 /*! 2 @file 3 @author Ustinov Igor aka Igor', DadyaIgor 4 @date 09/2011 5 */ 6 7 #include "MyGUI_DirectX11DataManager.h" 8 #include "MyGUI_DirectX11Diagnostic.h" 9 #include "MyGUI_DataFileStream.h" 10 #include "FileSystemInfo/FileSystemInfo.h" 11 #include <fstream> 12 13 namespace MyGUI 14 { 15 DirectX11DataManager()16 DirectX11DataManager::DirectX11DataManager() : 17 mIsInitialise(false) 18 { 19 } 20 initialise()21 void DirectX11DataManager::initialise() 22 { 23 MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 24 MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName()); 25 26 MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized"); 27 mIsInitialise = true; 28 } 29 shutdown()30 void DirectX11DataManager::shutdown() 31 { 32 MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 33 MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName()); 34 35 MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown"); 36 mIsInitialise = false; 37 } 38 getData(const std::string & _name)39 IDataStream* DirectX11DataManager::getData(const std::string& _name) 40 { 41 std::string filepath = getDataPath(_name); 42 if (filepath.empty()) 43 return nullptr; 44 45 std::ifstream* stream = new std::ifstream(); 46 stream->open(filepath.c_str(), std::ios_base::binary); 47 48 if (!stream->is_open()) 49 { 50 delete stream; 51 return nullptr; 52 } 53 54 DataFileStream* data = new DataFileStream(stream); 55 56 return data; 57 } 58 freeData(IDataStream * _data)59 void DirectX11DataManager::freeData(IDataStream* _data) 60 { 61 delete _data; 62 } 63 isDataExist(const std::string & _name)64 bool DirectX11DataManager::isDataExist(const std::string& _name) 65 { 66 const VectorString& files = getDataListNames(_name); 67 return !files.empty(); 68 } 69 getDataListNames(const std::string & _pattern)70 const VectorString& DirectX11DataManager::getDataListNames(const std::string& _pattern) 71 { 72 static VectorString result; 73 common::VectorWString wresult; 74 result.clear(); 75 76 for (VectorArhivInfo::const_iterator item = mPaths.begin(); item != mPaths.end(); ++item) 77 { 78 common::scanFolder(wresult, (*item).name, (*item).recursive, MyGUI::UString(_pattern).asWStr(), false); 79 } 80 81 for (common::VectorWString::const_iterator item = wresult.begin(); item != wresult.end(); ++item) 82 { 83 result.push_back(MyGUI::UString(*item).asUTF8()); 84 } 85 86 return result; 87 } 88 getDataPath(const std::string & _name)89 const std::string& DirectX11DataManager::getDataPath(const std::string& _name) 90 { 91 static std::string path; 92 VectorString result; 93 common::VectorWString wresult; 94 path.clear(); 95 96 for (VectorArhivInfo::const_iterator item = mPaths.begin(); item != mPaths.end(); ++item) 97 { 98 common::scanFolder(wresult, (*item).name, (*item).recursive, MyGUI::UString(_name).asWStr(), true); 99 } 100 101 for (common::VectorWString::const_iterator item = wresult.begin(); item != wresult.end(); ++item) 102 { 103 result.push_back(MyGUI::UString(*item).asUTF8()); 104 } 105 106 if (!result.empty()) 107 { 108 path = result[0]; 109 if (result.size() > 1) 110 { 111 MYGUI_PLATFORM_LOG(Warning, "There are several files with name '" << _name << "'. '" << path << "' was used."); 112 MYGUI_PLATFORM_LOG(Warning, "Other candidates are:"); 113 for (size_t index = 1; index < result.size(); index ++) 114 MYGUI_PLATFORM_LOG(Warning, " - '" << result[index] << "'"); 115 } 116 } 117 118 return path; 119 } 120 addResourceLocation(const std::string & _name,bool _recursive)121 void DirectX11DataManager::addResourceLocation(const std::string& _name, bool _recursive) 122 { 123 ArhivInfo info; 124 info.name = MyGUI::UString(_name).asWStr(); 125 info.recursive = _recursive; 126 mPaths.push_back(info); 127 } 128 129 } // namespace MyGUI 130