From 0862db3d034fa48db5a35b852d880bcddbd6d674 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 31 Mar 2022 21:59:14 +0800 Subject: [PATCH] improved PlugInManage --- inc/hgl/filesystem/FileSystem.h | 1 - inc/hgl/plugin/PlugInManage.h | 8 ++------ inc/hgl/type/Smart.h | 1 + src/PlugIn/ExternalPlugIn.cpp | 7 ++++++- src/PlugIn/PlugInManage.cpp | 23 +++++++++++++++++++++++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/inc/hgl/filesystem/FileSystem.h b/inc/hgl/filesystem/FileSystem.h index 7a72092..8dee7fd 100644 --- a/inc/hgl/filesystem/FileSystem.h +++ b/inc/hgl/filesystem/FileSystem.h @@ -47,7 +47,6 @@ namespace hgl bool GetLocalAppdataPath(OSString &); ///<取得当前用户应用程序数据存放路径 bool GetOSLibararyPath(OSString &); ///<取得操作系统共用动态库路径 - /** * @param filename 要查找的文件名称 diff --git a/inc/hgl/plugin/PlugInManage.h b/inc/hgl/plugin/PlugInManage.h index c5ed464..ab0bf53 100644 --- a/inc/hgl/plugin/PlugInManage.h +++ b/inc/hgl/plugin/PlugInManage.h @@ -17,12 +17,8 @@ namespace hgl public: - PlugInManage(const OSString &n) - { - name=n; - } - - virtual ~PlugInManage(); + PlugInManage(const OSString &n); + virtual ~PlugInManage()=default; bool RegistryPlugin(PlugIn *); ///<注册一个内置插件 uint UnregistryPlugin(const OSString &); ///<释放一个内置插件 diff --git a/inc/hgl/type/Smart.h b/inc/hgl/type/Smart.h index bf4a0b4..249dcdf 100644 --- a/inc/hgl/type/Smart.h +++ b/inc/hgl/type/Smart.h @@ -204,6 +204,7 @@ namespace hgl } T * get ()const{return sd?sd->data:0;} + const T * const_get ()const{return sd?sd->data:0;} virtual bool valid ()const{return sd;} int use_count ()const{return sd?sd->count:-1;} bool only ()const{return sd?sd->count==1:true;} diff --git a/src/PlugIn/ExternalPlugIn.cpp b/src/PlugIn/ExternalPlugIn.cpp index bd76f66..11fb51a 100644 --- a/src/PlugIn/ExternalPlugIn.cpp +++ b/src/PlugIn/ExternalPlugIn.cpp @@ -19,7 +19,9 @@ namespace hgl { if(!pi_module)return; - plugin_interface->Close(); + if(plugin_interface->Close) + plugin_interface->Close(); + plugin_interface=nullptr; delete pi_module; @@ -74,6 +76,9 @@ namespace hgl { if(!plugin_interface)return(false); + if(!plugin_interface->GetInterface) + return(false); + return plugin_interface->GetInterface(ver,interface_data); } }//namespace hgl diff --git a/src/PlugIn/PlugInManage.cpp b/src/PlugIn/PlugInManage.cpp index 792cc69..0b6a512 100644 --- a/src/PlugIn/PlugInManage.cpp +++ b/src/PlugIn/PlugInManage.cpp @@ -5,6 +5,29 @@ namespace hgl { using namespace filesystem; + PlugInManage::PlugInManage(const OSString &n) + { + name=OS_TEXT("CMP.")+n; + + OSString pn; + + if(filesystem::GetCurrentPath(pn)) + { + AddFindPath(pn); + + pn=MergeFilename(pn,OS_TEXT("Plug-ins")); + AddFindPath(pn); + } + + if(filesystem::GetCurrentProgramPath(pn)) + { + AddFindPath(pn); + + pn=MergeFilename(pn,OS_TEXT("Plug-ins")); + AddFindPath(pn); + } + } + bool PlugInManage::RegistryPlugin(PlugIn *pi) { if(!pi)return(false);