internal void Check()
        {
            if (Assemblies.Count == 0)
            {
                CollectAssemblies(RootPath, true);
            }
            foreach (AssemblyName assemblyName in Assemblies)
            {
                if (ExcludedAssemblies.FindLazy(assemblyName) == null)
                {
                    Assembly assembly = null;
                    try
                    {
                        assembly = Assembly.ReflectionOnlyLoadFrom(assemblyName.EscapedCodeBase);
                    }
                    catch (FileLoadException)
                    {
                    }

                    if (assembly != null)
                    {
                        CheckReferences(assembly);
                    }
                }
            }
        }
        public static void RegisterAssemblyForStacktracePatch(Assembly assembly)
        {
            if (ExcludedAssemblies
                .Concat(new[] {
                "UnityEngine",
                "Assembly-CSharp"
            })
                .Any(c => assembly.FullName.Contains(c)))
            {
                return;
            }

            ICollection <Type> types;

            try
            {
                types = assembly.GetAllTypes();
            }
            catch (ReflectionTypeLoadException ex)
            {
                types = ex.Types;
            }

            var selfAssembly = typeof(ProfilerPlugin).Assembly;

            foreach (var type in types)
            {
                // whitelist /freezeserver
                if (assembly == selfAssembly && type != typeof(CommandFreezeServer))
                {
                    continue;
                }

                foreach (var method in type.GetMethods(m_BindingFlags))
                {
                    RegisterMethod(assembly, method);
                }

                foreach (var constructor in type.GetConstructors(m_BindingFlags))
                {
                    RegisterMethod(assembly, constructor);
                }

                foreach (var property in type.GetProperties(m_BindingFlags))
                {
                    var getter = property.GetGetMethod(true);
                    if (getter != null)
                    {
                        RegisterMethod(assembly, getter);
                    }

                    var setter = property.GetGetMethod(true);
                    if (setter != null)
                    {
                        RegisterMethod(assembly, setter);
                    }
                }
            }
        }
Example #3
0
        public void ShouldAddAssemblyNameToExcludedAssemblies()
        {
            //Act
            var excluded = new ExcludedAssemblies();
            var result   = excluded.Assembly("Test");

            //Assert
            Assert.AreSame(excluded, result);
            Assert.IsTrue(result.Assemblies.Contains("Test"));
        }
Example #4
0
        /// <summary>
        /// A list of <see cref="Assembly" />s to ignore in the assembly scanning.
        /// </summary>
        /// <param name="assemblies">The file name of the assembly.</param>
        public void ExcludeAssemblies(params string[] assemblies)
        {
            Guard.AgainstNull(nameof(assemblies), assemblies);

            if (assemblies.Any(string.IsNullOrWhiteSpace))
            {
                throw new ArgumentException("Passed in a null or empty assembly name.", nameof(assemblies));
            }

            ExcludedAssemblies.AddRange(assemblies);
        }
Example #5
0
        public void ShouldCreateANewExcludedAssemblies()
        {
            //Act
            var result = new ExcludedAssemblies();

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IExcludedAssemblies));
            Assert.IsInstanceOfType(result, typeof(ExcludedAssemblies));
            Assert.IsInstanceOfType(result, typeof(IBootstrapperOption));
            Assert.IsInstanceOfType(result, typeof(BootstrapperOption));
        }
Example #6
0
        public void ShouldExcludeDefaultSystemAssemblies()
        {
            //Act
            var result = new ExcludedAssemblies().Assemblies;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(List <string>));
            Assert.IsTrue(result.Contains("System"));
            Assert.IsTrue(result.Contains("mscorlib"));
            Assert.IsTrue(result.Contains("Microsoft.VisualStudio"));
        }
        private void CheckReferences(Assembly assembly)
        {
            var references = assembly.GetReferencedAssemblies()
                             .Select(PrepareAssemblyName)
                             .ToList();

            foreach (AssemblyName name in references)
            {
                //Wenn die Referenz nirgendwo zu finden ist, dann ausgeben.
                if (Assemblies.Find(name) == null && ExcludedAssemblies.FindLazy(name) == null && !IsExcluded(name) && ReportedAssemblies.Find(name) == null)
                {
                    ReportedAssemblies.Add(new MissingReference()
                    {
                        MissingAssembly = name, ReferencesBy = assembly.GetName()
                    });
                }
            }
        }
        public static IEnumerable <MethodBase> GetMethods(this IEnumerable <StackFrame> Frames, params Assembly[] ExcludedAssemblies)
        {
            List <MethodBase> Methods = new List <MethodBase>();

            if (Frames == null)
            {
                return(Methods);
            }
            foreach (StackFrame Frame in Frames)
            {
                Methods.AddIf(x => x.DeclaringType != null &&
                              !ExcludedAssemblies.Contains(x.DeclaringType.Assembly) &&
                              !x.DeclaringType.Assembly.FullName.StartsWith("System", StringComparison.InvariantCulture) &&
                              !x.DeclaringType.Assembly.FullName.StartsWith("mscorlib", StringComparison.InvariantCulture) &&
                              !x.DeclaringType.Assembly.FullName.StartsWith("WebDev.WebHost40", StringComparison.InvariantCulture),
                              Frame.GetMethod());
            }
            return(Methods);
        }
 internal void AddExclude(AssemblyName assemblyName)
 {
     ExcludedAssemblies.Add(PrepareAssemblyName(assemblyName));
 }
