diff --git a/materializer/DataTypes.hpp b/materializer/DataTypes.hpp index e36cbdc..9f711fa 100644 --- a/materializer/DataTypes.hpp +++ b/materializer/DataTypes.hpp @@ -235,21 +235,35 @@ namespace VSW::Materializer::DataTypes { }; struct Table_plugin { - int dll_index; - std::string dll_name; - int plugin_index; + // Category std::string category; - CKBOOL active; + // Dll infos + std::string dll_name; + int position_in_dll; + // Plugin infos int64_t guid; std::string desc; std::string author; std::string summary; DWORD version; + CK_PLUGIN_TYPE type; std::string func_init; std::string func_exit; + // Reader specific + std::string reader_fct; + int reader_opt_count; + CK_DATAREADER_FLAGS reader_flags; + int64_t reader_setting_param_guid; + std::string reader_file_ext; + // Manager and Render Engine specific + CKBOOL manager_active; + // Behavior specific + std::string behavior_guids; }; #if defined(VIRTOOLS_21) + // Virtools 2.1 doesn't have Variable Manager + // We use a normal type as a placeholder. using GenericVarType_t = int; #else using GenericVarType_t = CKVariableManager::Variable::Type; diff --git a/materializer/ExportEnvironment.cpp b/materializer/ExportEnvironment.cpp index 091692b..a11cc5a 100644 --- a/materializer/ExportEnvironment.cpp +++ b/materializer/ExportEnvironment.cpp @@ -102,6 +102,9 @@ namespace VSW::Materializer::ExportEnvironment { } static void IteratePlugin(ExportContext& expctx, CKPluginManager* plugin_mgr) { + // prepare variables + CK_PLUGIN_TYPE plugin_type; + // get category count and iterate them int category_count = plugin_mgr->GetCategoryCount(); for (int i = 0; i < category_count; ++i) { @@ -115,21 +118,65 @@ namespace VSW::Materializer::ExportEnvironment { CKPluginInfo* plugin_info = &(plugin_entry->m_PluginInfo); CKPluginDll* plugin_dll = plugin_mgr->GetPluginDllInfo(plugin_entry->m_PluginDllIndex); - expctx.cache.plugin.dll_index = plugin_entry->m_PluginDllIndex; - + // dll infomation (name + position in dll) expctx.cache.plugin.dll_name = plugin_dll->m_DllFileName.CStr(); + expctx.cache.plugin.position_in_dll = plugin_entry->m_PositionInDll; - expctx.cache.plugin.plugin_index = plugin_entry->m_PositionInDll; - expctx.cache.plugin.active = plugin_entry->m_Active; - + // plugin info Utilities::CopyGuid(expctx.cache.plugin.guid, plugin_info->m_GUID); expctx.cache.plugin.desc = plugin_info->m_Description.CStr(); expctx.cache.plugin.author = plugin_info->m_Author.CStr(); expctx.cache.plugin.summary = plugin_info->m_Summary.CStr(); expctx.cache.plugin.version = plugin_info->m_Version; + plugin_type = plugin_info->m_Type; + expctx.cache.plugin.type = plugin_type; expctx.cache.plugin.func_init = Utilities::RelativeAddress(plugin_info->m_InitInstanceFct); expctx.cache.plugin.func_exit = Utilities::RelativeAddress(plugin_info->m_ExitInstanceFct); + // extra fields according to plugin type + // first reset these specific fields + expctx.cache.plugin.reader_fct.clear(); + + // then try to fetch these specific fields + switch (plugin_type) { + case CKPLUGIN_BITMAP_READER: + case CKPLUGIN_SOUND_READER: + case CKPLUGIN_MODEL_READER: + case CKPLUGIN_MOVIE_READER: + { + // Reader specific + expctx.cache.plugin.reader_fct = Utilities::RelativeAddress(plugin_entry->m_ReadersInfo->m_GetReaderFct); + expctx.cache.plugin.reader_opt_count = plugin_entry->m_ReadersInfo->m_OptionCount; + expctx.cache.plugin.reader_flags = plugin_entry->m_ReadersInfo->m_ReaderFlags; + Utilities::CopyGuid(expctx.cache.plugin.reader_setting_param_guid, plugin_entry->m_ReadersInfo->m_SettingsParameterGuid); + expctx.cache.plugin.reader_file_ext = static_cast(plugin_info->m_Extension); + break; + } + case CKPLUGIN_BEHAVIOR_DLL: + { + // Behavior specific + std::vector guids; + for (int i = 0; i < plugin_entry->m_BehaviorsInfo->m_BehaviorsGUID.Size(); ++i) { + int64_t guid_cache; + Utilities::CopyGuid(guid_cache, plugin_entry->m_BehaviorsInfo->m_BehaviorsGUID[i]); + guids.emplace_back(YYCC::ParserHelper::ToString(guid_cache)); + } + expctx.cache.plugin.behavior_guids = YYCC::EncodingHelper::ToOrdinaryView( + YYCC::StringHelper::Join(guids, YYCC_U8(", ")) + ); + break; + } + case CKPLUGIN_MANAGER_DLL: + case CKPLUGIN_RENDERENGINE_DLL: + { + // Render engine and manager specific + // active info + expctx.cache.plugin.manager_active = plugin_entry->m_Active; + break; + } + } + + expctx.db.Write(expctx.cache.plugin); } } @@ -139,17 +186,50 @@ namespace VSW::Materializer::ExportEnvironment { static void IterateVariable(ExportContext& expctx, CKVariableManager* var_mgr) { // prepare variables CKVariableManager::Variable* varobj = nullptr; + const char* var_name; + CKVariableManager::Variable::Type var_type; + const char* var_representation; + int int_cache; + float float_cache; XString xstring_cache; for (CKVariableManager::Iterator it = var_mgr->GetVariableIterator(); !it.End(); it++) { + // get variable varobj = it.GetVariable(); - expctx.cache.variable.name = it.GetName(); + // variable name + var_name = it.GetName(); + expctx.cache.variable.name = var_name; + // variable description Utilities::CopyCKString(expctx.cache.variable.desciption, varobj->GetDescription()); + // variable flags expctx.cache.variable.flags = varobj->GetFlags(); - expctx.cache.variable.type = varobj->GetType(); - Utilities::CopyCKString(expctx.cache.variable.representation, varobj->GetRepresentation()); - varobj->GetStringValue(xstring_cache); - expctx.cache.variable.data = xstring_cache.CStr(); + // variable type + var_type = varobj->GetType(); + expctx.cache.variable.type = var_type; + // variable representation + // Representation need a special treatment. + // Because it is not a name. + // So we should record it as empty string if it is nullptr, instead of default + var_representation = varobj->GetRepresentation(); + Utilities::CopyCKString(expctx.cache.variable.representation, var_representation, ""); + // We output variable stored value in different way + // according to its type. + switch (var_type) { + case CKVariableManager::Variable::Type::INT: + var_mgr->GetValue(var_name, &int_cache); + expctx.cache.variable.data = YYCC::EncodingHelper::ToOrdinaryView(YYCC::ParserHelper::ToString(int_cache)); + break; + case CKVariableManager::Variable::Type::FLOAT: + var_mgr->GetValue(var_name, &float_cache); + expctx.cache.variable.data = YYCC::EncodingHelper::ToOrdinaryView(YYCC::ParserHelper::ToString(float_cache)); + break; + case CKVariableManager::Variable::Type::STRING: + var_mgr->GetValue(var_name, xstring_cache); + expctx.cache.variable.data = xstring_cache.CStr(); + break; + default: + throw std::runtime_error("invalid variable type!"); + } expctx.db.Write(expctx.cache.variable); } diff --git a/materializer/Utilities.cpp b/materializer/Utilities.cpp index 4276665..dbab7ac 100644 --- a/materializer/Utilities.cpp +++ b/materializer/Utilities.cpp @@ -41,6 +41,11 @@ namespace VSW::Materializer::Utilities { return ret; } + //void CopyStrGuid(std::string& dst, const CKGUID& src) { + // auto ret = YYCC::StringHelper::Printf(YYCC_U8("<0x%08" PRIX32 ", 0x%08" PRIX32 ">"), src.d1, src.d2); + // dst = YYCC::EncodingHelper::ToOrdinaryView(ret); + //} + void CopyGuid(int64_t& dst, const CKGUID& src) { // todo: use template argument to implement this to improve performance if (sizeof(dst) != sizeof(src)) @@ -48,8 +53,10 @@ namespace VSW::Materializer::Utilities { std::memcpy(&dst, &src, sizeof(int64_t)); } - void CopyCKString(std::string& storage, const char* str) { - if (str == nullptr) storage = ""; + void CopyCKString(std::string& storage, const char* str, const char* fallback) { + if (fallback == nullptr) + throw std::invalid_argument("fallback string should not be nullptr!"); + if (str == nullptr) storage = fallback; else storage = str; } diff --git a/materializer/Utilities.hpp b/materializer/Utilities.hpp index c4f53bb..37b530c 100644 --- a/materializer/Utilities.hpp +++ b/materializer/Utilities.hpp @@ -26,7 +26,8 @@ namespace VSW::Materializer::Utilities { * @return Module based relative address like \c xxx.dll+0x00000000. */ std::string RelativeAddress(const void* absolute_addr); + //void CopyStrGuid(std::string& dst, const CKGUID& src); void CopyGuid(int64_t& dst, const CKGUID& src); - void CopyCKString(std::string& storage, const char* str); + void CopyCKString(std::string& storage, const char* str, const char* fallback = ""); }