private static void LoadServices() { if (services == null) { services = new List <ICppCompilerService>(); AppDomain.CurrentDomain.GetAssemblies().ParallelFor((assembly) => { foreach (Type service in assembly.GetTypes <ICppCompilerService>()) { try { ICppCompilerService instance; if (service.IsAbstract && MixinType.IsAssignableFrom(service)) { instance = MixinManager.Create(service) as ICppCompilerService; } else if (!service.IsAbstract) { instance = service.CreateInstance <ICppCompilerService>(); } else { continue; } if (instance != null) { services.Add(instance); } } catch { } } }); } }
public void TestMixins() { GlobalTest.Init(); var me3BackupPath = BackupService.GetGameBackupPath(MEGame.ME3); if (me3BackupPath != null) { GlobalTest.CreateScratchDir(); MixinHandler.LoadME3TweaksPackage(); // We can conduct this test var mixins = MixinHandler.ME3TweaksPackageMixins.Where(x => !x.IsFinalizer).ToList(); MixinHandler.LoadPatchDataForMixins(mixins); List <string> failedMixins = new List <string>(); void failedApplicationCallback(string str) { failedMixins.Add(str); } var compilingListsPerModule = MixinHandler.GetMixinApplicationList(mixins, failedApplicationCallback); //Mixins are ready to be applied var outdir = Path.Combine(Path.Combine(GlobalTest.GetScratchDir(), "MixinTest")); Utilities.DeleteFilesAndFoldersRecursively(outdir); Directory.CreateDirectory(outdir); foreach (var mapping in compilingListsPerModule) { MixinManager.ApplyMixinsToModule(mapping, outdir, null, failedApplicationCallback); } MixinHandler.FreeME3TweaksPatchData(); GlobalTest.DeleteScratchDir(); if (failedMixins.Any()) { Assert.Fail($"MixinTests failed. {failedMixins.Count} mixins failed to apply."); } } else { Console.WriteLine(@"No backup for ME3 is available. MixinTests will be skipped."); } }
private static void LoadMixins() { StorageDescriptor mixinCache = new StorageDescriptor(Application.CacheDirectory, ModuleCacheFileName); if (mixinCache.Load()) { foreach (StorageContainer node in mixinCache.Nodes.Values) { if (!node.Validate()) { mixinCache.Clear(); break; } } } StorageContainer assemblyNode; if (!mixinCache.TryGetNode(MixinAssemblyStorageAlias, out assemblyNode)) { Filter filter = new Filter(); SetMixinFilter(filter); List <FileSystemDescriptor> mixins = Application.SdkDirectory.FindFiles(filter); if (mixins.Count > 0) { FileDescriptor assemblyFile = Compile(mixins); assemblyNode = mixinCache.Store(assemblyFile, MixinAssemblyStorageAlias); foreach (FileDescriptor mixin in mixins) { mixinCache.Store(mixin); } mixinCache.Save(); } filter = null; mixins = null; } MixinManager.RegisterMixins(Assembly.GetExecutingAssembly()); if (assemblyNode != null && assemblyNode.Element.Exists()) { MixinManager.RegisterMixins(Assembly.LoadFrom(assemblyNode.Element.GetAbsolutePath())); } }
public static void DisplayManual() { Application.Log(SeverityFlags.None, "Forge {0}, distributed under the Schroedinger Entertainment EULA (See EULA.md for details)", Application.Version); StorageDescriptor mixinCache = new StorageDescriptor(Application.CacheDirectory, ModuleCacheFileName); if (mixinCache.Load() && mixinCache.Nodes.Count > 0) { Application.Log(SeverityFlags.None, "Loaded {0} Mixin(s) from root", mixinCache.Nodes.Count - 1); foreach (StorageContainer mixin in mixinCache.Nodes.Values) { if (mixin.Tag == 0) { Application.Log(SeverityFlags.None, " {0}", mixin.Element.GetRelativePath(Application.SdkDirectory)); } } } mixinCache = null; Application.Log(SeverityFlags.None, "Loaded {0} Plugin(s) from root", plugins.Count); foreach (Plugin plugin in plugins) { Application.Log(SeverityFlags.None, " {0}", plugin.Path.GetRelativePath(Application.SdkDirectory)); } Application.Log(SeverityFlags.None, string.Empty); PageFormatter page = new PageFormatter(); AutoConfig.GetAttributePage <Application>(page); page.Sort(); PageFormatter subPage = new PageFormatter(); AutoConfig.GetAttributePage(Application.Profile.GetType(), subPage); AutoConfig.GetAttributePage(Application.Profile, subPage); subPage.Sort(); if (subPage.Rows.Count > 0) { page.AddRow(""); page.AddRow(string.Format("{0} Profile", Application.Profile.Name.ToTitleCase())); page.Rows.AddRange(subPage.Rows); } Dictionary <string, PageFormatter> subSystems = new Dictionary <string, PageFormatter>(); AppDomain.CurrentDomain.GetAssemblies().ParallelFor((assembly) => { foreach (Type receiver in assembly.GetTypes <IConfigReceiver>()) { try { PageFormatter systemPage = new PageFormatter(); AutoConfig.GetAttributePage(receiver, systemPage); IConfigReceiver instance; if (receiver.IsAbstract && MixinType.IsAssignableFrom(receiver)) { instance = MixinManager.Create(receiver) as IConfigReceiver; } else if (!receiver.IsAbstract) { instance = receiver.CreateInstance <IConfigReceiver>(); } else { continue; } if (instance != null && instance.Display) { instance.GetAdditionalManualInfo(systemPage); if (systemPage.Rows.Count > 0) { lock (subSystems) { PageFormatter tmp; if (subSystems.TryGetValue(instance.DisplayName, out tmp)) { tmp.AddRows(systemPage.Rows); } else { subSystems.Add(instance.DisplayName, systemPage); } } } } } catch { } } }); foreach (KeyValuePair <string, PageFormatter> systems in subSystems.OrderBy(x => x.Key)) { systems.Value.Sort(); page.AddRow(""); page.AddRow(string.Format("{0} System", systems.Key)); page.Rows.AddRange(systems.Value.Rows); } foreach (Plugin plugin in plugins) { subPage = new PageFormatter(); plugin.GetManualPage(subPage); subPage.Sort(); if (subPage.Rows.Count > 0) { page.AddRow(""); page.AddRow(string.Format("{0} Plugin", plugin.Path.Name.ToTitleCase())); page.Rows.AddRange(subPage.Rows); } } Application.Log(SeverityFlags.None, page.ToString()); }