private bool CheckMethod(MethodConfig cfg) { bool result; try { AssemblyLoader loader = this.GetAssemblyLoader(cfg.assemblyName); if (null == loader) { loader = new AssemblyLoader(); if (!loader.LoadAssembly(cfg.assemblyName)) { return(false); } this.AddAssemblyLoader(cfg.assemblyName, loader); } result = loader.LoadMethod(cfg.fullClassName, cfg.methodName); } catch (Exception ex) { LogManager.WriteLog(LogTypes.Error, string.Format("PatchMgr::CheckMethod Error, AssemblyName={0}, fullClassName={1}, methodName={2}", cfg.assemblyName, cfg.fullClassName, cfg.methodName), ex, false); result = false; } return(result); }
public bool InitConfig() { string fileName = "AssemblyPatch.xml"; XElement xml = ConfigHelper.Load(fileName); bool result; if (null == xml) { result = false; } else { try { Dictionary <EventTypes, List <MethodConfig> > tmpPatchCfgDict = new Dictionary <EventTypes, List <MethodConfig> >(); bool[] flags = new bool[32768]; IEnumerable <XElement> xmlItems = xml.Elements(); foreach (XElement xmlItem in xmlItems) { MethodConfig config = new MethodConfig(); Enum.TryParse <EventTypes>(ConfigHelper.GetElementAttributeValue(xmlItem, "Type", ""), true, out config.eventType); config.assemblyName = ConfigHelper.GetElementAttributeValue(xmlItem, "AssemblyName", ""); config.fullClassName = ConfigHelper.GetElementAttributeValue(xmlItem, "fullClassName", ""); config.methodName = ConfigHelper.GetElementAttributeValue(xmlItem, "methodName", ""); config.methodParams = ConfigHelper.GetElementAttributeValue(xmlItem, "methodParams", "").Split(new char[] { ',' }); config.cmdID = (int)ConfigHelper.GetElementAttributeValueLong(xmlItem, "CmdID", 0L); if (this.CheckMethod(config)) { flags[config.cmdID] = true; if (tmpPatchCfgDict.ContainsKey(config.eventType)) { tmpPatchCfgDict[config.eventType].Add(config); } else { List <MethodConfig> methodList = new List <MethodConfig>(); methodList.Add(config); tmpPatchCfgDict.Add(config.eventType, methodList); } } } this.patchCfgDict = tmpPatchCfgDict; this.CmdRegisteredFlags = flags; } catch (Exception ex) { LogManager.WriteLog(LogTypes.Exception, "加载AssemblyPatch时文件出错\r\n" + ex.ToString(), null, true); } result = true; } return(result); }
public bool InitConfig() { string fileName = "AssemblyPatch.xml"; XElement xml = ConfigHelper.Load(fileName); bool result; if (null == xml) { result = false; } else { try { Dictionary <EventTypes, List <MethodConfig> > tmpPatchCfgDict = new Dictionary <EventTypes, List <MethodConfig> >(); bool[] flags = new bool[32768]; IEnumerable <XElement> xmlItems = xml.Elements(); foreach (XElement xmlItem in xmlItems) { string maxVer = Global.GetDefAttributeStr(xmlItem, "VersionID", "99.9.9.999999"); string curVer = Program.GetVersionStr(); if (!this.CheckVersion(curVer, maxVer)) { Program.DeleteFile("AssemblyPatch.xml"); Program.DeleteFile("AssemblyPatch.dll"); Program.DeleteFile("DotNetDetour.dll"); Program.DeleteFile("dlls\\AssemblyPatch.dll"); Program.DeleteFile("dlls\\DotNetDetour.dll"); return(true); } MethodConfig config = new MethodConfig(); Enum.TryParse <EventTypes>(Global.GetDefAttributeStr(xmlItem, "Type", ""), true, out config.eventType); config.assemblyName = Global.GetDefAttributeStr(xmlItem, "AssemblyName", ""); config.fullClassName = Global.GetDefAttributeStr(xmlItem, "fullClassName", ""); config.methodName = Global.GetDefAttributeStr(xmlItem, "methodName", ""); config.methodParams = Global.GetDefAttributeStr(xmlItem, "methodParams", "").Split(new char[] { ',' }); config.cmdID = (int)Global.GetSafeAttributeLong(xmlItem, "CmdID"); if (this.CheckMethod(config)) { flags[config.cmdID] = true; if (tmpPatchCfgDict.ContainsKey(config.eventType)) { tmpPatchCfgDict[config.eventType].Add(config); } else { List <MethodConfig> methodList = new List <MethodConfig>(); methodList.Add(config); tmpPatchCfgDict.Add(config.eventType, methodList); } } } this.patchCfgDict = tmpPatchCfgDict; this.CmdRegisteredFlags = flags; } catch (Exception ex) { LogManager.WriteLog(LogTypes.Fatal, "加载AssemblyPatch时文件出错", ex, true); } result = true; } return(result); }