Esempio n. 1
0
 public static bool registerPlugin(PluginBase plugin)
 {
     if (plugin == null)
     {
         return(false);
     }
     if (!PluginBase.isValidPlugin(plugin))
     {
         Log.i("ExtentCenter", "register plugin... " + plugin.mName);
         plugin.onRegisterResult(RetConst.MM_OK, 0);
         plugin.mMetaInfo.isRegistered = true;
         PluginMetaStorage.updateMetaInfo(plugin);
     }
     return(true);
 }
Esempio n. 2
0
 public static void syncPluginInstall(PluginBase plug, uint newFlag)
 {
     if (PluginBase.isValidPlugin(plug) && (plug.mProtocolPluginFlag != ((EPluginFlag)0)))
     {
         uint num = (uint)(((EPluginFlag)newFlag) & plug.mProtocolPluginFlag);
         if ((num != 0) && plug.isInstalledPlugin())
         {
             uninstallPlugin(plug, InstallMode.SyncInstall);
         }
         else if ((num == 0) && !plug.isInstalledPlugin())
         {
             installPlugin(plug, InstallMode.SyncInstall);
         }
     }
 }
Esempio n. 3
0
        public static bool restoreMetaInfo(PluginBase plug)
        {
            if ((mPluginMetaMap == null) || (plug == null))
            {
                return(false);
            }
            string key = plug.mName + plug.mID;

            if (!mPluginMetaMap.mapPluginMetaInfo.ContainsKey(key))
            {
                return(false);
            }
            PluginMetaInfo plugMeta = mPluginMetaMap.mapPluginMetaInfo[key];

            plug.mMetaInfo.copyFrom(plugMeta);
            return(true);
        }
Esempio n. 4
0
        public static PluginBase getPluginByChatTalker(string talker)
        {
            if (string.IsNullOrEmpty(talker))
            {
                return(null);
            }
            PluginBase ret = null;

            PluginManager.searchOnePlugin(delegate(PluginBase plug) {
                if (plug.onParseChatTalker(talker))
                {
                    ret = plug;
                    return(true);
                }
                return(false);
            });
            return(ret);
        }
Esempio n. 5
0
        public static PluginBase getPluginByChatMsg(ChatMsg chatMsg)
        {
            if (chatMsg == null)
            {
                return(null);
            }
            PluginBase ret = null;

            PluginManager.searchOnePlugin(delegate(PluginBase plug) {
                if (plug.onParseChatMsg(chatMsg))
                {
                    ret = plug;
                    return(true);
                }
                return(false);
            });
            return(ret);
        }
Esempio n. 6
0
        public static bool addPlugin(PluginBase plugin)
        {
            if (plugin == null)
            {
                return(false);
            }
            if (mListPlugin.Contains(plugin))
            {
                return(false);
            }
            PluginBase item = findPluginByName(plugin.mName);

            if (item != null)
            {
                mListPlugin.Remove(item);
            }
            mListPlugin.Add(plugin);
            return(true);
        }
Esempio n. 7
0
 public static bool updateMetaInfo(PluginBase plug)
 {
     if ((mPluginMetaMap != null) && PluginBase.isValidPlugin(plug))
     {
         string key = plug.mName + plug.mID;
         if (!mPluginMetaMap.mapPluginMetaInfo.ContainsKey(key))
         {
             PluginMetaInfo info = new PluginMetaInfo();
             info.copyFrom(plug.mMetaInfo);
             mPluginMetaMap.mapPluginMetaInfo.Add(key, info);
         }
         else
         {
             mPluginMetaMap.mapPluginMetaInfo[key].copyFrom(plug.mMetaInfo);
         }
         flushMetaToXML();
     }
     return(true);
 }
