<commit_before>﻿namespace ZeroMQ.Proxy
{
    using System;
    using System.IO;
    using System.Reflection;

    internal static class ProxyAssemblyLoader
    {
        private const string ProxyAssemblyFileName = "ZeroMQ.Proxy.dll";
        private const string NativeDllName = "libzmq.dll";
        private const string LoadError = "Unable to load {0} for {1} platform.";
        private const string WriteAccessRequired = " Write access to the current executing path or a temporary folder is required.";

        private static readonly string CurrentPlatform = Environment.Is64BitProcess ? "x64" : "x86";

        public static Assembly Load()
        {
            Assembly assembly = LoadFromLocalBinPath() ?? LoadFromExecutingPath() ?? LoadFromTempPath();

            if (assembly == null)
            {
                throw new InvalidOperationException(string.Format(LoadError, ProxyAssemblyFileName, CurrentPlatform) + WriteAccessRequired);
            }

            return assembly;
        }

        private static Assembly LoadFromLocalBinPath()
        {
            return ExtractAndLoadFromPath("bin");
        }

        private static Assembly LoadFromExecutingPath()
        {
            return ExtractAndLoadFromPath(".");
        }

        private static Assembly LoadFromTempPath()
        {
            string dir = Path.Combine(Path.GetTempPath(), "netzmq", CurrentPlatform);
            Directory.CreateDirectory(dir);

            return ExtractAndLoadFromPath(dir);
        }

        private static Assembly ExtractAndLoadFromPath(string dir)
        {
            if (!Directory.Exists(dir))
            {
                return null;
            }

            string proxyPath = Path.GetFullPath(Path.Combine(dir, ProxyAssemblyFileName));
            string nativePath = Path.GetFullPath(Path.Combine(dir, NativeDllName));
            string platformSuffix = "." + CurrentPlatform;

            if (!ExtractManifestResource(NativeDllName + platformSuffix, nativePath))
            {
                return null;
            }

            if (!ExtractManifestResource(ProxyAssemblyFileName + platformSuffix, proxyPath))
            {
                return null;
            }

            return Assembly.LoadFrom(proxyPath);<commit_msg>Only check if 'bin' dir exists.<commit_after>﻿namespace ZeroMQ.Proxy
{
    using System;
    using System.IO;
    using System.Reflection;

    internal static class ProxyAssemblyLoader
    {
        private const string ProxyAssemblyFileName = "ZeroMQ.Proxy.dll";
        private const string NativeDllName = "libzmq.dll";
        private const string LoadError = "Unable to load {0} for {1} platform.";
        private const string WriteAccessRequired = " Write access to the current executing path or a temporary folder is required.";

        private static readonly string CurrentPlatform = Environment.Is64BitProcess ? "x64" : "x86";

        public static Assembly Load()
        {
            Assembly assembly = LoadFromLocalBinPath() ?? LoadFromExecutingPath() ?? LoadFromTempPath();

            if (assembly == null)
            {
                throw new InvalidOperationException(string.Format(LoadError, ProxyAssemblyFileName, CurrentPlatform) + WriteAccessRequired);
            }

            return assembly;
        }

        private static Assembly LoadFromLocalBinPath()
        {
            return Directory.Exists("bin") ? ExtractAndLoadFromPath("bin") : null;
        }

        private static Assembly LoadFromExecutingPath()
        {
            return ExtractAndLoadFromPath(".");
        }

        private static Assembly LoadFromTempPath()
        {
            string dir = Path.Combine(Path.GetTempPath(), "netzmq", CurrentPlatform);
            Directory.CreateDirectory(dir);

            return ExtractAndLoadFromPath(dir);
        }

        private static Assembly ExtractAndLoadFromPath(string dir)
        {
            string proxyPath = Path.GetFullPath(Path.Combine(dir, ProxyAssemblyFileName));
            string nativePath = Path.GetFullPath(Path.Combine(dir, NativeDllName));
            string platformSuffix = "." + CurrentPlatform;

            if (!ExtractManifestResource(NativeDllName + platformSuffix, nativePath))
            {
                return null;
            }

            if (!ExtractManifestResource(ProxyAssemblyFileName + platformSuffix, proxyPath))
            {
                return null;
            }

            return Assembly.LoadFrom(proxyPath);
{'fraction_non_alphanumeric': 0.08013318534961154, 'fraction_numerical': 0.003551609322974473, 'mean_word_length': 2.2277936962750715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264079', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1046, 'n_words': 274}