Exemple #1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            // start the encryption thread pool to speed up the analyzer - this is also the first access to the native
            // "TrueCrypt.dll" and therefore an exception may occur when the library cannot be loaded
            try
            {
                TrueCrypt.EncryptionThreadPoolStart(Environment.ProcessorCount);
            }
            catch (Exception ex)
            {
                if (ex is DllNotFoundException || ex is EntryPointNotFoundException)
                {
                    MessageBox.Show(this, PageContext.GetInstance().GetResourceString("LoadTrueCryptDllFailed"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    silentExit = true;
                    Close();
                    return;
                }
                throw;
            }

            // try to open the TestCrypt driver just to test whether the driver can be opened
            try
            {
                TrueCrypt.OpenDriver();
            }
            catch (TrueCrypt.TrueCryptException ex)
            {
                // the TestCrypt driver could not be opened - most probably this is caused by a 64-bit operating system
                // which requires digitally signed drivers
                string msg;
                switch (ex.Cause)
                {
                case TrueCrypt.TrueCryptException.ExceptionCause.DriverLoadFailed:
                    // check whether loading the driver failed due to the missing digital driver signature
                    if (((uint)ex.ErrorCode == 0x80004005) &&
                        Wow.Is64BitOperatingSystem && Wow.IsOSAtLeast(Wow.OSVersion.WIN_VISTA))
                    {
                        // missing digital driver signature
                        notifyIcon.BalloonTipClicked += notifyIcon_BalloonTipClicked;
                        notifyIcon.BalloonTipTitle    = PageContext.GetInstance().GetResourceString("LoadTestCryptDriverFailedTitle");
                        notifyIcon.BalloonTipText     = PageContext.GetInstance().GetResourceString("DriverSignatureEnforcement");
                        notifyIcon.ShowBalloonTip(30000);
                    }
                    else
                    {
                        // another error has occurred
                        msg = string.Format(PageContext.GetInstance().GetResourceString("LoadTestCryptDriverFailed"), ex.ErrorCode, ex.Message);
                        MessageBox.Show(this, msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    break;

                case TrueCrypt.TrueCryptException.ExceptionCause.DriverOpenFailed:
                default:
                    msg = string.Format(PageContext.GetInstance().GetResourceString("OpenTestCryptDriverFailed"), ex.ErrorCode, ex.Message);
                    MessageBox.Show(this, msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    break;
                }
            }
        }