diff --git a/include/eepp/ui/uimanager.hpp b/include/eepp/ui/uimanager.hpp index 529dba562..f3d3deb7d 100644 --- a/include/eepp/ui/uimanager.hpp +++ b/include/eepp/ui/uimanager.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace pugi { class xml_node; @@ -125,6 +126,10 @@ class EE_API UIManager { void loadLayoutFromString( const std::string& layoutString ); void loadLayoutFromMemory( const void * buffer, Int32 bufferSize ); + + void loadLayoutFromStream( IOStream& stream ); + + void loadLayoutFromPack( Pack * pack, const std::string& FilePackPath ); protected: friend class UIControl; friend class UIWindow; diff --git a/src/eepp/ui/uimanager.cpp b/src/eepp/ui/uimanager.cpp index ee0a3a399..c6a40df29 100644 --- a/src/eepp/ui/uimanager.cpp +++ b/src/eepp/ui/uimanager.cpp @@ -520,15 +520,24 @@ void UIManager::loadLayoutNodes( pugi::xml_node node, UIControl * parent ) { } void UIManager::loadLayout( const std::string& layoutPath ) { - pugi::xml_document doc; - pugi::xml_parse_result result = doc.load_file( layoutPath.c_str() ); + if ( FileSystem::fileExists( layoutPath ) ) { + pugi::xml_document doc; + pugi::xml_parse_result result = doc.load_file( layoutPath.c_str() ); - if ( result ) { - loadLayoutNodes( doc.first_child(), getMainControl() ); - } else { - eePRINTL( "Error: Couldn't load UI Layout: %s", layoutPath.c_str() ); - eePRINTL( "Error description: %s", result.description() ); - eePRINTL( "Error offset: %d", result.offset ); + if ( result ) { + loadLayoutNodes( doc.first_child(), getMainControl() ); + } else { + eePRINTL( "Error: Couldn't load UI Layout: %s", layoutPath.c_str() ); + eePRINTL( "Error description: %s", result.description() ); + eePRINTL( "Error offset: %d", result.offset ); + } + } else if ( PackManager::instance()->isFallbackToPacksActive() ) { + std::string path( layoutPath ); + Pack * pack = PackManager::instance()->exists( path ); + + if ( NULL != pack ) { + loadLayoutFromPack( pack, path ); + } } } void UIManager::loadLayoutFromString( const std::string& layoutString ) { @@ -557,4 +566,32 @@ void UIManager::loadLayoutFromMemory( const void * buffer, Int32 bufferSize ) { } } +void UIManager::loadLayoutFromStream( IOStream& stream ) { + if ( !stream.isOpen() ) + return; + + ios_size bufferSize = stream.getSize(); + SafeDataPointer safeDataPointer( eeNewArray( Uint8, bufferSize ), bufferSize ); + stream.read( reinterpret_cast( safeDataPointer.Data ), safeDataPointer.DataSize ); + + pugi::xml_document doc; + pugi::xml_parse_result result = doc.load_buffer( safeDataPointer.Data, safeDataPointer.DataSize ); + + if ( result ) { + loadLayoutNodes( doc.first_child(), getMainControl() ); + } else { + eePRINTL( "Error: Couldn't load UI Layout from stream" ); + eePRINTL( "Error description: %s", result.description() ); + eePRINTL( "Error offset: %d", result.offset ); + } +} + +void UIManager::loadLayoutFromPack( Pack * pack, const std::string& FilePackPath ) { + SafeDataPointer PData; + + if ( pack->isOpen() && pack->extractFileToMemory( FilePackPath, PData ) ) { + loadLayoutFromMemory( PData.Data, PData.DataSize ); + } +} + }}