CreateMod() protected method

Creates a mod of the appropriate type from the specified file.
protected CreateMod ( string p_strModPath, string p_strCachePath, IGameMode p_gmdGameMode ) : IMod
p_strModPath string The path to the mod file.
p_strCachePath string The path to the cache file.
p_gmdGameMode IGameMode The game mode for which to create the plugin.
return IMod
        /// <summary>
        /// Searches for mods in the specified path, and loads
        /// any mods that are found into a registry.
        /// </summary>
        /// <param name="p_frgFormatRegistry">The <see cref="IModFormatRegistry"/> that contains the list
        /// of supported <see cref="IModFormat"/>s.</param>
        /// <param name="p_strSearchPath">The path in which to search for mod format assemblies.</param>
        /// <param name="p_booRecurse">Whether to check sub folders of <paramref name="p_strSearchPath"/> for mods.</param>
        /// <param name="p_gmdGameMode">The game mode for which to discover mods.</param>
        /// <param name="p_strExcludedSubDirectories">The list of subdirectories not to examine for mods.</param>
        /// <returns>A registry containing all of the discovered mods.</returns>
        public static ModRegistry DiscoverManagedMods(IModFormatRegistry p_frgFormatRegistry, IModCacheManager p_frgCacheManager, string p_strSearchPath, bool p_booRecurse, IEnvironmentInfo p_eiEnvironmentInfo, IGameMode p_gmdGameMode, params string[] p_strExcludedSubDirectories)
        {
            Trace.TraceInformation("Discovering Managed Mods...");
            Trace.Indent();

            Trace.TraceInformation("Looking in: {0}", p_strSearchPath);

            List <string> lstExludedPaths = new List <string>();

            for (Int32 i = 0; i < p_strExcludedSubDirectories.Length; i++)
            {
                lstExludedPaths.Add((p_strExcludedSubDirectories[i].Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar).ToLower());
            }

            ModRegistry mdrRegistry = new ModRegistry(p_frgFormatRegistry, p_gmdGameMode);

            string[]      strMods     = Directory.GetFiles(p_strSearchPath, "*", p_booRecurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
            IMod          modMod      = null;
            List <string> modList     = new List <String>();
            bool          booExcluded = false;

            foreach (string strMod in strMods)
            {
                string strModPath = strMod.ToLower();
                booExcluded = false;

                if (strModPath.EndsWith(".meta"))
                {
                    continue;
                }

                foreach (string strExclusion in lstExludedPaths)
                {
                    if (strModPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).StartsWith(strExclusion))
                    {
                        booExcluded = true;
                        break;
                    }
                }
                if (booExcluded)
                {
                    continue;
                }
                Trace.TraceInformation("Found: {0}", strMod);

                try
                {
                    string strCachePath = p_frgCacheManager.GetCacheFilePath(strMod);
                    modMod = mdrRegistry.CreateMod(strMod, strCachePath, p_gmdGameMode, p_eiEnvironmentInfo);
                }
                catch
                {
                    modList.Add(strMod);
                    modMod = null;
                }

                if (modMod == null)
                {
                    continue;
                }
                mdrRegistry.m_oclRegisteredMods.Add(modMod);
                Trace.Indent();
                Trace.TraceInformation("Registered.");
                Trace.Unindent();
            }

            p_eiEnvironmentInfo.Settings.CacheOverhaulSetup = true;
            p_eiEnvironmentInfo.Settings.Save();

            if (modList.Count > 0)
            {
                string strErrorMessage = "Error loading the following mods: " + Environment.NewLine;
                foreach (string modstr in modList)
                {
                    strErrorMessage += modstr + Environment.NewLine;
                }
                MessageBox.Show(strErrorMessage, "Mod loading error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Trace.Unindent();
            return(mdrRegistry);
        }
		/// <summary>
		/// Searches for mods in the specified path, and loads
		/// any mods that are found into a registry.
		/// </summary>
		/// <param name="p_frgFormatRegistry">The <see cref="IModFormatRegistry"/> that contains the list
		/// of supported <see cref="IModFormat"/>s.</param>
		/// <param name="p_strSearchPath">The path in which to search for mod format assemblies.</param>
		/// <param name="p_booRecurse">Whether to check sub folders of <paramref name="p_strSearchPath"/> for mods.</param>
		/// <param name="p_gmdGameMode">The game mode for which to discover mods.</param>
		/// <param name="p_strExcludedSubDirectories">The list of subdirectories not to examine for mods.</param>
		/// <returns>A registry containing all of the discovered mods.</returns>
		public static ModRegistry DiscoverManagedMods(IModFormatRegistry p_frgFormatRegistry, IModCacheManager p_frgCacheManager, string p_strSearchPath, bool p_booRecurse, IGameMode p_gmdGameMode, params string[] p_strExcludedSubDirectories)
		{
			Trace.TraceInformation("Discovering Managed Mods...");
			Trace.Indent();

			Trace.TraceInformation("Looking in: {0}", p_strSearchPath);

			List<string> lstExludedPaths = new List<string>();
			for (Int32 i = 0; i < p_strExcludedSubDirectories.Length; i++)
				lstExludedPaths.Add((p_strExcludedSubDirectories[i].Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Trim(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar).ToLower());

			ModRegistry mdrRegistry = new ModRegistry(p_frgFormatRegistry, p_gmdGameMode);
			string[] strMods = Directory.GetFiles(p_strSearchPath, "*", p_booRecurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
			IMod modMod = null;
			List<string> modList = new List<String>();
			bool booExcluded = false;
			foreach (string strMod in strMods)
			{
				string strModPath = strMod.ToLower();
				booExcluded = false;
				foreach (string strExclusion in lstExludedPaths)
					if (strModPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).StartsWith(strExclusion))
					{
						booExcluded = true;
						break;
					}
				if (booExcluded)
					continue;
				Trace.TraceInformation("Found: {0}", strMod);

				try
				{
					string strCachePath = p_frgCacheManager.GetCacheFilePath(strMod);
					modMod = mdrRegistry.CreateMod(strMod, strCachePath, p_gmdGameMode);
				}
				catch
				{
					modList.Add(strMod);
					modMod = null;
				}

				if (modMod == null)
					continue;
				mdrRegistry.m_oclRegisteredMods.Add(modMod);
				Trace.Indent();
				Trace.TraceInformation("Registered.");
				Trace.Unindent();
			}

			if (modList.Count > 0)
			{
				string strErrorMessage = "Error loading the following mods: " + Environment.NewLine;
				foreach (string modstr in modList)
				{
					strErrorMessage += modstr + Environment.NewLine;
				}
				MessageBox.Show(strErrorMessage, "Mod loading error", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}

			Trace.Unindent();
			return mdrRegistry;
		}