Esempio n. 8
0
 public static bool unregisterPlugin(PluginBase plugin)
 {
     if (plugin == null)
     {
         return(false);
     }
     if (PluginBase.isValidPlugin(plugin))
     {
         Log.i("ExtentCenter", "unregister plugin... " + plugin.mName);
         if (plugin.isInstalledPlugin())
         {
             plugin.onUninstalled(InstallMode.DefaultInstall);
             plugin.mMetaInfo.isInstalled = false;
         }
         plugin.onUnRegisterResult(RetConst.MM_OK, 0);
         plugin.mMetaInfo.isRegistered = false;
         PluginMetaStorage.updateMetaInfo(plugin);
     }
     return(true);
 }
Esempio n. 9
0
 public static bool uninstallPlugin(PluginBase plugin, InstallMode mode = 0)
 {
     if (!PluginBase.isValidPlugin(plugin))
     {
         return(false);
     }
     if (!PluginBase.isInstalledPlugin(plugin))
     {
         return(false);
     }
     Log.i("ExtentCenter", string.Concat(new object[] { "uninstall plugin... ", plugin.mName, ", uninstall mode =", mode }));
     plugin.onUninstalled(mode);
     plugin.mMetaInfo.isInstalled = false;
     PluginMetaStorage.updateMetaInfo(plugin);
     if ((mode == InstallMode.UserInstall) && (plugin.mProtocolPluginFlag != ((EPluginFlag)0)))
     {
         Account acc = AccountMgr.getCurAccount();
         acc.nPluginFlag = (uint)(((EPluginFlag)acc.nPluginFlag) | plugin.mProtocolPluginFlag);
         AccountMgr.updateAccount();
         // OpLogMgr.opModUserInfo(0x800, acc);
         ServiceCenter.sceneNewSync.doScene(7, syncScene.MM_NEWSYNC_SCENE_OTHER);
     }
     return(true);
 }
Esempio n. 10
0
        public static bool preLoadPlugin(string className)
        {
            string typeName = "MicroMsg.Plugin." + className + "." + className;
            Type   type     = Type.GetType(typeName);

            if (type == null)
            {
                Log.e("PluginLoader", "Not found class, name =  " + typeName);
                return(false);
            }
            Type c = typeof(PluginBase);

            if (!type.IsSubclassOf(c))
            {
                Log.e("PluginLoader", "Not a plugin class, name = " + typeName);
                return(false);
            }
            PluginBase plug = Activator.CreateInstance(type) as PluginBase;

            if (plug == null)
            {
                Log.e("PluginLoader", "Failed to create instance, name = " + typeName);
                return(false);
            }
            if (!plug.mEnabled)
            {
                Log.e("PluginLoader", "Plugin disabled, name = " + typeName);
                return(false);
            }
            Account account = AccountMgr.getCurAccount();

            if (!PluginMetaStorage.restoreMetaInfo(plug))
            {
                Log.i("PluginLoader", "First load plugin, name = " + typeName);
                if (!ExtentCenter.registerPlugin(plug))
                {
                    Log.e("PluginLoader", "Not pass to register plugin, name = " + typeName);
                    return(false);
                }
                if (plug.mProtocolPluginFlag != ((EPluginFlag)0))
                {
                    if ((((EPluginFlag)account.nPluginFlag) & plug.mProtocolPluginFlag) == ((EPluginFlag)0))
                    {
                        ExtentCenter.installPlugin(plug, InstallMode.DefaultInstall);
                    }
                }
                else if (plug.mDefaultInstalled)
                {
                    ExtentCenter.installPlugin(plug, InstallMode.DefaultInstall);
                }
            }
            else
            {
                Log.i("PluginLoader", "Restore plugin completed, name = " + typeName);
                if (!PluginBase.isValidPlugin(plug))
                {
                    Log.e("PluginLoader", "Ignored invalid plugin , name = " + typeName);
                    return(false);
                }
                ExtentCenter.initializePlugin(plug);
                ExtentCenter.syncPluginInstall(plug, account.nPluginFlag);
            }
            PluginManager.addPlugin(plug);
            return(true);
        }