<commit_before>namespace Farmhand.Installers.Patcher.Cecil
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.IO;
    using System.Linq;
    using System.Reflection;

    using Farmhand.Installers.Patcher.Injection;

    using Mono.Cecil;
    using Mono.Cecil.Cil;
    using Mono.Cecil.Mdb;
    using Mono.Cecil.Pdb;
    using Mono.Collections.Generic;

    /// <summary>
    ///     A utility class which helps with injecting via Cecil.
    /// </summary>
    [Export(typeof(IInjectionContext))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class CecilContext : IInjectionContext
    {
        internal AssemblyDefinition AssemblyDefinition { get; set; }

        #region IInjectionContext Members

        /// <summary>
        ///     Gets the loaded assemblies.
        /// </summary>
        public IEnumerable<Assembly> LoadedAssemblies { get; } = new List<Assembly>();

        /// <summary>
        ///     Loads an assembly.
        /// </summary>
        /// <param name="file">
        ///     The path of the assembly to load.
        /// </param>
        public void LoadAssembly(string file)
        {
            ((List<Assembly>)this.LoadedAssemblies).Add(Assembly.LoadFrom(file));
        }

        /// <summary>
        ///     Sets the primary assembly.
        /// </summary>
        /// <param name="file">
        ///     The path of the assembly.
        /// </param>
        /// <param name="loadDebugInformation">
        ///     Whether debug symbols should also be loaded.
        /// </param>
        public void SetPrimaryAssembly(string file, bool loadDebugInformation)
        {
            var mono = Type.GetType("Mono.Runtime") != null;
            ISymbolReaderProvider readerProvider;
            if (mono)
            {
                readerProvider = new MdbReaderProvider();
            }
            else
            {
                readerProvider = new PdbReaderProvider();
            }

            var pdbPath = Path.GetDirectoryName(file) + Path.GetFileName(file) + $".{(mono ? "m" : "p")}db";
            if (loadDebugInformation && File.Exists(pdbPath))
            {
                var readerParameters = new ReaderParameters
                                       {
                                           SymbolReaderProvider = readerProvider,
                                           ReadSymbols = true
                                       };
                this.AssemblyDefinition = AssemblyDefinition.ReadAssembly(file, readerParameters);
            }
            else
            {
                this.AssemblyDefinition = AssemblyDefinition.ReadAssembly(file);
            }
        }

        /// <summary>
        ///     Writes the modified assembly to disk.
        /// </summary>
        /// <param name="file">
        ///     The output file.
        /// </param>
        /// <param name="writePdb">
        ///     Whether an updated PDB should also be written.
        /// </param>
        public void WriteAssembly(string file, bool writePdb = false)
        {<commit_msg>Fixed PDB generation issue<commit_after>namespace Farmhand.Installers.Patcher.Cecil
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.IO;
    using System.Linq;
    using System.Reflection;

    using Farmhand.Installers.Patcher.Injection;

    using Mono.Cecil;
    using Mono.Cecil.Cil;
    using Mono.Cecil.Mdb;
    using Mono.Cecil.Pdb;
    using Mono.Collections.Generic;

    /// <summary>
    ///     A utility class which helps with injecting via Cecil.
    /// </summary>
    [Export(typeof(IInjectionContext))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class CecilContext : IInjectionContext
    {
        internal AssemblyDefinition AssemblyDefinition { get; set; }

        #region IInjectionContext Members

        /// <summary>
        ///     Gets the loaded assemblies.
        /// </summary>
        public IEnumerable<Assembly> LoadedAssemblies { get; } = new List<Assembly>();

        /// <summary>
        ///     Loads an assembly.
        /// </summary>
        /// <param name="file">
        ///     The path of the assembly to load.
        /// </param>
        public void LoadAssembly(string file)
        {
            ((List<Assembly>)this.LoadedAssemblies).Add(Assembly.LoadFrom(file));
        }

        /// <summary>
        ///     Sets the primary assembly.
        /// </summary>
        /// <param name="file">
        ///     The path of the assembly.
        /// </param>
        /// <param name="loadDebugInformation">
        ///     Whether debug symbols should also be loaded.
        /// </param>
        public void SetPrimaryAssembly(string file, bool loadDebugInformation)
        {
            var mono = Type.GetType("Mono.Runtime") != null;
            ISymbolReaderProvider readerProvider;
            if (mono)
            {
                readerProvider = new MdbReaderProvider();
            }
            else
            {
                readerProvider = new PdbReaderProvider();
            }

            var pdbPath = Path.GetDirectoryName(file) + Path.GetFileNameWithoutExtension(file) + $".{(mono ? "m" : "p")}db";
            if (loadDebugInformation && File.Exists(pdbPath))
            {
                var readerParameters = new ReaderParameters
                                       {
                                           SymbolReaderProvider = readerProvider,
                                           ReadSymbols = true
                                       };
                this.AssemblyDefinition = AssemblyDefinition.ReadAssembly(file, readerParameters);
            }
            else
            {
                this.AssemblyDefinition = AssemblyDefinition.ReadAssembly(file);
            }
        }

        /// <summary>
        ///     Writes the modified assembly to disk.
        /// </summary>
        /// <param name="file">
        ///     The output file.
        /// </param>
        /// <param name="writePdb">
        ///     Whether an updated PDB should also be written.
        /// </param>
        public void WriteAssembly(string file, bool writePdb = false)
        {
{'fraction_non_alphanumeric': 0.10795364343546594, 'fraction_numerical': 0.0, 'mean_word_length': 1.4901185770750989, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4331672', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1524, 'n_words': 371}