internal unsafe static void Init() { lock (s_initlock) { if (s_initialized) { return; } string assembly_path = AssemblyUtility.TrinityCorePath; #if !CORECLR string native_assembly_name = "Trinity.C.dll"; string trinity_c_path = Path.Combine(assembly_path, native_assembly_name); bool found = false; if (File.Exists(trinity_c_path)) { using (Stream resourceStream = GetTrinityCAssembly(native_assembly_name)) { string embedded_sha = SecureHashHelper.GetSHA512(resourceStream).Trim().ToLowerInvariant(); string ondisk_sha = SecureHashHelper.GetFileSHA512(trinity_c_path).Trim().ToLowerInvariant(); if (embedded_sha.Equals(ondisk_sha)) { found = true; } } } if (!found) { ReleaseNativeAssembly(native_assembly_name, trinity_c_path); } #endif fixed(char *pAssemblyPath = AssemblyUtility.MyAssemblyPath) { __INIT_TRINITY_C__(pAssemblyPath); } if (Environment.OSVersion.Platform == PlatformID.Win32NT) { Win32.NativeAPI.timeBeginPeriod(1); #if !CORECLR Register(); #endif } s_initialized = true; } }
static TrinityC() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { string assembly_path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string trinity_c_md5 = Resources.Trinity_C_sha512.Trim().ToLowerInvariant(); string trinity_c_path = Path.Combine(assembly_path, "Trinity.C.dll"); bool found = false; if (File.Exists(trinity_c_path)) { string md5 = SecureHashHelper.GetFileSHA512(trinity_c_path).Trim().ToLowerInvariant(); if (trinity_c_md5.Equals(md5)) { found = true; } } if (!found) { Assembly assembly = Assembly.GetExecutingAssembly(); Stream resourceStream = assembly.GetManifestResourceStream("Trinity.Trinity.C.dll"); try { using (FileStream fs = new FileStream(trinity_c_path, FileMode.Create)) { resourceStream.CopyTo(fs); fs.Flush(); } if (resourceStream != null) { resourceStream.Dispose(); } } catch (Exception) { Console.WriteLine("Trinity.C cannot be released, please make sure the working directory is writable."); Win32.NativeAPI.timeEndPeriod(1); Environment.Exit(0); } } } }
static TrinityC() { string assembly_path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); #if !CORECLR string native_assembly_name = "Trinity.C.dll"; #else string native_assembly_name = null; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: native_assembly_name = "Trinity.dll"; break; case PlatformID.Unix: native_assembly_name = "libTrinity.so"; break; default: throw new NotImplementedException(); } #endif string trinity_c_path = Path.Combine(assembly_path, native_assembly_name); #if !CORECLR string trinity_c_md5 = Resources.Trinity_C_sha512.Trim().ToLowerInvariant(); bool found = false; if (File.Exists(trinity_c_path)) { string md5 = SecureHashHelper.GetFileSHA512(trinity_c_path).Trim().ToLowerInvariant(); if (trinity_c_md5.Equals(md5)) { found = true; } } if (found) { return; } #endif Assembly assembly = Assembly.GetExecutingAssembly(); Stream resourceStream = assembly.GetManifestResourceStream("Trinity." + native_assembly_name); try { using (FileStream fs = new FileStream(trinity_c_path, FileMode.Create)) { resourceStream.CopyTo(fs); fs.Flush(); } if (resourceStream != null) { resourceStream.Dispose(); } } catch (Exception) { Console.WriteLine("Trinity.C cannot be released, please make sure the working directory is writable."); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { Win32.NativeAPI.timeEndPeriod(1); } Environment.Exit(0); } }
internal static void Init() { lock (s_initlock) { if (s_initialized) { return; } string assembly_path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); #if !CORECLR string native_assembly_name = "Trinity.C.dll"; #else string native_assembly_name = null; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: native_assembly_name = "Trinity.dll"; break; case PlatformID.Unix: native_assembly_name = "libTrinity.so"; break; default: throw new NotImplementedException(); } #endif string trinity_c_path = Path.Combine(assembly_path, native_assembly_name); bool found = false; #if !CORECLR string trinity_c_md5 = Resources.Trinity_C_sha512.Trim().ToLowerInvariant(); if (File.Exists(trinity_c_path)) { string md5 = SecureHashHelper.GetFileSHA512(trinity_c_path).Trim().ToLowerInvariant(); if (trinity_c_md5.Equals(md5)) { found = true; } } #endif if (!found) { ReleaseNativeAssembly(native_assembly_name, trinity_c_path); } /* native assembly is released. initialize Trinity.C now */ __INIT_TRINITY_C__(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { Win32.NativeAPI.timeBeginPeriod(1); #if !CORECLR Register(); #endif } s_initialized = true; } }
internal unsafe static void Init() { lock (s_initlock) { if (s_initialized) { return; } string assembly_path = AssemblyPath.TrinityCorePath; #if !CORECLR string native_assembly_name = "Trinity.C.dll"; #else string native_assembly_name = null; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: native_assembly_name = "Trinity.dll"; break; case PlatformID.Unix: native_assembly_name = "libTrinity.so"; break; default: throw new NotImplementedException(); } #endif string trinity_c_path = Path.Combine(assembly_path, native_assembly_name); bool found = false; if (File.Exists(trinity_c_path)) { using (Stream resourceStream = GetTrinityCAssembly(native_assembly_name)) { string embedded_sha = SecureHashHelper.GetSHA512(resourceStream).Trim().ToLowerInvariant(); string ondisk_sha = SecureHashHelper.GetFileSHA512(trinity_c_path).Trim().ToLowerInvariant(); if (embedded_sha.Equals(ondisk_sha)) { found = true; } } } if (!found) { ReleaseNativeAssembly(native_assembly_name, trinity_c_path); } /* native assembly is released. initialize Trinity.C now */ fixed(char *pAssemblyPath = AssemblyPath.MyAssemblyPath) { __INIT_TRINITY_C__(pAssemblyPath); } if (Environment.OSVersion.Platform == PlatformID.Win32NT) { Win32.NativeAPI.timeBeginPeriod(1); #if !CORECLR Register(); #endif } s_initialized = true; } }