コード例 #1
0
ファイル: WCellAddonMgr.cs プロジェクト: 0xFh/Asda2-Project
        public static WCellAddonContext LoadAddon(FileInfo file)
        {
            string            fullName = file.FullName;
            WCellAddonContext context;

            if (ContextsByFile.TryGetValue(fullName, out context))
            {
                if (!Unload(context))
                {
                    return(null);
                }
            }

            Assembly asm;

            try
            {
                asm = Assembly.LoadFrom(fullName);
            }
            catch (BadImageFormatException ex)
            {
                LogManager.GetCurrentClassLogger().Error(
                    "Failed to load Assembly \"{0}\" because it has the wrong format - Make sure that you only load .NET assemblies that are compiled for the correct target platform: {1}",
                    file.Name, Environment.Is64BitProcess ? "xx64" : "x86");
                return(null);
            }

            WCellAddonContext wcellAddonContext = new WCellAddonContext(file, asm);

            Contexts.Add(wcellAddonContext);
            ContextsByFile.Add(wcellAddonContext.File.FullName, wcellAddonContext);
            return(wcellAddonContext);
        }
コード例 #2
0
ファイル: WCellAddonMgr.cs プロジェクト: 0xFh/Asda2-Project
        /// <summary>
        /// Loads an Addon from the given file.
        /// Returns null if file does not exist.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public WCellAddonContext LoadAndInitAddon(FileInfo file)
        {
            WCellAddonContext wcellAddonContext = LoadAddon(file);

            if (wcellAddonContext != null)
            {
                wcellAddonContext.InitAddon();
            }
            return(wcellAddonContext);
        }
コード例 #3
0
ファイル: WCellAddonMgr.cs プロジェクト: 0xFh/Asda2-Project
        public WCellAddonContext TryLoadAddon(string libName)
        {
            WCellAddonContext contextByName = GetContextByName(libName);

            if (contextByName != null)
            {
                return(LoadAndInitAddon(contextByName.File));
            }
            if (!libName.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase))
            {
                libName += ".dll";
            }
            return(LoadAndInitAddon(libName));
        }
コード例 #4
0
ファイル: WCellAddonBase.cs プロジェクト: WCellFR/WCellFR
		public void InitConfig(WCellAddonContext context)
		{
			Context = context;
			config.FilePath = Path.Combine(context.File.DirectoryName, GetType().Name + "Config.xml");
			if (UseConfig)
			{
				config.AutoSave = true;
				config.AddVariablesOfAsm<VariableAttribute>(GetType().Assembly);
				config.Load();
				try
				{
					config.Save();
				}
				catch (Exception e)
				{
					throw new Exception("Unable to save " + config.GetType().Name + " of addon: " + this, e);
				}
			}
		}
コード例 #5
0
ファイル: WCellAddonMgr.cs プロジェクト: 0xFh/Asda2-Project
        public static bool Unload(WCellAddonContext context)
        {
            IWCellAddon addon = context.Addon;

            if (addon == null)
            {
                return(false);
            }
            Logger currentClassLogger = LogManager.GetCurrentClassLogger();

            currentClassLogger.Info("Unloading Addon: " + context + " ...");
            TearDown(addon);
            Contexts.Remove(context);
            ContextsByFile.Remove(context.File.FullName);
            ContextsByName.Remove(context.ShortName);
            ContextsByTypeName.Remove(addon.GetType().FullName);
            currentClassLogger.Info("Done. - Unloaded Addon: " + context);
            return(true);
        }
コード例 #6
0
 public void InitAddon(WCellAddonContext context)
 {
     Context = context;
     if (!UseConfig)
     {
         return;
     }
     config = CreateConfig();
     if (!config.Load())
     {
         try
         {
             config.Save(true, true);
         }
         catch (Exception ex)
         {
             throw new Exception("Unable to save " + config.GetType().Name + " of addon: " + this,
                                 ex);
         }
     }
 }
コード例 #7
0
ファイル: WCellAddonMgr.cs プロジェクト: 0xFh/Asda2-Project
        internal static void RegisterAddon(WCellAddonContext context)
        {
            string fullName = context.Addon.GetType().FullName;

            if (context.ShortName.Length == 0)
            {
                LogManager.GetCurrentClassLogger().Warn("Addon of Type \"{0}\" did not specify a ShortName.",
                                                        context.Addon.GetType().FullName);
            }
            else
            {
                if (context.ShortName.ContainsIgnoreCase("addon"))
                {
                    LogManager.GetCurrentClassLogger()
                    .Warn(
                        "The Addon ShortName \"{0}\" contains the word \"Addon\" - The name should be short and not contain unnecessary information.",
                        context.ShortName);
                }
                if (ContextsByName.ContainsKey(context.ShortName))
                {
                    throw new ArgumentException(string.Format(
                                                    "Found more than one addon with ShortName \"{0}\": {1} and {2}", context.ShortName,
                                                    GetAddon(context.ShortName), context.Addon));
                }
                ContextsByName.Add(context.ShortName, context);
                if (fullName.Equals(context.ShortName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }
            }

            if (ContextsByTypeName.ContainsKey(fullName))
            {
                throw new InvalidProgramException("Tried to register two Addons with the same TypeName: " + fullName);
            }
            ContextsByTypeName.Add(fullName, context);
        }