Esempio n. 1
0
        //
        Window OpenHashPropWindow(string filename)
        {
            // Combine the path to the class .dll with the relative path to the test vectors
            if (PATH_PREFIX == null)
            {
                PATH_PREFIX = Path.Combine(
                    Path.GetDirectoryName(
                        Uri.UnescapeDataString(
                            new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
                            )
                        ),
                    RELATIVE_PATH_PREFIX
                    );
            }

            // Open the Checksums tab in the shell file properties sheet
            SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO();

            sei.cbSize       = (uint)System.Runtime.InteropServices.Marshal.SizeOf(sei);
            sei.fMask        = 0x0000010C; // SEE_MASK_INVOKEIDLIST | SEE_MASK_NOASYNC
            sei.lpVerb       = "Properties";
            sei.lpFile       = Path.Combine(PATH_PREFIX, filename);
            sei.lpParameters = "Checksums";
            sei.nShow        = 1;    // SW_SHOWNORMAL
            ShellExecuteExW(ref sei);

            // Find the file properties sheet window
            Window prop_window = null;

            // Prior to Windows 10, the file properties sheet opens in the curent process
            int orig_timeout = CoreAppXmlConfiguration.Instance.FindWindowTimeout;

            if ((int)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMajorVersionNumber", 0) >= 10)
            {
                CoreAppXmlConfiguration.Instance.FindWindowTimeout = 1500;  // likely to fail on Windows 10+, so use a short timeout (1.5s) in that case
            }
            if (!is_com_surrogate)
            {
                Application app = Application.Attach(Process.GetCurrentProcess());
                try
                {
                    prop_window      = app.GetWindow(filename + " Properties");
                    is_com_surrogate = false;
                }
                catch (AutomationException) { }
            }

            // Starting with Windows 10, the file properties sheet is hosted in a dllhost COM surrogate
            if (prop_window == null)
            {
                foreach (Process proc in Process.GetProcessesByName("dllhost"))
                {
                    Application app = Application.Attach(proc);
                    try
                    {
                        prop_window = app.GetWindow(filename + " Properties");
                        break;
                    }
                    catch (AutomationException) { }
                }
                Assert.NotNull(prop_window);
                is_com_surrogate = true;
            }
            CoreAppXmlConfiguration.Instance.FindWindowTimeout = orig_timeout;

            return(prop_window);
        }