<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text;
using Fody;
using Mono.Cecil;

public partial class ModuleWeaver : IDisposable
{
    private readonly List<Stream> _streams = new List<Stream>();
    private string _cachePath;

    private void EmbedResources(Configuration config)
    {
        if (ReferenceCopyLocalPaths is null)
        {
            throw new WeavingException("ReferenceCopyLocalPaths is required you may need to update to the latest version of Fody.");
        }

        var assemblyDirectory = Path.GetDirectoryName(AssemblyFilePath);
        _cachePath = Path.Combine(assemblyDirectory, "Costura");
        Directory.CreateDirectory(_cachePath);

        var references = GetReferences();
        var embeddedReferences = new List<EmbeddedReferenceInfo>();

        var disableCompression = config.DisableCompression;
        var createTemporaryAssemblies = config.CreateTemporaryAssemblies;

        var normalReferences = GetFilteredReferences(references, config).ToList();
        if (normalReferences.Any())
        {
            WriteInfo("\tIncluding references");

            foreach (var reference in normalReferences)
            {
                var referencePath = reference.FullPath;
                var relativeFileName = reference.RelativeFileName;
                var relativePrefix = reference.GetResourceNamePrefix("costura.");

                if (reference.IsResourcesAssembly && config.IgnoreSatelliteAssemblies)
                {
                    continue;
                }

                var embeddedReference = Embed(relativePrefix, relativeFileName, referencePath, !disableCompression, createTemporaryAssemblies, config.DisableCleanup);
                if (embeddedReference is null == false)
                {
                    embeddedReferences.Add(embeddedReference);
                }

                if (config.IncludeDebugSymbols)
                {
                    var pdbFullPath = Path.ChangeExtension(referencePath, "pdb");
                    if (File.Exists(pdbFullPath))
                    {
                        var embeddedPdb = Embed(relativePrefix, Path.ChangeExtension(relativeFileName, "pdb"), pdbFullPath, !disableCompression, createTemporaryAssemblies, config.DisableCleanup);
                        if (embeddedPdb is null == false)
                        {
                            embeddedReferences.Add(embeddedPdb);
                        }
                    }
                }
            }
        }

        if (config.IncludeRuntimeReferences)
        {
            if (!ModuleDefinition.IsUsingDotNetCore())
            {
                WriteInfo("\tSkipping runtime references for this target framework, library doesn't target .NET Core");
            }
            else
            {
                var runtimeReferences = GetFilteredRuntimeReferences(references, config).ToList();
                if (runtimeReferences.Any())
                {
                    WriteInfo("\tIncluding runtime references");

                    foreach (var runtimeReference in runtimeReferences)
                    {
                        var runtimeReferencePath = runtimeReference.FullPath;
                        var relativeFileName = runtimeReference.RelativeFileName;
                        var relativePrefix = runtimeReference.GetResourceNamePrefix("costura.");

                        if (runtimeReference.IsResourcesAssembly && config.IgnoreSatelliteAssemblies)
                        {
                            continue;
                        }

                        var embeddedReference = Embed(relativePrefix, relativeFileName, runtimeReferencePath, !disableCompression, createTemporaryAssemblies, config.DisableCleanup);
                        if (embeddedReference is null == false)
                        {
                            embeddedReferences.Add(embeddedReference);
                        }

                        if (config.IncludeDebugSymbols)
                        {
                            var pdbFullPath = Path.ChangeExtension(runtimeReferencePath, "pdb");
                            if (File.Exists(pdbFullPath))
                            {
                                var embeddedPdb = Embed(relativePrefix, Path.ChangeExtension(relativeFileName, "pdb"), pdbFullPath, !disableCompression, createTemporaryAssemblies, config.DisableCleanup);
                                if (embeddedPdb is null == false)
                                {
                                    embeddedReferences.Add(embeddedPdb);
                                }
                            }
                        }
                    }
                }
            }
        }

        foreach (var reference in references)
        {
            var prefix = string.Empty;

            if (config.Unmanaged32Assemblies.Any(x => string.Equals(x, Path.GetFileNameWithoutExtension(reference.FullPath), StringComparison.OrdinalIgnoreCase)))
            {
                prefix = "costura32.";<commit_msg>Add support for including runtime references under .NET Framework<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text;
using Fody;
using Mono.Cecil;

public partial class ModuleWeaver : IDisposable
{
    private readonly List<Stream> _streams = new List<Stream>();
    private string _cachePath;

    private void EmbedResources(Configuration config)
    {
        if (ReferenceCopyLocalPaths is null)
        {
            throw new WeavingException("ReferenceCopyLocalPaths is required you may need to update to the latest version of Fody.");
        }

        var assemblyDirectory = Path.GetDirectoryName(AssemblyFilePath);
        _cachePath = Path.Combine(assemblyDirectory, "Costura");
        Directory.CreateDirectory(_cachePath);

        var references = GetReferences();
        var embeddedReferences = new List<EmbeddedReferenceInfo>();

        var disableCompression = config.DisableCompression;
        var createTemporaryAssemblies = config.CreateTemporaryAssemblies;

        var normalReferences = GetFilteredReferences(references, config).ToList();
        if (normalReferences.Any())
        {
            WriteInfo("\tIncluding references");

            foreach (var reference in normalReferences)
            {
                var referencePath = reference.FullPath;
                var relativeFileName = reference.RelativeFileName;
                var relativePrefix = reference.GetResourceNamePrefix("costura.");

                if (reference.IsResourcesAssembly && config.IgnoreSatelliteAssemblies)
                {
                    continue;
                }

                var embeddedReference = Embed(relativePrefix, relativeFileName, referencePath, !disableCompression, createTemporaryAssemblies, config.DisableCleanup);
                if (embeddedReference is null == false)
                {
                    embeddedReferences.Add(embeddedReference);
                }

                if (config.IncludeDebugSymbols)
                {
                    var pdbFullPath = Path.ChangeExtension(referencePath, "pdb");
                    if (File.Exists(pdbFullPath))
                    {
                        var embeddedPdb = Embed(relativePrefix, Path.ChangeExtension(relativeFileName, "pdb"), pdbFullPath, !disableCompression, createTemporaryAssemblies, config.DisableCleanup);
                        if (embeddedPdb is null == false)
                        {
                            embeddedReferences.Add(embeddedPdb);
                        }
                    }
                }
            }
        }

        if (config.IncludeRuntimeReferences)
        {
            var runtimeReferences = GetFilteredRuntimeReferences(references, config).ToList();
            if (runtimeReferences.Any())
            {
                WriteInfo("\tIncluding runtime references");

                foreach (var runtimeReference in runtimeReferences)
                {
                    var runtimeReferencePath = runtimeReference.FullPath;
                    var relativeFileName = runtimeReference.RelativeFileName;
                    var relativePrefix = runtimeReference.GetResourceNamePrefix("costura.");

                    if (runtimeReference.IsResourcesAssembly && config.IgnoreSatelliteAssemblies)
                    {
                        continue;
                    }

                    var embeddedReference = Embed(relativePrefix, relativeFileName, runtimeReferencePath, !disableCompression, createTemporaryAssemblies, config.DisableCleanup);
                    if (embeddedReference is null == false)
                    {
                        embeddedReferences.Add(embeddedReference);
                    }

                    if (config.IncludeDebugSymbols)
                    {
                        var pdbFullPath = Path.ChangeExtension(runtimeReferencePath, "pdb");
                        if (File.Exists(pdbFullPath))
                        {
                            var embeddedPdb = Embed(relativePrefix, Path.ChangeExtension(relativeFileName, "pdb"), pdbFullPath, !disableCompression, createTemporaryAssemblies, config.DisableCleanup);
                            if (embeddedPdb is null == false)
                            {
                                embeddedReferences.Add(embeddedPdb);
                            }
                        }
                    }
                }
            }
        }

        foreach (var reference in references)
        {
            var prefix = string.Empty;

            if (config.Unmanaged32Assemblies.Any(x => string.Equals(x, Path.GetFileNameWithoutExtension(reference.FullPath), StringComparison.OrdinalIgnoreCase)))
            {
                prefix = "costura32.";
{'fraction_non_alphanumeric': 0.07091917591125198, 'fraction_numerical': 0.000792393026941363, 'mean_word_length': 1.6853723404255319, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2475240', 'n_tokens_mistral': 2308, 'n_tokens_neox': 2111, 'n_words': 466}