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")); }
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); }
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); //} } //} }