示例#1
0
        // Token: 0x06000025 RID: 37 RVA: 0x00002780 File Offset: 0x00000980
        private static void SetWinDllDirectory()
        {
            string location = Assembly.GetExecutingAssembly().Location;
            string text;

            if (string.IsNullOrEmpty(location) || (text = Path.GetDirectoryName(location)) == null)
            {
                Trace.TraceWarning(string.Format("{0}: Failed to get executing assembly location", "ZstdNet"));
                return;
            }
            if (Path.GetFileName(text).StartsWith("net", StringComparison.Ordinal) && Path.GetFileName(Path.GetDirectoryName(text)) == "lib" && File.Exists(Path.Combine(text, "../../zstdnet.nuspec")))
            {
                text = Path.Combine(text, "../../build");
            }

            /*string path = Environment.Is64BitProcess ? "x64" : "x86";
             *          if (!ExternMethods.SetDllDirectory(Path.Combine(text, path)))
             *          {
             *                  Trace.TraceWarning(string.Format("{0}: Failed to set DLL directory to '{1}'", "ZstdNet", text));
             *          }*/
            var dllLoader = new DynamicDllLoader();


            var assembly     = Assembly.GetExecutingAssembly();
            var resourceName = "ExportWadLol.libzstd.dll";


            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                if (!File.Exists(text + "/libzstd.dll"))
                {
                    var fileStream = new FileStream(text + "/libzstd.dll", FileMode.Create, FileAccess.Write);
                    stream.CopyTo(fileStream);
                    fileStream.Dispose();
                }
            }

            if (!ExternMethods.SetDllDirectory(text))
            {
                Trace.TraceWarning(string.Format("{0}: Failed to set DLL directory to '{1}'", "ZstdNet", text));
            }

            /*
             * using (Stream stream = assembly.GetManifestResourceStream(resourceName))
             * {
             *  using (var memoryStream = new MemoryStream())
             *  {
             *      stream.CopyTo(memoryStream);
             *      if (!dllLoader.LoadLibrary(memoryStream.ToArray()))
             *      {
             *          Trace.TraceWarning(string.Format("{0}: Failed to set DLL directory to '{1}'", "ZstdNet", text));
             *      }
             *  }
             *
             * }*/
        }