Esempio n. 1
0
        /// <summary>
        /// Loads Plugins (Servers and Processors) from a Directory
        /// </summary>
        /// <param name="D">Plugin directory with info.txt file in it</param>
        private static void loadModule(string D)
        {
            NameValueCollection NVC = Base.ParseContent(File.ReadAllText(Path.Combine(D, "info.txt")));

            if (!string.IsNullOrEmpty(NVC["FILE"]) && !string.IsNullOrEmpty(NVC["TYPE"]))
            {
                if (Contains(NVC["TYPE"].ToLower().Split(','), "genericprocessor"))
                {
                    if (NVC["FILE"].Contains("."))
                    {
                        try
                        {
                            switch (NVC["FILE"].Substring(NVC["FILE"].LastIndexOf('.') + 1).ToUpper())
                            {
                            case "CS":
                                AddonManager.LoadProcessor(Path.Combine(D, NVC["FILE"]));
                                break;

                            case "DLL":
                                AddonManager.LoadProcessorLib(Path.Combine(D, NVC["FILE"]));
                                break;

                            default:
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            LOG(string.Format("Cannot load server module {0}", NVC["NAME"]));
                            LOG(string.Format(ex.Message));
                            if (AddonManager.LastErrors != null)
                            {
                                foreach (var e in AddonManager.LastErrors)
                                {
                                    LOG(e.ToString());
                                }
                                AddonManager.LastErrors = null;
                            }
                        }
                    }
                }
            }

            //Load Servers
            if (!string.IsNullOrEmpty(NVC["FILE"]) && !string.IsNullOrEmpty(NVC["TYPE"]))
            {
                if (Contains(NVC["TYPE"].ToLower().Split(','), "genericserver"))
                {
                    if (NVC["FILE"].Contains("."))
                    {
                        try
                        {
                            switch (NVC["FILE"].Substring(NVC["FILE"].LastIndexOf('.') + 1).ToUpper())
                            {
                            case "CS":
                                AddonManager.LoadServer(Path.Combine(D, NVC["FILE"]));
                                break;

                            case "DLL":
                                AddonManager.LoadServerLib(Path.Combine(D, NVC["FILE"]));
                                break;

                            default:
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            LOG(string.Format("Cannot load server module {0}", NVC["NAME"]));
                            LOG(string.Format(ex.Message));
                            if (AddonManager.LastErrors != null)
                            {
                                foreach (var e in AddonManager.LastErrors)
                                {
                                    LOG(e.ToString());
                                }
                                AddonManager.LastErrors = null;
                            }
                        }
                    }
                }
            }
        }