Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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;
            }
        }