Example #10
0
        public static void BuildAndEmbedAssetBundles(FileInfo modDll, FileInfo weaverCoreDLL, MethodInfo OnComplete)
        {
            Data = new BundleBuildData
            {
                ModDLL             = modDll == null ? "" : modDll.FullName,
                ModName            = modDll == null ? "" : modDll.Name.Replace(".dll", ""),
                WeaverCoreOnly     = modDll == null,
                WeaverCoreDLL      = weaverCoreDLL.FullName,
                PreBuildInfo       = ScriptFinder.GetProjectScriptInfo(),
                ExcludedAssemblies = new List <ExcludedAssembly>(),
                OnComplete         = new SerializedMethod(OnComplete),
                BundlingSuccessful = false
            };
            /**/
            PrepareForAssetBundling(new List <string> {
                "WeaverCore.Editor"
            }, typeof(BundleTools).GetMethod(nameof(BeginBundleProcess), BindingFlags.Static | BindingFlags.NonPublic));
        }

        static bool IsFileLocked(FileInfo file)
        {
            try
            {
                using (FileStream stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    stream.Close();
                }
            }
            catch (IOException)
            {
                //the file is unavailable because it is:
                //still being written to
                //or being processed by another thread
                //or does not exist (has already been processed)
                return(true);
            }

            //file is not locked
            return(false);
        }

        static void PrepareForAssetBundling(List <string> ExcludedAssemblies, MethodInfo whenReady)
        {
            //AssetDatabase.DisallowAutoRefresh();
            Debug.Log("Preparing Assets for Bundling");
            //UnboundCoroutine.Start(Delay());
            //IEnumerator Delay()
            //{

            /*yield return new WaitForSeconds(0.5f);
             * foreach (var registry in RegistryChecker.LoadAllRegistries())
             * {
             *      registry.ReplaceAssemblyName("Assembly-CSharp", Data.ModName);
             *      registry.ApplyChanges();
             * }*/
            //Debug.Log("A_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));

            /*var buildCache = new DirectoryInfo("Library\\BuildCache");
             * if (buildCache.Exists)
             * {
             *      buildCache.Delete(true);
             * }*/
            //yield return new WaitForSeconds(0.5f);
            //Debug.Log("B_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitUntil(() => !EditorApplication.isCompiling);
            //AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
            //yield return new WaitForSeconds(0.5f);
            //Debug.Log("C_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitUntil(() => !EditorApplication.isCompiling);
#if REWRITE_REGISTRIES
            foreach (var registry in RegistryChecker.LoadAllRegistries())
            {
                registry.ReplaceAssemblyName("Assembly-CSharp", Data.ModName);
                registry.ApplyChanges();
            }
#endif
            Data.Registries = new List <RegistryInfo>();
            var registryIDs = AssetDatabase.FindAssets($"t:{nameof(Registry)}");
            foreach (var id in registryIDs)
            {
                var path     = AssetDatabase.GUIDToAssetPath(id);
                var registry = AssetDatabase.LoadAssetAtPath <Registry>(path);
                Data.Registries.Add(new RegistryInfo
                {
                    AssemblyName    = registry.ModAssemblyName,
                    AssetBundleName = GetAssetBundleName(registry),
                    ModTypeName     = registry.ModName,
                    RegistryName    = registry.RegistryName,
                    Path            = path
                });
            }
            //yield return new WaitForSeconds(0.5f);
            //Debug.Log("D_Editor File Locked = " + IsFileLocked(new FileInfo("Library\\ScriptAssemblies\\WeaverCore.Editor.dll")));
            //yield return new WaitUntil(() => !EditorApplication.isCompiling);
            bool assetsChanged = false;
            try
            {
                AssetDatabase.StartAssetEditing();
                foreach (var asm in Data.PreBuildInfo.Where(i => ExcludedAssemblies.Contains(i.AssemblyName)))
                {
                    if (asm.Definition.includePlatforms.Count == 1 && asm.Definition.includePlatforms[0] == "Editor")
                    {
                        continue;
                    }
                    Data.ExcludedAssemblies.Add(new ExcludedAssembly()
                    {
                        AssemblyName = asm.AssemblyName,
                        OriginalExcludedPlatforms = asm.Definition.excludePlatforms,
                        OriginalIncludedPlatforms = asm.Definition.includePlatforms
                    });
                    asm.Definition.excludePlatforms = new List <string>();
                    asm.Definition.includePlatforms = new List <string>
                    {
                        "Editor"
                    };
                    //Debug.Log("Asm Definition Path = " + asm.AssemblyDefinitionPath);
                    //Debug.Log("Importing Asset = " + asm.AssemblyDefinitionPath);
                    asm.Save();
                    AssetDatabase.ImportAsset(asm.AssemblyDefinitionPath, ImportAssetOptions.ForceUpdate);
                    assetsChanged = true;
                }
                if (assetsChanged)
                {
                    Data.NextMethod = new SerializedMethod(whenReady);
                }
                else
                {
                    Data.NextMethod = default;
                }
                PersistentData.StoreData(Data);
                PersistentData.SaveData();

                if (!assetsChanged && whenReady != null)
                {
                    whenReady.Invoke(null, null);
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Exception occured" + e);
            }
            finally
            {
                AssetDatabase.StopAssetEditing();
                //if (assetsChanged)
                //{
                //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                //}
            }
            //}
        }
Example #11
0
 private static void InitializeExcludedAndIncludedAssemblies()
 {
     Excluding     = new ExcludedAssemblies();
     Including     = new IncludedAssemblies();
     IncludingOnly = new IncludedOnlyAssemblies();
 }